@@ -581,8 +581,12 @@ def get_traceparent(self, *args: "Any", **kwargs: "Any") -> "Optional[str]":
581581 client = self .get_client ()
582582
583583 # If we have an active span, return traceparent from there
584- if has_tracing_enabled (client .options ) and self .span is not None :
585- return self .span .to_traceparent ()
584+ if (
585+ has_tracing_enabled (client .options )
586+ and self .span is not None
587+ and not isinstance (self .span , NoOpStreamedSpan )
588+ ):
589+ return self .span ._to_traceparent ()
586590
587591 # else return traceparent from the propagation context
588592 return self .get_active_propagation_context ().to_traceparent ()
@@ -595,8 +599,12 @@ def get_baggage(self, *args: "Any", **kwargs: "Any") -> "Optional[Baggage]":
595599 client = self .get_client ()
596600
597601 # If we have an active span, return baggage from there
598- if has_tracing_enabled (client .options ) and self .span is not None :
599- return self .span .to_baggage ()
602+ if (
603+ has_tracing_enabled (client .options )
604+ and self .span is not None
605+ and not isinstance (self .span , NoOpStreamedSpan )
606+ ):
607+ return self .span ._to_baggage ()
600608
601609 # else return baggage from the propagation context
602610 return self .get_active_propagation_context ().get_baggage ()
@@ -605,8 +613,12 @@ def get_trace_context(self) -> "Dict[str, Any]":
605613 """
606614 Returns the Sentry "trace" context from the Propagation Context.
607615 """
608- if has_tracing_enabled (self .get_client ().options ) and self ._span is not None :
609- return self ._span .get_trace_context ()
616+ if (
617+ has_tracing_enabled (self .get_client ().options )
618+ and self ._span is not None
619+ and not isinstance (self ._span , NoOpStreamedSpan )
620+ ):
621+ return self ._span ._get_trace_context ()
610622
611623 # if we are tracing externally (otel), those values take precedence
612624 external_propagation_context = get_external_propagation_context ()
@@ -670,8 +682,12 @@ def iter_trace_propagation_headers(
670682 span = kwargs .pop ("span" , None )
671683 span = span or self .span
672684
673- if has_tracing_enabled (client .options ) and span is not None :
674- for header in span .iter_headers ():
685+ if (
686+ has_tracing_enabled (client .options )
687+ and span is not None
688+ and not isinstance (span , NoOpStreamedSpan )
689+ ):
690+ for header in span ._iter_headers ():
675691 yield header
676692 elif has_external_propagation_context ():
677693 # when we have an external_propagation_context (otlp)
@@ -718,7 +734,7 @@ def clear(self) -> None:
718734 self .clear_breadcrumbs ()
719735 self ._should_capture : bool = True
720736
721- self ._span : "Optional[Span]" = None
737+ self ._span : "Optional[Union[ Span, StreamedSpan] ]" = None
722738 self ._session : "Optional[Session]" = None
723739 self ._force_auto_session_tracking : "Optional[bool]" = None
724740
@@ -772,6 +788,14 @@ def transaction(self) -> "Any":
772788 if self ._span is None :
773789 return None
774790
791+ if isinstance (self ._span , StreamedSpan ):
792+ warnings .warn (
793+ "Scope.transaction is not available in streaming mode." ,
794+ DeprecationWarning ,
795+ stacklevel = 2 ,
796+ )
797+ return None
798+
775799 # there is an orphan span on the scope
776800 if self ._span .containing_transaction is None :
777801 return None
@@ -801,17 +825,36 @@ def transaction(self, value: "Any") -> None:
801825 "Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead."
802826 )
803827 self ._transaction = value
804- if self ._span and self ._span .containing_transaction :
805- self ._span .containing_transaction .name = value
828+ if self ._span :
829+ if isinstance (self ._span , StreamedSpan ):
830+ warnings .warn (
831+ "Scope.transaction is not available in streaming mode." ,
832+ DeprecationWarning ,
833+ stacklevel = 2 ,
834+ )
835+ return None
836+
837+ if self ._span .containing_transaction :
838+ self ._span .containing_transaction .name = value
806839
807840 def set_transaction_name (self , name : str , source : "Optional[str]" = None ) -> None :
808841 """Set the transaction name and optionally the transaction source."""
809842 self ._transaction = name
810-
811- if self ._span and self ._span .containing_transaction :
812- self ._span .containing_transaction .name = name
813- if source :
814- self ._span .containing_transaction .source = source
843+ if self ._span :
844+ if isinstance (self ._span , NoOpStreamedSpan ):
845+ return
846+
847+ elif isinstance (self ._span , StreamedSpan ):
848+ self ._span ._segment .name = name
849+ if source :
850+ self ._span ._segment .set_attribute (
851+ "sentry.span.source" , getattr (source , "value" , source )
852+ )
853+
854+ elif self ._span .containing_transaction :
855+ self ._span .containing_transaction .name = name
856+ if source :
857+ self ._span .containing_transaction .source = source
815858
816859 if source :
817860 self ._transaction_info ["source" ] = source
@@ -834,12 +877,12 @@ def set_user(self, value: "Optional[Dict[str, Any]]") -> None:
834877 session .update (user = value )
835878
836879 @property
837- def span (self ) -> "Optional[Span]" :
880+ def span (self ) -> "Optional[Union[ Span, StreamedSpan] ]" :
838881 """Get/set current tracing span or transaction."""
839882 return self ._span
840883
841884 @span .setter
842- def span (self , span : "Optional[Span]" ) -> None :
885+ def span (self , span : "Optional[Union[ Span, StreamedSpan] ]" ) -> None :
843886 self ._span = span
844887 # XXX: this differs from the implementation in JS, there Scope.setSpan
845888 # does not set Scope._transactionName.
@@ -1148,6 +1191,15 @@ def start_span(
11481191 be removed in the next major version. Going forward, it should only
11491192 be used by the SDK itself.
11501193 """
1194+ client = sentry_sdk .get_client ()
1195+ if has_span_streaming_enabled (client .options ):
1196+ warnings .warn (
1197+ "Scope.start_span is not available in streaming mode." ,
1198+ DeprecationWarning ,
1199+ stacklevel = 2 ,
1200+ )
1201+ return NoOpSpan ()
1202+
11511203 if kwargs .get ("description" ) is not None :
11521204 warnings .warn (
11531205 "The `description` parameter is deprecated. Please use `name` instead." ,
@@ -1167,6 +1219,9 @@ def start_span(
11671219
11681220 # get current span or transaction
11691221 span = self .span or self .get_isolation_scope ().span
1222+ if isinstance (span , StreamedSpan ):
1223+ # make mypy happy
1224+ return NoOpSpan ()
11701225
11711226 if span is None :
11721227 # New spans get the `trace_id` from the scope
0 commit comments