Skip to content

Commit 52cd46d

Browse files
committed
.
1 parent cc772a0 commit 52cd46d

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

sentry_sdk/scope.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,11 @@ def get_traceparent(self, *args: "Any", **kwargs: "Any") -> "Optional[str]":
583583
client = self.get_client()
584584

585585
# If we have an active span, return traceparent from there
586-
if has_tracing_enabled(client.options) and self.span is not None:
586+
if (
587+
has_tracing_enabled(client.options)
588+
and self.span is not None
589+
and not isinstance(self.span, NoOpStreamedSpan)
590+
):
587591
return self.span._to_traceparent()
588592

589593
# else return traceparent from the propagation context
@@ -597,7 +601,11 @@ def get_baggage(self, *args: "Any", **kwargs: "Any") -> "Optional[Baggage]":
597601
client = self.get_client()
598602

599603
# If we have an active span, return baggage from there
600-
if has_tracing_enabled(client.options) and self.span is not None:
604+
if (
605+
has_tracing_enabled(client.options)
606+
and self.span is not None
607+
and not isinstance(self.span, NoOpStreamedSpan)
608+
):
601609
return self.span._to_baggage()
602610

603611
# else return baggage from the propagation context
@@ -607,7 +615,11 @@ def get_trace_context(self) -> "Dict[str, Any]":
607615
"""
608616
Returns the Sentry "trace" context from the Propagation Context.
609617
"""
610-
if has_tracing_enabled(self.get_client().options) and self._span is not None:
618+
if (
619+
has_tracing_enabled(self.get_client().options)
620+
and self._span is not None
621+
and not isinstance(self.span, NoOpStreamedSpan)
622+
):
611623
return self._span._get_trace_context()
612624

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

tests/tracing/test_span_streaming.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,16 +729,14 @@ def test_outgoing_traceparent_and_baggage_when_noop_span_is_active(
729729
noop_span_id = span.span_id
730730

731731
traceparent = sentry_sdk.get_traceparent()
732-
assert traceparent != f"{noop_trace_id}-{noop_span_id}-0"
733-
assert traceparent == f"{propagation_trace_id}-{propagation_span_id}-0"
732+
assert traceparent != f"{noop_trace_id}-{noop_span_id}"
733+
assert traceparent == f"{propagation_trace_id}-{propagation_span_id}"
734734

735735
baggage = sentry_sdk.get_baggage()
736736
baggage_items = dict(tuple(item.split("=")) for item in baggage.split(","))
737737
assert "sentry-trace_id" in baggage_items
738738
assert baggage_items["sentry-trace_id"] != noop_trace_id
739739
assert baggage_items["sentry-trace_id"] == propagation_trace_id
740-
assert "sentry-sampled" in baggage_items
741-
assert baggage_items["sentry-sampled"] == "false"
742740

743741

744742
def test_trace_decorator(sentry_init, capture_envelopes):

0 commit comments

Comments
 (0)