Skip to content

Commit

Permalink
feat(spans): Extract trace context status for indexed spans (#3407)
Browse files Browse the repository at this point in the history
Extract trace context `status` for indexed spans.

#skip-changelog
  • Loading branch information
edwardgou-sentry committed Apr 15, 2024
1 parent 60fa63b commit 1d06dfb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
49 changes: 49 additions & 0 deletions relay-event-normalization/src/normalize/span/tag_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub enum SpanTagKey {
AppStartType,
ReplayId,
CacheHit,
TraceStatus,
}

impl SpanTagKey {
Expand Down Expand Up @@ -113,6 +114,7 @@ impl SpanTagKey {
SpanTagKey::OsName => "os.name",
SpanTagKey::AppStartType => "app_start_type",
SpanTagKey::ReplayId => "replay_id",
SpanTagKey::TraceStatus => "trace.status",
}
}
}
Expand Down Expand Up @@ -232,6 +234,10 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> {
if let Some(op) = extract_transaction_op(trace_context) {
tags.insert(SpanTagKey::TransactionOp, op.to_lowercase().to_owned());
}

if let Some(status) = trace_context.status.value() {
tags.insert(SpanTagKey::TraceStatus, status.to_string());
}
}

if MOBILE_SDKS.contains(&event.sdk_name()) {
Expand Down Expand Up @@ -1647,6 +1653,49 @@ LIMIT 1
);
}

#[test]
fn test_extract_trace_status() {
let json = r#"
{
"type": "transaction",
"platform": "python",
"start_timestamp": "2021-04-26T07:59:01+0100",
"timestamp": "2021-04-26T08:00:00+0100",
"transaction": "foo",
"contexts": {
"trace": {
"status": "ok"
}
},
"spans": [
{
"op": "resource.script",
"span_id": "bd429c44b67a3eb1",
"start_timestamp": 1597976300.0000000,
"timestamp": 1597976302.0000000,
"trace_id": "ff62a8b040f340bda5d830223def1d81"
}
]
}
"#;

let mut event = Annotated::<Event>::from_json(json)
.unwrap()
.into_value()
.unwrap();

extract_span_tags_from_event(&mut event, 200);

let span = &event.spans.value().unwrap()[0];
let tags = span.value().unwrap().sentry_tags.value().unwrap();

assert_eq!(
tags.get("trace.status"),
Some(&Annotated::new("ok".to_string()))
);
}

fn extract_tags_supabase(description: impl Into<String>) -> BTreeMap<SpanTagKey, String> {
let json = r#"{
"description": "from(my_table)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -84,6 +85,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -132,6 +134,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -177,6 +180,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -224,6 +228,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -271,6 +276,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -352,6 +358,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down Expand Up @@ -431,6 +438,7 @@ expression: "(&event.value().unwrap().spans, metrics)"
"release": "1.2.3",
"sdk.name": "sentry.javascript.react-native",
"sdk.version": "unknown",
"trace.status": "unknown",
"transaction": "gEt /api/:version/users/",
"transaction.method": "GET",
"ttid": "ttid",
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/test_spans.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_span_extraction(
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"trace.status": "unknown",
"transaction": "hi",
"transaction.op": "hi",
},
Expand Down Expand Up @@ -133,6 +134,7 @@ def test_span_extraction(
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"trace.status": "unknown",
"transaction": "hi",
"transaction.op": "hi",
},
Expand Down Expand Up @@ -869,6 +871,7 @@ def test_span_extraction_with_metrics_summary(
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"trace.status": "unknown",
"transaction": "hi",
"transaction.op": "hi",
},
Expand Down Expand Up @@ -1042,6 +1045,7 @@ def test_span_extraction_with_ddm_missing_values(
"platform": "other",
"sdk.name": "raven-node",
"sdk.version": "2.6.3",
"trace.status": "unknown",
"transaction": "hi",
"transaction.op": "hi",
},
Expand Down

0 comments on commit 1d06dfb

Please sign in to comment.