Skip to content

Commit 74f1e4a

Browse files
committed
wip
1 parent 2e1b785 commit 74f1e4a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

sentry_sdk/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk._types import TYPE_CHECKING
66
from sentry_sdk.consts import INSTRUMENTER
77
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
8-
from sentry_sdk.tracing import NoOpSpan, Transaction
8+
from sentry_sdk.tracing import POTelSpan, Transaction
99

1010
if TYPE_CHECKING:
1111
from collections.abc import Mapping
@@ -286,14 +286,14 @@ def flush(
286286
def start_span(
287287
**kwargs, # type: Any
288288
):
289-
# type: (...) -> Span
289+
# type: (...) -> POTelSpan
290290
return tracing.start_span(**kwargs)
291291

292292

293293
def start_inactive_span(
294294
**kwargs, # type: Any
295295
):
296-
# type: (...) -> Span
296+
# type: (...) -> POTelSpan
297297
return tracing.start_inactive_span(**kwargs)
298298

299299

@@ -303,7 +303,7 @@ def start_transaction(
303303
custom_sampling_context=None, # type: Optional[SamplingContext]
304304
**kwargs, # type: Unpack[TransactionKwargs]
305305
):
306-
# type: (...) -> Union[Transaction, NoOpSpan]
306+
# type: (...) -> POTelSpan
307307
"""
308308
.. deprecated:: 3.0.0
309309
This function is deprecated and will be removed in a future release.

sentry_sdk/integrations/opentelemetry/consts.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
SENTRY_BAGGAGE_KEY = create_key("sentry-baggage")
66
OTEL_SENTRY_CONTEXT = "otel"
77
SPAN_ORIGIN = "auto.otel"
8+
9+
10+
class SentrySpanAttribute:
11+
# XXX better name
12+
# XXX not all of these need separate attributes, we might just use
13+
# existing otel attrs for some
14+
DESCRIPTION = "sentry.description"
15+
OP = "sentry.op"
16+
ORIGIN = "sentry.origin"

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import cast
44

55
from opentelemetry.context import get_value
6-
from opentelemetry.sdk.trace import SpanProcessor, ReadableSpan as OTelSpan
6+
from opentelemetry.sdk.trace import SpanProcessor, Span as OTelSpan
77
from opentelemetry.trace import (
88
format_span_id,
99
format_trace_id,

sentry_sdk/tracing.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ class POTelSpan:
11701170
# XXX Maybe it makes sense to repurpose the existing Span class for this.
11711171
# For now I'm keeping this class separate to have a clean slate.
11721172

1173-
# XXX The wrapper itself should have as little state as possible.
1173+
# XXX The wrapper itself should have as little state as possible
11741174

11751175
def __init__(
11761176
self,
@@ -1189,12 +1189,21 @@ def __init__(
11891189
origin="manual", # type: str
11901190
):
11911191
# type: (...) -> None
1192-
self._otel_span = tracer.start_span(description or "")
1192+
from sentry_sdk.integrations.opentelemetry.consts import SentrySpanAttribute
1193+
1194+
self._otel_span = tracer.start_span(description or op or "") # XXX
11931195
self._active = active
1194-
# XXX
1196+
1197+
self._otel_span.set_attribute(SentrySpanAttribute.ORIGIN, origin)
1198+
if op is not None:
1199+
self._otel_span.set_attribute(SentrySpanAttribute.OP, op)
1200+
if description is not None:
1201+
self._otel_span.set_attribute(SentrySpanAttribute.DESCRIPTION, description)
11951202

11961203
def __enter__(self):
11971204
# type: () -> POTelSpan
1205+
# XXX use_span? https://github.com/open-telemetry/opentelemetry-python/blob/3836da8543ce9751051e38a110c0468724042e62/opentelemetry-api/src/opentelemetry/trace/__init__.py#L547
1206+
#
11981207
# create a Context object with parent set as current span
11991208
if self._active:
12001209
ctx = otel_trace.set_span_in_context(self._otel_span)
@@ -1206,7 +1215,7 @@ def __enter__(self):
12061215
def __exit__(self, ty, value, tb):
12071216
# type: (Optional[Any], Optional[Any], Optional[Any]) -> None
12081217
self._otel_span.end()
1209-
1218+
# XXX set status to error if unset and an exception occurred?
12101219
if self._active:
12111220
context.detach(self._ctx_token)
12121221

0 commit comments

Comments
 (0)