Skip to content

Commit 0fe2870

Browse files
authored
feat(spans): Convert Span V1 to Span V2 (#5139)
This conversion will eventually be used to convert Span V1 payloads early in the pipeline. Short term it will be needed to convert `SpanV1 -> SpanV2 -> CompatSpan` at the end of processing so we can migrate the span consumer (sentry-side) to the new schema. ref: INGEST-531
1 parent ffb4542 commit 0fe2870

File tree

17 files changed

+505
-26
lines changed

17 files changed

+505
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ target
1717

1818
# Editors
1919
/.idea/
20+
/*.sln
2021
.DS_Store
2122

2223
# NPM utilities for building docs

relay-event-normalization/src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn normalize(event: &mut Event, meta: &mut Meta, config: &NormalizationConfig) {
348348
}
349349

350350
if config.performance_issues_spans && event.ty.value() == Some(&EventType::Transaction) {
351-
event._performance_issues_spans = Annotated::new(true);
351+
event.performance_issues_spans = Annotated::new(true);
352352
}
353353

354354
if config.enrich_spans {

relay-event-normalization/src/normalize/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ mod tests {
20742074
platform: ~,
20752075
was_transaction: ~,
20762076
kind: ~,
2077-
_performance_issues_spans: ~,
2077+
performance_issues_spans: ~,
20782078
other: {},
20792079
},
20802080
]
@@ -2122,7 +2122,7 @@ mod tests {
21222122
platform: ~,
21232123
was_transaction: ~,
21242124
kind: ~,
2125-
_performance_issues_spans: ~,
2125+
performance_issues_spans: ~,
21262126
other: {},
21272127
},
21282128
]
@@ -2170,7 +2170,7 @@ mod tests {
21702170
platform: ~,
21712171
was_transaction: ~,
21722172
kind: ~,
2173-
_performance_issues_spans: ~,
2173+
performance_issues_spans: ~,
21742174
other: {},
21752175
},
21762176
]

relay-event-schema/src/protocol/attributes.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl fmt::Debug for Attribute {
4242
}
4343
}
4444

45+
impl From<AttributeValue> for Attribute {
46+
fn from(value: AttributeValue) -> Self {
47+
Self {
48+
value,
49+
other: Default::default(),
50+
}
51+
}
52+
}
53+
4554
#[derive(Debug, Clone, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
4655
pub struct AttributeValue {
4756
#[metastructure(field = "type", required = true, trim = false, pii = "false")]
@@ -197,7 +206,7 @@ impl Attributes {
197206
String: Borrow<Q>,
198207
Q: Ord + ?Sized,
199208
{
200-
self.get_attribute(key)?.value.value.value()
209+
self.get_annotated_value(key)?.value()
201210
}
202211

203212
/// Returns the attribute with the given key.
@@ -209,8 +218,17 @@ impl Attributes {
209218
self.0.get(key)?.value()
210219
}
211220

221+
/// Returns the attribute value as annotated.
222+
pub fn get_annotated_value<Q>(&self, key: &Q) -> Option<&Annotated<Value>>
223+
where
224+
String: Borrow<Q>,
225+
Q: Ord + ?Sized,
226+
{
227+
Some(&self.0.get(key)?.value()?.value.value)
228+
}
229+
212230
/// Inserts an attribute with the given value into this collection.
213-
pub fn insert<V: Into<AttributeValue>>(&mut self, key: String, value: V) {
231+
pub fn insert<K: Into<String>, V: Into<AttributeValue>>(&mut self, key: K, value: V) {
214232
fn inner(slf: &mut Attributes, key: String, value: AttributeValue) {
215233
let attribute = Annotated::new(Attribute {
216234
value,
@@ -220,7 +238,7 @@ impl Attributes {
220238
}
221239
let value = value.into();
222240
if !value.value.is_empty() {
223-
inner(self, key, value);
241+
inner(self, key.into(), value);
224242
}
225243
}
226244

relay-event-schema/src/protocol/event.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,12 @@ pub struct Event {
496496
///
497497
/// When the flag is set to true, this transaction event will be skipped for performance issue
498498
/// detection in favor of the spans pipeline.
499-
#[metastructure(skip_serialization = "empty", trim = false)]
500-
pub _performance_issues_spans: Annotated<bool>,
499+
#[metastructure(
500+
field = "_performance_issues_spans",
501+
skip_serialization = "empty",
502+
trim = false
503+
)]
504+
pub performance_issues_spans: Annotated<bool>,
501505

502506
/// Additional arbitrary fields for forwards compatibility.
503507
#[metastructure(additional_properties, pii = "true")]

relay-event-schema/src/protocol/span.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ pub struct Span {
128128
/// is a root (segment) instead of the transaction event.
129129
///
130130
/// Only set on root spans extracted from transactions.
131-
#[metastructure(skip_serialization = "empty", trim = false)]
132-
pub _performance_issues_spans: Annotated<bool>,
131+
#[metastructure(
132+
field = "_performance_issues_spans",
133+
skip_serialization = "empty",
134+
trim = false
135+
)]
136+
pub performance_issues_spans: Annotated<bool>,
133137

134138
// TODO remove retain when the api stabilizes
135139
/// Additional arbitrary fields for forwards compatibility.

relay-event-schema/src/protocol/span/compat.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub struct CompatSpan {
2020
pub segment_id: Annotated<String>,
2121
pub start_timestamp_ms: Annotated<u64>, // TODO: remove from kafka schema, no longer used in consumer
2222
pub start_timestamp_precise: Annotated<Timestamp>,
23+
24+
#[metastructure(field = "_performance_issues_spans")]
25+
pub performance_issues_spans: Annotated<bool>, // TODO: add to Kafka schema?
2326
}
2427

2528
impl TryFrom<SpanV2> for CompatSpan {
@@ -73,13 +76,20 @@ impl TryFrom<SpanV2> for CompatSpan {
7376
}
7477

7578
if let Some(segment_id) = attributes
76-
.get_value("sentry.segment.id") // TODO: EAP expects `sentry.segment_id`, double write this somewhere.
79+
.get_value("sentry.segment.id")
7780
.and_then(Value::as_str)
7881
{
7982
compat_span.segment_id = Annotated::from(segment_id.to_owned());
8083
}
84+
85+
if let Some(Value::Bool(b)) =
86+
attributes.get_value("sentry._internal.performance_issues_spans")
87+
{
88+
compat_span.performance_issues_spans = Annotated::new(*b);
89+
}
8190
}
8291

92+
// FIXME: preserve _meta everywhere (see a test failure).
8393
compat_span.span_v2 = span_v2;
8494
Ok(compat_span)
8595
}
@@ -143,6 +153,10 @@ mod tests {
143153
"sentry.segment.name": {
144154
"value": "my 1st transaction",
145155
"type": "string"
156+
},
157+
"sentry._internal.performance_issues_spans": {
158+
"value": true,
159+
"type": "bool"
146160
}
147161
}
148162
}"#;
@@ -165,6 +179,10 @@ mod tests {
165179
"type": "string",
166180
"value": "Chrome"
167181
},
182+
"sentry._internal.performance_issues_spans": {
183+
"type": "bool",
184+
"value": true
185+
},
168186
"sentry.description": {
169187
"type": "string",
170188
"value": "mydescription"
@@ -204,6 +222,7 @@ mod tests {
204222
},
205223
"data": {
206224
"browser.name": "Chrome",
225+
"sentry._internal.performance_issues_spans": true,
207226
"sentry.description": "mydescription",
208227
"sentry.environment": "prod",
209228
"sentry.op": "myop",
@@ -220,7 +239,8 @@ mod tests {
220239
"profile_id": "a0aaaaaaaaaaaaaaaaaaaaaaaaaaaaab",
221240
"segment_id": "FA90FDEAD5F74052",
222241
"start_timestamp_ms": 123000,
223-
"start_timestamp_precise": 123.0
242+
"start_timestamp_precise": 123.0,
243+
"_performance_issues_spans": true
224244
}
225245
"###);
226246
}

relay-event-schema/src/protocol/span/convert.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl From<&Event> for Span {
1717

1818
measurements,
1919
_metrics,
20-
_performance_issues_spans,
20+
performance_issues_spans,
2121
..
2222
} = event;
2323

@@ -72,7 +72,7 @@ impl From<&Event> for Span {
7272
platform: platform.clone(),
7373
was_transaction: true.into(),
7474
kind: Default::default(),
75-
_performance_issues_spans: _performance_issues_spans.clone(),
75+
performance_issues_spans: performance_issues_spans.clone(),
7676
other: Default::default(),
7777
}
7878
}
@@ -134,7 +134,7 @@ mod tests {
134134
.unwrap();
135135

136136
let span_from_event = Span::from(&event);
137-
insta::assert_debug_snapshot!(span_from_event, @r#"
137+
insta::assert_debug_snapshot!(span_from_event, @r###"
138138
Span {
139139
timestamp: ~,
140140
start_timestamp: ~,
@@ -287,9 +287,9 @@ mod tests {
287287
platform: "php",
288288
was_transaction: true,
289289
kind: ~,
290-
_performance_issues_spans: ~,
290+
performance_issues_spans: ~,
291291
other: {},
292292
}
293-
"#);
293+
"###);
294294
}
295295
}

relay-pii/src/snapshots/relay_pii__processor__tests__does_not_scrub_if_no_graphql.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ Event {
109109
scraping_attempts: ~,
110110
_metrics: ~,
111111
_dsc: ~,
112-
_performance_issues_spans: ~,
112+
performance_issues_spans: ~,
113113
other: {},
114114
}

relay-pii/src/snapshots/relay_pii__processor__tests__scrub_graphql_response_data_with_variables.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ Event {
109109
scraping_attempts: ~,
110110
_metrics: ~,
111111
_dsc: ~,
112-
_performance_issues_spans: ~,
112+
performance_issues_spans: ~,
113113
other: {},
114114
}

0 commit comments

Comments
 (0)