feat(metrics): Basic metrics capturing functionality in sentry-core#1073
feat(metrics): Basic metrics capturing functionality in sentry-core#1073szokeasaurusrex wants to merge 1 commit intoszokeasaurusrex/metrics-protocolfrom
Conversation
|
532ad35 to
d47f8a2
Compare
fda826a to
1b0c9be
Compare
d47f8a2 to
88d565c
Compare
fb6c66b to
b887824
Compare
bd6780b to
1932f45
Compare
1861bc0 to
aadec60
Compare
…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)
aadec60 to
06aeb9d
Compare
…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)
06aeb9d to
cf4fe98
Compare
…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)
cf4fe98 to
f27b842
Compare
…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)
f27b842 to
93692bd
Compare
giortzisg
left a comment
There was a problem hiding this comment.
overall looks good, just left a comment for attribute ordering and some minor nits.
| 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, | ||
| } |
There was a problem hiding this comment.
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.
…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)
93692bd to
cd20001
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| { | ||
| batcher.enqueue(metric); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit cd20001. Configure here.
…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)
cd20001 to
d383c6c
Compare
…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)
d383c6c to
07acfeb
Compare
| .field("before_send_log", &before_send_log); | ||
|
|
||
| #[cfg(feature = "metrics")] | ||
| debug_struct.field("enable_metrics", &self.enable_metrics); |
There was a problem hiding this comment.
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, |


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