Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add span data to the transactions trace context #3374

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add span data to the transactions trace context
  • Loading branch information
antonpirker committed Jul 30, 2024
commit e7479b9234a9be035add8b5689e6ff79a39c8457
9 changes: 9 additions & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,15 @@ def to_json(self):

return rv

def get_trace_context(self):
# type: () -> Any
trace_context = super().get_trace_context()

if self._data:
trace_context["data"] = self._data

return trace_context

def get_baggage(self):
# type: () -> Baggage
"""Returns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
Expand Down
30 changes: 30 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sentry_sdk.tracing import Span, Transaction
from sentry_sdk.tracing_utils import should_propagate_trace
from sentry_sdk.utils import Dsn
from tests.conftest import ApproxDict


def test_span_trimming(sentry_init, capture_events):
Expand Down Expand Up @@ -60,6 +61,35 @@ def test_transaction_naming(sentry_init, capture_events):
assert events[2]["transaction"] == "a"


def test_transaction_data(sentry_init, capture_events):
sentry_init(traces_sample_rate=1.0)
events = capture_events()

with start_transaction(name="test-transaction"):
span_or_tx = sentry_sdk.get_current_span()
span_or_tx.set_data("foo", "bar")
with start_span(op="test-span") as span:
span.set_data("spanfoo", "spanbar")

(transaction,) = events
span = transaction["spans"][0]

transaction_data = transaction["contexts"]["trace"]["data"]
span_data = span["data"]

assert transaction_data == ApproxDict(
{
"foo": "bar",
}
)
antonpirker marked this conversation as resolved.
Show resolved Hide resolved

assert span_data == ApproxDict(
{
"spanfoo": "spanbar",
}
)


def test_start_transaction(sentry_init):
sentry_init(traces_sample_rate=1.0)

Expand Down
Loading