Skip to content

feat(sentry-types): Add trace metric protocol envelope support#1022

Open
szokeasaurusrex wants to merge 1 commit intomasterfrom
szokeasaurusrex/metrics-protocol
Open

feat(sentry-types): Add trace metric protocol envelope support#1022
szokeasaurusrex wants to merge 1 commit intomasterfrom
szokeasaurusrex/metrics-protocol

Conversation

@szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Mar 2, 2026

Add TraceMetric protocol types and trace_metric envelope container serialization/deserialization in sentry-types.

Closes #1008
Closes RUST-159

@linear
Copy link

linear bot commented Mar 2, 2026

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

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

Generated by 🚫 dangerJS against 52b0419

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-protocol branch from 11642d7 to ee23bf8 Compare March 2, 2026 17:12
Add `TraceMetric` protocol types and `trace_metric` envelope container serialization/deserialization in `sentry-types`.

Closes #1008
Closes [RUST-159](https://linear.app/getsentry/issue/RUST-159/add-trace-metric-protocol-models-and-envelope-item-container-support)
Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/metrics-protocol branch from ee23bf8 to 52b0419 Compare March 2, 2026 17:16
@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review March 2, 2026 17:16
@szokeasaurusrex szokeasaurusrex requested a review from lcian as a code owner March 2, 2026 17:16
Copy link

@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.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Non-exhaustive struct without constructor blocks external usage
    • Removed #[non_exhaustive] from TraceMetric struct to allow external crates to construct instances, matching the pattern used by the similar Log struct.

Create PR

Or push these changes by commenting:

@cursor push 27ed5ff65a
Preview (27ed5ff65a)
diff --git a/sentry-types/src/protocol/v7.rs b/sentry-types/src/protocol/v7.rs
--- a/sentry-types/src/protocol/v7.rs
+++ b/sentry-types/src/protocol/v7.rs
@@ -2383,7 +2383,6 @@
 
 /// A single [trace metric](https://develop.sentry.dev/sdk/telemetry/metrics/).
 #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
-#[non_exhaustive]
 pub struct TraceMetric {
     /// The metric type.
     pub r#type: TraceMetricType,
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

/// Additional key-value attributes.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub attributes: Map<String, LogAttribute>,
}
Copy link

Choose a reason for hiding this comment

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

Non-exhaustive struct without constructor blocks external usage

Medium Severity

TraceMetric has #[non_exhaustive] on a struct, which prevents construction via struct literal syntax from external crates — but no constructor or Default impl is provided. This means crates like sentry that depend on sentry-types cannot create TraceMetric instances at all, making the type effectively unusable for its intended purpose. This is inconsistent with the analogous Log struct, which omits #[non_exhaustive] and allows direct construction. The #[non_exhaustive] on the TraceMetricType enum is fine (allows adding variants), but on the struct it needs to be paired with a constructor.

Fix in Cursor Fix in Web

pub struct TraceMetric {
/// The metric type.
pub r#type: TraceMetricType,
/// The metric name . Uses dot separators for hierarchy.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// The metric name . Uses dot separators for hierarchy.
/// The metric name. Uses dot separators for hierarchy.

/// The metric name . Uses dot separators for hierarchy.
pub name: String,
/// The numeric value.
pub value: f64,
Copy link
Member

Choose a reason for hiding this comment

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

Is this fine?
It's technically not defined in the spec, but logically you should only be able to send ints for counters while you should be able to send floats for e.g. gauges.
I wonder what happens if you send a counter but serialize the value as 1.0, I guess it depends on how loosely this is defined in Relay/other systems.

pub unit: Option<String>,
/// Additional key-value attributes.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub attributes: Map<String, LogAttribute>,
Copy link
Member

Choose a reason for hiding this comment

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

I think we could rename this to Attribute and then alias type LogAttribute = Attribute so that it's not a breaking change if anyone is using it.
wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add trace metric protocol models and envelope item container support

2 participants