Skip to content

Commit

Permalink
Move PotelSentrySpanProcessor to SentrySpanProcessor
Browse files Browse the repository at this point in the history
* remove the older one
* fix propagator `inject` to not rely on old SentrySpanProcessor span
  map
  • Loading branch information
sl0thentr0py committed Nov 28, 2024
1 parent 7c2d770 commit ce06df2
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 1,263 deletions.
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/opentelemetry/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.integrations.opentelemetry.propagator import SentryPropagator
from sentry_sdk.integrations.opentelemetry.potel_span_processor import (
PotelSentrySpanProcessor,
from sentry_sdk.integrations.opentelemetry.span_processor import (
SentrySpanProcessor,
)
from sentry_sdk.integrations.opentelemetry.contextvars_context import (
SentryContextVarsRuntimeContext,
Expand Down Expand Up @@ -79,7 +79,7 @@ def _setup_scope_context_management():
def _setup_sentry_tracing():
# type: () -> None
provider = TracerProvider(sampler=SentrySampler())
provider.add_span_processor(PotelSentrySpanProcessor())
provider.add_span_processor(SentrySpanProcessor())
trace.set_tracer_provider(provider)

set_global_textmap(SentryPropagator())
Expand Down
273 changes: 0 additions & 273 deletions sentry_sdk/integrations/opentelemetry/potel_span_processor.py

This file was deleted.

37 changes: 14 additions & 23 deletions sentry_sdk/integrations/opentelemetry/propagator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import cast

from opentelemetry import trace
from opentelemetry.context import (
Context,
get_current,
get_value,
set_value,
)
from opentelemetry.propagators.textmap import (
Expand All @@ -21,9 +24,7 @@
from sentry_sdk.integrations.opentelemetry.consts import (
SENTRY_BAGGAGE_KEY,
SENTRY_TRACE_KEY,
)
from sentry_sdk.integrations.opentelemetry.span_processor import (
SentrySpanProcessor,
SENTRY_SCOPES_KEY,
)
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
Expand All @@ -35,6 +36,7 @@

if TYPE_CHECKING:
from typing import Optional, Set
from sentry_sdk.integrations.opentelemetry.scope import PotelScope


class SentryPropagator(TextMapPropagator):
Expand All @@ -47,6 +49,7 @@ def extract(self, carrier, context=None, getter=default_getter):
if context is None:
context = get_current()

# TODO-neel-potel cleanup with continue_trace / isolation_scope
sentry_trace = getter.get(carrier, SENTRY_TRACE_HEADER_NAME)
if not sentry_trace:
return context
Expand Down Expand Up @@ -89,27 +92,15 @@ def inject(self, carrier, context=None, setter=default_setter):
if context is None:
context = get_current()

current_span = trace.get_current_span(context)
current_span_context = current_span.get_span_context()

if not current_span_context.is_valid:
return

span_id = trace.format_span_id(current_span_context.span_id)

span_map = SentrySpanProcessor().otel_span_map
sentry_span = span_map.get(span_id, None)
if not sentry_span:
return

setter.set(carrier, SENTRY_TRACE_HEADER_NAME, sentry_span.to_traceparent())
scopes = get_value(SENTRY_SCOPES_KEY, context)
if scopes:
scopes = cast("tuple[PotelScope, PotelScope]", scopes)
(current_scope, _) = scopes

if sentry_span.containing_transaction:
baggage = sentry_span.containing_transaction.get_baggage()
if baggage:
baggage_data = baggage.serialize()
if baggage_data:
setter.set(carrier, BAGGAGE_HEADER_NAME, baggage_data)
# TODO-neel-potel check trace_propagation_targets
# TODO-neel-potel test propagator works with twp
for (key, value) in current_scope.iter_trace_propagation_headers():
setter.set(carrier, key, value)

@property
def fields(self):
Expand Down
Loading

0 comments on commit ce06df2

Please sign in to comment.