Skip to content

Commit

Permalink
fix(profiling): Move thread data to trace context
Browse files Browse the repository at this point in the history
The thread data was added to the profile context in #2830. It should live in the
trace context to align with other SDKs.
  • Loading branch information
Zylphrex committed Jun 11, 2024
1 parent 6a9d152 commit 8f7f07a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
30 changes: 15 additions & 15 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ class TransactionKwargs(SpanKwargs, total=False):
"ProfileContext",
{
"profiler.id": str,
"thread.id": str,
"thread.name": str,
},
total=False,
)


Expand Down Expand Up @@ -661,6 +658,19 @@ def get_trace_context(self):
self.containing_transaction.get_baggage().dynamic_sampling_context()
)

data = {}

thread_id = self._data.get(SPANDATA.THREAD_ID)
if thread_id is not None:
data["thread.id"] = thread_id

thread_name = self._data.get(SPANDATA.THREAD_NAME)
if thread_name is not None:
data["thread.name"] = thread_name

if data:
rv["data"] = data

return rv

def get_profile_context(self):
Expand All @@ -669,19 +679,9 @@ def get_profile_context(self):
if profiler_id is None:
return None

rv = {
return {
"profiler.id": profiler_id,
} # type: ProfileContext

thread_id = self._data.get(SPANDATA.THREAD_ID)
if thread_id is not None:
rv["thread.id"] = thread_id

thread_name = self._data.get(SPANDATA.THREAD_NAME)
if thread_name is not None:
rv["thread.name"] = thread_name

return rv
}


class Transaction(Span):
Expand Down
19 changes: 13 additions & 6 deletions tests/profiler/test_continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,25 @@ def assert_single_transaction_with_profile_chunks(envelopes, thread):
assert len(items["profile_chunk"]) > 0

transaction = items["transaction"][0].payload.json
profile_context = transaction["contexts"]["profile"]

profiler_id = profile_context["profiler.id"]
trace_context = transaction["contexts"]["trace"]

assert profile_context == ApproxDict(
assert trace_context == ApproxDict(
{
"profiler.id": profiler_id,
"thread.id": str(thread.ident),
"thread.name": thread.name,
"data": ApproxDict(
{
"thread.id": str(thread.ident),
"thread.name": thread.name,
}
),
}
)

profile_context = transaction["contexts"]["profile"]
profiler_id = profile_context["profiler.id"]

assert profile_context == ApproxDict({"profiler.id": profiler_id})

spans = transaction["spans"]
assert len(spans) > 0
for span in spans:
Expand Down

0 comments on commit 8f7f07a

Please sign in to comment.