Skip to content

Commit 22e586b

Browse files
Zylphrexarjenzorgdoc
authored andcommitted
fix(profiling): Move thread data to trace context (getsentry#3157)
The thread data was added to the profile context in getsentry#2830. It should live in the trace context to align with other SDKs.
1 parent 657fb1d commit 22e586b

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
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: 13 additions & 6 deletions
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:

tests/test_new_scopes_compat_event.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def create_expected_error_event(trx, span):
3636
"abs_path": mock.ANY,
3737
"function": "_faulty_function",
3838
"module": "tests.test_new_scopes_compat_event",
39-
"lineno": 240,
39+
"lineno": 248,
4040
"pre_context": [
4141
" return create_expected_transaction_event",
4242
"",
@@ -76,6 +76,10 @@ def create_expected_error_event(trx, span):
7676
"parent_span_id": span.parent_span_id,
7777
"op": "test_span",
7878
"description": None,
79+
"data": {
80+
"thread.id": mock.ANY,
81+
"thread.name": "MainThread",
82+
},
7983
},
8084
"runtime": {
8185
"name": "CPython",
@@ -157,6 +161,10 @@ def create_expected_transaction_event(trx, span):
157161
"parent_span_id": None,
158162
"op": "test_transaction_op",
159163
"description": None,
164+
"data": {
165+
"thread.id": mock.ANY,
166+
"thread.name": "MainThread",
167+
},
160168
},
161169
"character": {
162170
"name": "Mighty Fighter changed by before_send_transaction",

0 commit comments

Comments
 (0)