File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1027,6 +1027,15 @@ def to_json(self):
10271027
10281028 return rv
10291029
1030+ def get_trace_context (self ):
1031+ # type: () -> Any
1032+ trace_context = super ().get_trace_context ()
1033+
1034+ if self ._data :
1035+ trace_context ["data" ] = self ._data
1036+
1037+ return trace_context
1038+
10301039 def get_baggage (self ):
10311040 # type: () -> Baggage
10321041 """Returns the :py:class:`~sentry_sdk.tracing_utils.Baggage`
Original file line number Diff line number Diff line change @@ -60,6 +60,33 @@ def test_transaction_naming(sentry_init, capture_events):
6060 assert events [2 ]["transaction" ] == "a"
6161
6262
63+ def test_transaction_data (sentry_init , capture_events ):
64+ sentry_init (traces_sample_rate = 1.0 )
65+ events = capture_events ()
66+
67+ with start_transaction (name = "test-transaction" ):
68+ span_or_tx = sentry_sdk .get_current_span ()
69+ span_or_tx .set_data ("foo" , "bar" )
70+ with start_span (op = "test-span" ) as span :
71+ span .set_data ("spanfoo" , "spanbar" )
72+
73+ assert len (events ) == 1
74+
75+ transaction = events [0 ]
76+ transaction_data = transaction ["contexts" ]["trace" ]["data" ]
77+
78+ assert "data" not in transaction .keys ()
79+ assert transaction_data .items () >= {"foo" : "bar" }.items ()
80+
81+ assert len (transaction ["spans" ]) == 1
82+
83+ span = transaction ["spans" ][0 ]
84+ span_data = span ["data" ]
85+
86+ assert "contexts" not in span .keys ()
87+ assert span_data .items () >= {"spanfoo" : "spanbar" }.items ()
88+
89+
6390def test_start_transaction (sentry_init ):
6491 sentry_init (traces_sample_rate = 1.0 )
6592
You can’t perform that action at this time.
0 commit comments