Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 9 additions & 1 deletion tests/test_new_scopes_compat_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create_expected_error_event(trx, span):
"abs_path": mock.ANY,
"function": "_faulty_function",
"module": "tests.test_new_scopes_compat_event",
"lineno": 240,
"lineno": 248,
"pre_context": [
" return create_expected_transaction_event",
"",
Expand Down Expand Up @@ -76,6 +76,10 @@ def create_expected_error_event(trx, span):
"parent_span_id": span.parent_span_id,
"op": "test_span",
"description": None,
"data": {
"thread.id": mock.ANY,
"thread.name": "MainThread",
},
},
"runtime": {
"name": "CPython",
Expand Down Expand Up @@ -157,6 +161,10 @@ def create_expected_transaction_event(trx, span):
"parent_span_id": None,
"op": "test_transaction_op",
"description": None,
"data": {
"thread.id": mock.ANY,
"thread.name": "MainThread",
},
},
"character": {
"name": "Mighty Fighter changed by before_send_transaction",
Expand Down