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 07acfeb

@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
{
batcher.enqueue(metric);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing enable_metrics guard in capture_metric

Low Severity

capture_metric is missing an early-return check for self.options.enable_metrics, unlike capture_log which guards with if !self.options.enable_logs { return; }. While the metric ultimately won't be sent (because metrics_batcher is None when disabled), prepare_metric still runs — applying scope data and converting the metric — doing unnecessary work. This inconsistency with the capture_log pattern also makes the intent less clear to future readers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cd20001. Configure here.

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
…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
.field("before_send_log", &before_send_log);

#[cfg(feature = "metrics")]
debug_struct.field("enable_metrics", &self.enable_metrics);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO: I should probably change this to also print when feature is disabled

///
/// This setting has no effect unless the `metrics` feature is enabled at compile-time,
/// as the feature is a prerequisite for sending metrics.
pub enable_metrics: bool,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed the #[cfg(feature = "metrics")] from this field due to #1081.

cc @lcian, that issue may be interesting to you, TIL that feature-flag-guarding fields on a struct is a SemVer no-no for pub structs with all pub fields

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