-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiles): Extract thread ID and name in spans (#3771)
- Loading branch information
Showing
9 changed files
with
177 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,8 @@ pub enum SpanTagKey { | |
TraceStatus, | ||
MessagingDestinationName, | ||
MessagingMessageId, | ||
ThreadName, | ||
ThreadId, | ||
ProfilerId, | ||
} | ||
|
||
|
@@ -134,7 +136,8 @@ impl SpanTagKey { | |
SpanTagKey::TraceStatus => "trace.status", | ||
SpanTagKey::MessagingDestinationName => "messaging.destination.name", | ||
SpanTagKey::MessagingMessageId => "messaging.message.id", | ||
|
||
SpanTagKey::ThreadName => "thread.name", | ||
SpanTagKey::ThreadId => "thread.id", | ||
SpanTagKey::ProfilerId => "profiler_id", | ||
} | ||
} | ||
|
@@ -343,6 +346,19 @@ fn extract_shared_tags(event: &Event) -> BTreeMap<SpanTagKey, String> { | |
event.platform.as_str().unwrap_or("other").into(), | ||
); | ||
|
||
if let Some(data) = event | ||
.context::<TraceContext>() | ||
.and_then(|trace_context| trace_context.data.value()) | ||
{ | ||
if let Some(thread_id) = data.thread_id.value() { | ||
tags.insert(SpanTagKey::ThreadId, thread_id.to_string()); | ||
} | ||
|
||
if let Some(thread_name) = data.thread_name.value() { | ||
tags.insert(SpanTagKey::ThreadName, thread_name.to_string()); | ||
} | ||
} | ||
|
||
tags | ||
} | ||
|
||
|
@@ -763,6 +779,16 @@ pub fn extract_tags( | |
span_tags.insert(SpanTagKey::BrowserName, browser_name.clone()); | ||
} | ||
|
||
if let Some(data) = span.data.value() { | ||
if let Some(thread_id) = data.thread_id.value() { | ||
span_tags.insert(SpanTagKey::ThreadId, thread_id.to_string()); | ||
} | ||
|
||
if let Some(thread_name) = data.thread_name.value().and_then(|name| name.as_str()) { | ||
span_tags.insert(SpanTagKey::ThreadName, thread_name.into()); | ||
} | ||
} | ||
|
||
span_tags | ||
} | ||
|
||
|
@@ -2486,4 +2512,100 @@ LIMIT 1 | |
"[email protected]" | ||
); | ||
} | ||
|
||
#[test] | ||
fn extract_thread_id_name_from_span_data_into_sentry_tags() { | ||
let json = r#" | ||
{ | ||
"type": "transaction", | ||
"platform": "javascript", | ||
"start_timestamp": "2021-04-26T07:59:01+0100", | ||
"timestamp": "2021-04-26T08:00:00+0100", | ||
"transaction": "foo", | ||
"contexts": { | ||
"trace": { | ||
"trace_id": "ff62a8b040f340bda5d830223def1d81", | ||
"span_id": "bd429c44b67a3eb4" | ||
} | ||
}, | ||
"spans": [ | ||
{ | ||
"op": "before_first_display", | ||
"span_id": "bd429c44b67a3eb1", | ||
"start_timestamp": 1597976300.0000000, | ||
"timestamp": 1597976302.0000000, | ||
"trace_id": "ff62a8b040f340bda5d830223def1d81", | ||
"data": { | ||
"thread.name": "main", | ||
"thread.id": 42 | ||
} | ||
} | ||
] | ||
} | ||
"#; | ||
|
||
let mut event = Annotated::<Event>::from_json(json).unwrap(); | ||
|
||
normalize_event( | ||
&mut event, | ||
&NormalizationConfig { | ||
enrich_spans: true, | ||
..Default::default() | ||
}, | ||
); | ||
|
||
let spans = get_value!(event.spans!); | ||
let span = &spans[0]; | ||
|
||
assert_eq!(get_value!(span.sentry_tags["thread.id"]!), "42",); | ||
assert_eq!(get_value!(span.sentry_tags["thread.name"]!), "main",); | ||
} | ||
|
||
#[test] | ||
fn extract_thread_id_name_from_trace_context_into_sentry_tags() { | ||
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": { | ||
"op": "queue.process", | ||
"status": "ok", | ||
"data": { | ||
"thread.name": "main", | ||
"thread.id": 42 | ||
} | ||
} | ||
}, | ||
"spans": [ | ||
{ | ||
"op": "before_first_display", | ||
"span_id": "bd429c44b67a3eb1", | ||
"start_timestamp": 1597976300.0000000, | ||
"timestamp": 1597976302.0000000, | ||
"trace_id": "ff62a8b040f340bda5d830223def1d81" | ||
} | ||
] | ||
} | ||
"#; | ||
|
||
let mut event = Annotated::<Event>::from_json(json).unwrap(); | ||
|
||
normalize_event( | ||
&mut event, | ||
&NormalizationConfig { | ||
enrich_spans: true, | ||
..Default::default() | ||
}, | ||
); | ||
|
||
let spans = get_value!(event.spans!); | ||
let span = &spans[0]; | ||
|
||
assert_eq!(get_value!(span.sentry_tags["thread.id"]!), "42",); | ||
assert_eq!(get_value!(span.sentry_tags["thread.name"]!), "main",); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters