Skip to content

Commit ed66f59

Browse files
committed
move thread id/name into trace context
1 parent 578e1e9 commit ed66f59

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

sentry_sdk/tracing.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ class TransactionKwargs(SpanKwargs, total=False):
109109
"ProfileContext",
110110
{
111111
"profiler.id": str,
112-
"thread.id": str,
113-
"thread.name": str,
114112
},
115-
total=False,
116113
)
117114

118115

@@ -661,6 +658,19 @@ def get_trace_context(self):
661658
self.containing_transaction.get_baggage().dynamic_sampling_context()
662659
)
663660

661+
data = {}
662+
663+
thread_id = self._data.get(SPANDATA.THREAD_ID)
664+
if thread_id is not None:
665+
data["thread.id"] = thread_id
666+
667+
thread_name = self._data.get(SPANDATA.THREAD_NAME)
668+
if thread_name is not None:
669+
data["thread.name"] = thread_name
670+
671+
if data:
672+
rv["data"] = data
673+
664674
return rv
665675

666676
def get_profile_context(self):
@@ -669,19 +679,9 @@ def get_profile_context(self):
669679
if profiler_id is None:
670680
return None
671681

672-
rv = {
682+
return {
673683
"profiler.id": profiler_id,
674-
} # type: ProfileContext
675-
676-
thread_id = self._data.get(SPANDATA.THREAD_ID)
677-
if thread_id is not None:
678-
rv["thread.id"] = thread_id
679-
680-
thread_name = self._data.get(SPANDATA.THREAD_NAME)
681-
if thread_name is not None:
682-
rv["thread.name"] = thread_name
683-
684-
return rv
684+
}
685685

686686

687687
class Transaction(Span):

tests/profiler/test_continuous_profiler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,21 @@ def assert_single_transaction_with_profile_chunks(envelopes, thread):
8686
assert len(items["profile_chunk"]) > 0
8787

8888
transaction = items["transaction"][0].payload.json
89+
trace_context = transaction["contexts"]["trace"]
90+
assert trace_context["data"] == ApproxDict(
91+
{
92+
"thread.id": str(thread.ident),
93+
"thread.name": thread.name,
94+
}
95+
)
96+
8997
profile_context = transaction["contexts"]["profile"]
9098

9199
profiler_id = profile_context["profiler.id"]
92100

93101
assert profile_context == ApproxDict(
94102
{
95103
"profiler.id": profiler_id,
96-
"thread.id": str(thread.ident),
97-
"thread.name": thread.name,
98104
}
99105
)
100106

0 commit comments

Comments
 (0)