Skip to content

Commit 3bd94e5

Browse files
simplify
1 parent 530a858 commit 3bd94e5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
if TYPE_CHECKING:
3535
from typing import Any, Optional, Union
3636
from opentelemetry import context as context_api
37+
from opentelemetry.trace import SpanContext
3738
from sentry_sdk._types import Event, Hint
3839

3940
OPEN_TELEMETRY_CONTEXT = "otel"
@@ -131,7 +132,7 @@ def on_start(
131132
if self._is_sentry_span(otel_span):
132133
return
133134

134-
trace_data = self._get_trace_data(otel_span, parent_context)
135+
trace_data = self._get_trace_data(otel_span, span_context, parent_context)
135136

136137
parent_span_id = trace_data["parent_span_id"]
137138
sentry_parent_span = (
@@ -256,25 +257,26 @@ def _get_otel_context(self, otel_span: "OTelSpan") -> "dict[str, Any]":
256257
return ctx
257258

258259
def _get_trace_data(
259-
self, otel_span: "OTelSpan", parent_context: "Optional[context_api.Context]"
260+
self,
261+
otel_span: "OTelSpan",
262+
span_context: "SpanContext",
263+
parent_context: "Optional[context_api.Context]",
260264
) -> "dict[str, Any]":
261265
"""
262266
Extracts tracing information from one OTel span and its parent OTel context.
263267
"""
264268
trace_data: "dict[str, Any]" = {}
265-
span_context = otel_span.get_span_context()
266269

267-
if span_context is not None:
268-
span_id = format_span_id(span_context.span_id)
269-
trace_data["span_id"] = span_id
270+
span_id = format_span_id(span_context.span_id)
271+
trace_data["span_id"] = span_id
270272

271-
trace_id = format_trace_id(span_context.trace_id)
272-
trace_data["trace_id"] = trace_id
273+
trace_id = format_trace_id(span_context.trace_id)
274+
trace_data["trace_id"] = trace_id
273275

274-
parent_span_id = (
275-
format_span_id(otel_span.parent.span_id) if otel_span.parent else None
276-
)
277-
trace_data["parent_span_id"] = parent_span_id
276+
parent_span_id = (
277+
format_span_id(otel_span.parent.span_id) if otel_span.parent else None
278+
)
279+
trace_data["parent_span_id"] = parent_span_id
278280

279281
sentry_trace_data = get_value(SENTRY_TRACE_KEY, parent_context)
280282
sentry_trace_data = cast("dict[str, Union[str, bool, None]]", sentry_trace_data)

0 commit comments

Comments
 (0)