feat(sentry-types): Add trace metric protocol envelope support#1022
feat(sentry-types): Add trace metric protocol envelope support#1022szokeasaurusrex wants to merge 1 commit intomasterfrom
Conversation
|
11642d7 to
ee23bf8
Compare
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>
ee23bf8 to
52b0419
Compare
There was a problem hiding this comment.
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.
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,| /// Additional key-value attributes. | ||
| #[serde(default, skip_serializing_if = "Map::is_empty")] | ||
| pub attributes: Map<String, LogAttribute>, | ||
| } |
There was a problem hiding this comment.
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.
| pub struct TraceMetric { | ||
| /// The metric type. | ||
| pub r#type: TraceMetricType, | ||
| /// The metric name . Uses dot separators for hierarchy. |
There was a problem hiding this comment.
| /// 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, |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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?



Add
TraceMetricprotocol types andtrace_metricenvelope container serialization/deserialization insentry-types.Closes #1008
Closes RUST-159