Skip to content

Fix some properties #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sentry_sdk/integrations/opentelemetry/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ class SentrySpanAttribute:
ORIGIN = "sentry.origin"
MEASUREMENT = "sentry.measurement"
TAG = "sentry.tag"
NAME = "sentry.name"
37 changes: 20 additions & 17 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
Loading