Skip to content

Commit

Permalink
feat(spans): Add a measurements field to span protocol (#2792)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops committed Nov 29, 2023
1 parent a428668 commit e86aa02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Partition and split metric buckets just before sending. Log outcomes for metrics. ([#2682](https://github.com/getsentry/relay/pull/2682))
- Return global config ready status to downstream relays. ([#2765](https://github.com/getsentry/relay/pull/2765))
- Add Mixed JS/Android Profiles events processing. ([#2706](https://github.com/getsentry/relay/pull/2706))
- Allow to ingest measurements on a span. ([#2792](https://github.com/getsentry/relay/pull/2792))

**Internal**:

Expand Down
3 changes: 3 additions & 0 deletions relay-event-normalization/src/normalize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,7 @@ mod tests {
data: ~,
sentry_tags: ~,
received: ~,
measurements: ~,
other: {},
},
]
Expand Down Expand Up @@ -2450,6 +2451,7 @@ mod tests {
data: ~,
sentry_tags: ~,
received: ~,
measurements: ~,
other: {},
},
]
Expand Down Expand Up @@ -2491,6 +2493,7 @@ mod tests {
data: ~,
sentry_tags: ~,
received: ~,
measurements: ~,
other: {},
},
]
Expand Down
30 changes: 26 additions & 4 deletions relay-event-schema/src/protocol/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use relay_protocol::{Annotated, Empty, FromValue, Getter, IntoValue, Object, Val

use crate::processor::ProcessValue;
use crate::protocol::{
Event, EventId, JsonLenientString, OperationType, OriginType, ProfileContext, SpanId,
SpanStatus, Timestamp, TraceContext, TraceId,
Event, EventId, JsonLenientString, Measurements, OperationType, OriginType, ProfileContext,
SpanId, SpanStatus, Timestamp, TraceContext, TraceId,
};

#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
Expand Down Expand Up @@ -76,6 +76,11 @@ pub struct Span {
/// Timestamp when the span has been received by Sentry.
pub received: Annotated<Timestamp>,

/// Measurements which holds observed values such as web vitals.
#[metastructure(skip_serialization = "empty")]
#[metastructure(omit_from_schema)] // we only document error events for now
pub measurements: Annotated<Measurements>,

// TODO remove retain when the api stabilizes
/// Additional arbitrary fields for forwards compatibility.
#[metastructure(additional_properties, retain = "true", pii = "maybe")]
Expand Down Expand Up @@ -151,8 +156,10 @@ impl Getter for Span {

#[cfg(test)]
mod tests {
use crate::protocol::Measurement;
use chrono::{TimeZone, Utc};
use insta::assert_debug_snapshot;
use relay_base_schema::metrics::{InformationUnit, MetricUnit};
use similar_asserts::assert_eq;

use super::*;
Expand All @@ -168,9 +175,22 @@ mod tests {
"span_id": "fa90fdead5f74052",
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"status": "ok",
"origin": "auto.http"
"origin": "auto.http",
"measurements": {
"memory": {
"value": 9001.0,
"unit": "byte"
}
}
}"#;

let mut measurements = Object::new();
measurements.insert(
"memory".into(),
Annotated::new(Measurement {
value: Annotated::new(9001.0),
unit: Annotated::new(MetricUnit::Information(InformationUnit::Byte)),
}),
);
let span = Annotated::new(Span {
timestamp: Annotated::new(Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap().into()),
start_timestamp: Annotated::new(
Expand All @@ -183,6 +203,7 @@ mod tests {
span_id: Annotated::new(SpanId("fa90fdead5f74052".into())),
status: Annotated::new(SpanStatus::Ok),
origin: Annotated::new("auto.http".to_owned()),
measurements: Annotated::new(Measurements(measurements)),
..Default::default()
});
assert_eq!(json, span.to_json_pretty().unwrap());
Expand Down Expand Up @@ -258,6 +279,7 @@ mod tests {
data: ~,
sentry_tags: ~,
received: ~,
measurements: ~,
other: {},
}
"###);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"transaction.method": "GET",
},
received: ~,
measurements: ~,
other: {},
},
],
Expand Down
1 change: 1 addition & 0 deletions relay-server/src/metrics_extraction/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ mod tests {
data: ~,
sentry_tags: ~,
received: ~,
measurements: ~,
other: {},
},
]
Expand Down

0 comments on commit e86aa02

Please sign in to comment.