diff --git a/sentry_sdk/integrations/opentelemetry/consts.py b/sentry_sdk/integrations/opentelemetry/consts.py index aca364fd54..8af978f8fd 100644 --- a/sentry_sdk/integrations/opentelemetry/consts.py +++ b/sentry_sdk/integrations/opentelemetry/consts.py @@ -21,3 +21,4 @@ class SentrySpanAttribute: ORIGIN = "sentry.origin" MEASUREMENT = "sentry.measurement" TAG = "sentry.tag" + NAME = "sentry.name" diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 6496327834..43a17e44ff 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -1200,6 +1200,7 @@ def __init__( scope=None, # type: Optional[Scope] start_timestamp=None, # type: Optional[Union[datetime, float]] origin=None, # type: Optional[str] + name=None, # type: Optional[str] **_, # type: dict[str, object] ): # type: (...) -> None @@ -1224,6 +1225,7 @@ def __init__( self.origin = origin or DEFAULT_SPAN_ORIGIN self.op = op self.description = description + self.name = name if status is not None: self.set_status(status) @@ -1303,7 +1305,9 @@ def containing_transaction(self): .. deprecated:: 3.0.0 This will be removed in the future. Use :func:`root_span` instead. """ - logger.warning("Deprecated: This will be removed in the future.") + logger.warning( + "Deprecated: This will be removed in the future. Use root_span instead." + ) return self.root_span @containing_transaction.setter @@ -1318,17 +1322,11 @@ def containing_transaction(self, value): @property def root_span(self): - if isinstance(self._otel_span, otel_trace.NonRecordingSpan): - return None - - parent = None - while True: - if self._otel_span.parent: - parent = self._otel_span.parent - else: - break - - return parent + # type: () -> Optional[POTelSpan] + # XXX implement this + # there's a span.parent property, but it returns the parent spancontext + # not sure if there's a way to retrieve the parent with pure otel. + return None @root_span.setter def root_span(self, value): @@ -1371,7 +1369,7 @@ def op(self): # type: () -> Optional[str] from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute - self._otel_span.attributes.get(SentrySpanAttribute.OP) + return self._otel_span.attributes.get(SentrySpanAttribute.OP) @op.setter def op(self, value): @@ -1383,13 +1381,18 @@ def op(self, value): @property def name(self): - # type: () -> str - pass + # type: () -> Optional[str] + from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute + + return self._otel_span.attributes.get(SentrySpanAttribute.NAME) @name.setter def name(self, value): - # type: (str) -> None - pass + # type: (Optional[str]) -> None + from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute + + if value is not None: + self._otel_span.set_attribute(SentrySpanAttribute.NAME, value) @property def source(self):