Skip to content
Merged
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
14 changes: 13 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ class Transaction(Span):
# tracestate data from other vendors, of the form `dogs=yes,cats=maybe`
"_third_party_tracestate",
"_measurements",
"_contexts",
"_profile",
"_baggage",
"_active_thread_id",
Expand All @@ -586,7 +587,9 @@ def __init__(
"instead of Span(transaction=...)."
)
name = kwargs.pop("transaction")

Span.__init__(self, **kwargs)

self.name = name
self.source = source
self.sample_rate = None # type: Optional[float]
Expand All @@ -597,6 +600,7 @@ def __init__(
self._sentry_tracestate = sentry_tracestate
self._third_party_tracestate = third_party_tracestate
self._measurements = {} # type: Dict[str, Any]
self._contexts = {} # type: Dict[str, Any]
self._profile = None # type: Optional[sentry_sdk.profiler.Profile]
self._baggage = baggage
# for profiling, we want to know on which thread a transaction is started
Expand Down Expand Up @@ -685,11 +689,15 @@ def finish(self, hub=None):
# to be garbage collected
self._span_recorder = None

contexts = {}
contexts.update(self._contexts)
contexts.update({"trace": self.get_trace_context()})

event = {
"type": "transaction",
"transaction": self.name,
"transaction_info": {"source": self.source},
"contexts": {"trace": self.get_trace_context()},
"contexts": contexts,
"tags": self._tags,
"timestamp": self.timestamp,
"start_timestamp": self.start_timestamp,
Expand All @@ -714,6 +722,10 @@ def set_measurement(self, name, value, unit=""):

self._measurements[name] = {"value": value, "unit": unit}

def set_context(self, key, value):
# type: (str, Any) -> None
self._contexts[key] = value

def to_json(self):
# type: () -> Dict[str, Any]
rv = super(Transaction, self).to_json()
Expand Down