Skip to content

Commit 3da73af

Browse files
committed
Implement minimal get_trace_context for StreamedSpan
1 parent e71bf03 commit 3da73af

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

sentry_sdk/scope.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,6 @@ def get_trace_context(self) -> "Dict[str, Any]":
606606
Returns the Sentry "trace" context from the Propagation Context.
607607
"""
608608
if has_tracing_enabled(self.get_client().options) and self._span is not None:
609-
if isinstance(self._span, StreamedSpan):
610-
warnings.warn(
611-
"Scope.get_trace_context is not available in streaming mode.",
612-
DeprecationWarning,
613-
stacklevel=2,
614-
)
615-
return {}
616-
617609
return self._span.get_trace_context()
618610

619611
# if we are tracing externally (otel), those values take precedence

sentry_sdk/traces.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ def _set_sampling_decision(self, sampling_context: "SamplingContext") -> None:
647647
f"[Tracing] Discarding {self._name} because it's not included in the random sample (sampling rate = {self.sample_rate})"
648648
)
649649

650+
# TODO: Populate other fields as necessary
651+
def get_trace_context(self) -> "dict[str, Any]":
652+
warnings.warn(
653+
"StreamedSpan.get_trace_context is probably incorrect in streaming mode.",
654+
DeprecationWarning,
655+
stacklevel=2,
656+
)
657+
658+
return {
659+
"trace_id": self.trace_id,
660+
"span_id": self.span_id,
661+
"parent_span_id": self.parent_span_id,
662+
}
663+
650664
def _set_segment_attributes(self) -> None:
651665
if not self.is_segment():
652666
self.set_attribute("sentry.segment.id", self.segment.span_id)

0 commit comments

Comments
 (0)