diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 1f3162605f..dbc26e28e1 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -9,6 +9,8 @@ from functools import wraps from itertools import chain +from opentelemetry.trace import Span as OTelSpan + from sentry_sdk._types import AnnotatedValue from sentry_sdk.attachments import Attachment from sentry_sdk.consts import ( @@ -748,7 +750,10 @@ def span(self): def span(self, span): # type: (Optional[Span]) -> None """Set current tracing span.""" - self._span = span + if isinstance(span, OTelSpan): + self._span = Span(otel_span=span) + else: + self._span = span @property def profile(self): diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index c56a7e729c..a8ed04dfc4 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -6,7 +6,7 @@ from opentelemetry.trace import ( format_trace_id, format_span_id, - Span as OtelSpan, + Span as OTelSpan, TraceState, get_current_span, INVALID_SPAN, @@ -182,7 +182,7 @@ def __init__( attributes=None, # type: Optional[dict[str, Any]] only_if_parent=False, # type: bool parent_span=None, # type: Optional[Span] - otel_span=None, # type: Optional[OtelSpan] + otel_span=None, # type: Optional[OTelSpan] ): # type: (...) -> None """ @@ -319,7 +319,7 @@ def origin(self, value): def root_span(self): # type: () -> Optional[Span] root_otel_span = cast( - "Optional[OtelSpan]", get_sentry_meta(self._otel_span, "root_span") + "Optional[OTelSpan]", get_sentry_meta(self._otel_span, "root_span") ) return Span(otel_span=root_otel_span) if root_otel_span else None