Skip to content

Commit b694764

Browse files
fix: Introduce get_current_streamed_span to keep types backwards compatible
1 parent d58ac65 commit b694764

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

sentry_sdk/api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,22 @@ def set_measurement(name: str, value: float, unit: "MeasurementUnit" = "") -> No
422422

423423
def get_current_span(
424424
scope: "Optional[Scope]" = None,
425-
) -> "Optional[Union[Span, StreamedSpan]]":
425+
) -> "Optional[Span]":
426426
"""
427427
Returns the currently active span if there is one running, otherwise `None`
428428
"""
429429
return tracing_utils.get_current_span(scope)
430430

431431

432+
def get_current_streamed_span(
433+
scope: "Optional[Scope]" = None,
434+
) -> "Optional[StreamedSpan]":
435+
"""
436+
Returns the currently active streamed span if there is one running, otherwise `None`
437+
"""
438+
return tracing_utils.get_current_streamed_span(scope)
439+
440+
432441
def get_traceparent() -> "Optional[str]":
433442
"""
434443
Returns the traceparent either from the active span or from the scope.

sentry_sdk/scope.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,15 @@ def set_user(self, value: "Optional[Dict[str, Any]]") -> None:
877877
session.update(user=value)
878878

879879
@property
880-
def span(self) -> "Optional[Union[Span, StreamedSpan]]":
880+
def span(self) -> "Optional[Span]":
881881
"""Get/set current tracing span or transaction."""
882882
return self._span
883883

884+
@property
885+
def streamed_span(self) -> "Optional[StreamedSpan]":
886+
"""Get/set current tracing span."""
887+
return self._span
888+
884889
@span.setter
885890
def span(self, span: "Optional[Union[Span, StreamedSpan]]") -> None:
886891
self._span = span

sentry_sdk/tracing_utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ def sync_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
11941194

11951195
def get_current_span(
11961196
scope: "Optional[sentry_sdk.Scope]" = None,
1197-
) -> "Optional[Union[Span, StreamedSpan]]":
1197+
) -> "Optional[Span]":
11981198
"""
11991199
Returns the currently active span if there is one running, otherwise `None`
12001200
"""
@@ -1203,6 +1203,17 @@ def get_current_span(
12031203
return current_span
12041204

12051205

1206+
def get_current_streamed_span(
1207+
scope: "Optional[sentry_sdk.Scope]" = None,
1208+
) -> "Optional[StreamedSpan]":
1209+
"""
1210+
Returns the currently active span if there is one running, otherwise `None`
1211+
"""
1212+
scope = scope or sentry_sdk.get_current_scope()
1213+
current_span = scope.streamed_span
1214+
return current_span
1215+
1216+
12061217
def set_span_errored(span: "Optional[Union[Span, StreamedSpan]]" = None) -> None:
12071218
"""
12081219
Set the status of the current or given span to INTERNAL_ERROR.

0 commit comments

Comments
 (0)