Skip to content

feat(metrics): Basic metrics capturing functionality in sentry-core#1073

Open
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-protocolfrom
szokeasaurusrex/metrics-pub-functions
Open

feat(metrics): Basic metrics capturing functionality in sentry-core#1073
szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-protocolfrom
szokeasaurusrex/metrics-pub-functions

Conversation

@szokeasaurusrex
Copy link
Copy Markdown
Member

@szokeasaurusrex szokeasaurusrex commented Apr 21, 2026

Basic metrics capture functionality. Follow-up PR will implement the rest.

This PR implements public APIs for capturing metrics, plus batching when sending them.

Stacked on #1022

Co-authored-by: Joris Bayer joris.bayer@sentry.io

Closes #1073
Closes RUST-193
Closes #1023
Closes RUST-168
Closes #1058
Closes RUST-186

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 0c98e2f

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from 532ad35 to d47f8a2 Compare April 21, 2026 17:13
@szokeasaurusrex szokeasaurusrex force-pushed the issue-1058-trace-metric branch from fda826a to 1b0c9be Compare April 21, 2026 17:14
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from d47f8a2 to 88d565c Compare April 21, 2026 17:32
@szokeasaurusrex szokeasaurusrex changed the base branch from issue-1058-trace-metric to szokeasaurusrex/core-metrics-capture April 21, 2026 17:34
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch 2 times, most recently from fb6c66b to b887824 Compare April 22, 2026 08:31
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/core-metrics-capture branch from bd6780b to 1932f45 Compare April 22, 2026 09:26
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch 2 times, most recently from 1861bc0 to aadec60 Compare April 22, 2026 09:34
@szokeasaurusrex szokeasaurusrex changed the base branch from szokeasaurusrex/core-metrics-capture to szokeasaurusrex/metrics-protocol April 22, 2026 09:34
@szokeasaurusrex szokeasaurusrex changed the title feat(metrics): Add public APIs for capturing metrics feat(metrics): Basic metrics capturing functionality in sentry-core Apr 22, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 22, 2026

szokeasaurusrex added a commit that referenced this pull request Apr 22, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from aadec60 to 06aeb9d Compare April 22, 2026 09:35
szokeasaurusrex added a commit that referenced this pull request Apr 22, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from 06aeb9d to cf4fe98 Compare April 22, 2026 14:41
szokeasaurusrex added a commit that referenced this pull request Apr 22, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from cf4fe98 to f27b842 Compare April 22, 2026 14:51
szokeasaurusrex added a commit that referenced this pull request Apr 22, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from f27b842 to 93692bd Compare April 22, 2026 17:15
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review April 22, 2026 17:15
@szokeasaurusrex szokeasaurusrex requested a review from lcian as a code owner April 22, 2026 17:15
Comment thread sentry-core/src/hub.rs Outdated
Copy link
Copy Markdown
Contributor

@giortzisg giortzisg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, just left a comment for attribute ordering and some minor nits.

Comment thread sentry-core/src/scope/real.rs
Comment thread sentry-core/src/client.rs
Comment thread sentry-core/src/scope/real.rs Outdated
Comment on lines +51 to +65
pub struct CounterMetric {
inner: MetricInner,
}

/// A gauge metric, created with [`gauge`].
#[must_use = "metrics must be captured via `.capture()` to be sent to Sentry"]
pub struct GaugeMetric {
inner: UnitMetricInner,
}

/// A distribution metric, created with [`distribution`].
#[must_use = "metrics must be captured via `.capture()` to be sent to Sentry"]
pub struct DistributionMetric {
inner: UnitMetricInner,
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not an enum?

Copy link
Copy Markdown
Member Author

@szokeasaurusrex szokeasaurusrex Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability to add a unit is only implemented for gauge and distribution metrics, as units are only applicable to those metric types per the spec.

Using an enum would not allow us to have .unit only exist for gauge and distribution, but not counter metrics. So, while this design is a bit more complex, we can actually encode the semantics via the API.

szokeasaurusrex added a commit that referenced this pull request Apr 23, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from 93692bd to cd20001 Compare April 23, 2026 20:03
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd20001. Configure here.

Comment thread sentry-core/src/client.rs
szokeasaurusrex added a commit that referenced this pull request Apr 23, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from cd20001 to d383c6c Compare April 23, 2026 21:21
szokeasaurusrex added a commit that referenced this pull request Apr 23, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from d383c6c to 07acfeb Compare April 23, 2026 21:24
Comment thread sentry-core/src/clientoptions.rs Outdated
Comment thread sentry-core/src/clientoptions.rs
szokeasaurusrex added a commit that referenced this pull request Apr 24, 2026
Remove the blanket `#![allow(unused)]` in `sentry-core/src/hub.rs`. This
will allow the linter to find problems [like
this](#1073 (comment))
and many more, rather than needing to rely on the clanker for such
things.

Instead, we now have a macro that adds a `let _ = ...arguments...` when
the `client` feature is enabled. This solves the stated purpose of
having the `allow(unused)` in the first place, but where more narrowly.

The clanker also cleaned up some truly unused things that were
suppressed before.

<details>

<summary>What the clanker wrote</summary>

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
### Description
Removes the blanket `#![allow(unused)]` from `sentry-core/src/hub.rs`.

Instead of repeating a long `#[cfg_attr(not(feature = "client"),
expect(unused, ...))]` annotation across many parameters, this change
uses a small documented local `use_without_client!` helper macro that
only touches those values in `not(feature = "client")` builds. That
keeps the handling narrow to the specific methods and arguments that
need it, while avoiding duplicated attributes in the signatures.

Also cleans up truly unused imports, removes an unnecessary `mut` in the
release-health session setup path, and keeps the file rustfmt-clean for
CI.

Validated with:
- `cargo +1.88.0 fmt --all --check`
- `cargo +1.88.0 clippy -p sentry-core --no-default-features -- -D
warnings`
- `cargo +1.88.0 clippy -p sentry-core --no-default-features --features
client -- -D warnings`
- `cargo +1.88.0 clippy -p sentry-core --all-features -- -D warnings`
- `cargo +1.88.0 clippy -p sentry-core --no-default-features --features
release-health -- -D warnings`
- `cargo +1.88.0 clippy -p sentry-core --no-default-features --features
logs -- -D warnings`

Note: a full local workspace `cargo clippy --all-features --workspace
--tests --examples --locked` is blocked in this environment by missing
system OpenSSL development libraries, which is unrelated to this
`hub.rs` change.

#### Issues
- N/A

#### Reminders
- GH Issue ID / Linear ID: N/A
- CHANGELOG.md: not updated (internal lint cleanup)
- PR title uses conventional commit style
- Useful links for external contributors: [Sentry SDK development
docs](https://develop.sentry.dev/sdk/), [Discord
community](https://discord.gg/sentry)
<!-- CURSOR_AGENT_PR_BODY_END -->

</details>

<div><a
href="https://cursor.com/agents/bc-0342af16-4799-43c3-8028-50dc657541e4"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-0342af16-4799-43c3-8028-50dc657541e4"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Daniel Szoke <szokeasaurusrex@users.noreply.github.com>
szokeasaurusrex added a commit that referenced this pull request Apr 24, 2026
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from 07acfeb to 207d6fc Compare April 24, 2026 12:30
…1073)

Basic metrics capture functionality. Follow-up PR will implement the rest.

Stacked on #1022

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>

Closes #1023
Closes [RUST-168](https://linear.app/getsentry/issue/RUST-168/implement-trace-metric-capture-and-batching-in-sentry-core)
Closes #1058
Closes [RUST-186](https://linear.app/getsentry/issue/RUST-186/add-trace-metric-tracing-association-in-sentry-core)
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-pub-functions branch from 207d6fc to 0c98e2f Compare April 24, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants