@@ -584,7 +584,7 @@ def get_traceparent(self, *args: "Any", **kwargs: "Any") -> "Optional[str]":
584584
585585 # If we have an active span, return traceparent from there
586586 if has_tracing_enabled (client .options ) and self .span is not None :
587- return self .span .to_traceparent ()
587+ return self .span ._to_traceparent ()
588588
589589 # else return traceparent from the propagation context
590590 return self .get_active_propagation_context ().to_traceparent ()
@@ -598,7 +598,7 @@ def get_baggage(self, *args: "Any", **kwargs: "Any") -> "Optional[Baggage]":
598598
599599 # If we have an active span, return baggage from there
600600 if has_tracing_enabled (client .options ) and self .span is not None :
601- return self .span .to_baggage ()
601+ return self .span ._to_baggage ()
602602
603603 # else return baggage from the propagation context
604604 return self .get_active_propagation_context ().get_baggage ()
@@ -608,7 +608,7 @@ def get_trace_context(self) -> "Dict[str, Any]":
608608 Returns the Sentry "trace" context from the Propagation Context.
609609 """
610610 if has_tracing_enabled (self .get_client ().options ) and self ._span is not None :
611- return self ._span .get_trace_context ()
611+ return self ._span ._get_trace_context ()
612612
613613 # if we are tracing externally (otel), those values take precedence
614614 external_propagation_context = get_external_propagation_context ()
@@ -673,7 +673,7 @@ def iter_trace_propagation_headers(
673673 span = span or self .span
674674
675675 if has_tracing_enabled (client .options ) and span is not None :
676- for header in span .iter_headers ():
676+ for header in span ._iter_headers ():
677677 yield header
678678 elif has_external_propagation_context ():
679679 # when we have an external_propagation_context (otlp)
@@ -720,7 +720,7 @@ def clear(self) -> None:
720720 self .clear_breadcrumbs ()
721721 self ._should_capture : bool = True
722722
723- self ._span : "Optional[Span]" = None
723+ self ._span : "Optional[Union[ Span, StreamedSpan] ]" = None
724724 self ._session : "Optional[Session]" = None
725725 self ._force_auto_session_tracking : "Optional[bool]" = None
726726
@@ -774,6 +774,14 @@ def transaction(self) -> "Any":
774774 if self ._span is None :
775775 return None
776776
777+ if isinstance (self ._span , StreamedSpan ):
778+ warnings .warn (
779+ "Scope.transaction is not available in streaming mode." ,
780+ DeprecationWarning ,
781+ stacklevel = 2 ,
782+ )
783+ return None
784+
777785 # there is an orphan span on the scope
778786 if self ._span .containing_transaction is None :
779787 return None
@@ -803,17 +811,39 @@ def transaction(self, value: "Any") -> None:
803811 "Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead."
804812 )
805813 self ._transaction = value
806- if self ._span and self ._span .containing_transaction :
807- self ._span .containing_transaction .name = value
814+ if self ._span :
815+ if isinstance (self ._span , StreamedSpan ):
816+ warnings .warn (
817+ "Scope.transaction is not available in streaming mode." ,
818+ DeprecationWarning ,
819+ stacklevel = 2 ,
820+ )
821+ return None
822+
823+ if self ._span .containing_transaction :
824+ self ._span .containing_transaction .name = value
808825
809826 def set_transaction_name (self , name : str , source : "Optional[str]" = None ) -> None :
810827 """Set the transaction name and optionally the transaction source."""
811828 self ._transaction = name
829+ if self ._span :
830+ if isinstance (self ._span , NoOpStreamedSpan ):
831+ return
832+
833+ elif isinstance (self ._span , StreamedSpan ):
834+ self ._span ._segment .name = name
835+ if source :
836+ self ._span ._segment .set_attribute (
837+ "sentry.span.source" , getattr (source , "value" , source )
838+ )
839+
840+ elif self ._span .containing_transaction :
841+ self ._span .containing_transaction .name = name
842+ if source :
843+ self ._span .containing_transaction .source = source
812844
813- if self ._span and self ._span .containing_transaction :
814- self ._span .containing_transaction .name = name
815- if source :
816- self ._span .containing_transaction .source = source
845+ if source :
846+ self ._transaction_info ["source" ] = source
817847
818848 if source :
819849 self ._transaction_info ["source" ] = source
@@ -836,12 +866,12 @@ def set_user(self, value: "Optional[Dict[str, Any]]") -> None:
836866 session .update (user = value )
837867
838868 @property
839- def span (self ) -> "Optional[Span]" :
869+ def span (self ) -> "Optional[Union[ Span, StreamedSpan] ]" :
840870 """Get/set current tracing span or transaction."""
841871 return self ._span
842872
843873 @span .setter
844- def span (self , span : "Optional[Span]" ) -> None :
874+ def span (self , span : "Optional[Union[ Span, StreamedSpan] ]" ) -> None :
845875 self ._span = span
846876 # XXX: this differs from the implementation in JS, there Scope.setSpan
847877 # does not set Scope._transactionName.
@@ -1150,6 +1180,15 @@ def start_span(
11501180 be removed in the next major version. Going forward, it should only
11511181 be used by the SDK itself.
11521182 """
1183+ client = sentry_sdk .get_client ()
1184+ if has_span_streaming_enabled (client .options ):
1185+ warnings .warn (
1186+ "Scope.start_span is not available in streaming mode." ,
1187+ DeprecationWarning ,
1188+ stacklevel = 2 ,
1189+ )
1190+ return NoOpSpan ()
1191+
11531192 if kwargs .get ("description" ) is not None :
11541193 warnings .warn (
11551194 "The `description` parameter is deprecated. Please use `name` instead." ,
@@ -1169,6 +1208,9 @@ def start_span(
11691208
11701209 # get current span or transaction
11711210 span = self .span or self .get_isolation_scope ().span
1211+ if isinstance (span , StreamedSpan ):
1212+ # make mypy happy
1213+ return NoOpSpan ()
11721214
11731215 if span is None :
11741216 # New spans get the `trace_id` from the scope
0 commit comments