Skip to content

Commit 8f7f07a

Browse files
committed
fix(profiling): Move thread data to trace context
The thread data was added to the profile context in #2830. It should live in the trace context to align with other SDKs.
1 parent 6a9d152 commit 8f7f07a

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

sentry_sdk/tracing.py

+15-15
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

+13-6
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,25 @@ 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-
profile_context = transaction["contexts"]["profile"]
9089

91-
profiler_id = profile_context["profiler.id"]
90+
trace_context = transaction["contexts"]["trace"]
9291

93-
assert profile_context == ApproxDict(
92+
assert trace_context == ApproxDict(
9493
{
95-
"profiler.id": profiler_id,
96-
"thread.id": str(thread.ident),
97-
"thread.name": thread.name,
94+
"data": ApproxDict(
95+
{
96+
"thread.id": str(thread.ident),
97+
"thread.name": thread.name,
98+
}
99+
),
98100
}
99101
)
100102

103+
profile_context = transaction["contexts"]["profile"]
104+
profiler_id = profile_context["profiler.id"]
105+
106+
assert profile_context == ApproxDict({"profiler.id": profiler_id})
107+
101108
spans = transaction["spans"]
102109
assert len(spans) > 0
103110
for span in spans:

0 commit comments

Comments
 (0)