Skip to content

Conversation

jwhitaker-gridcog
Copy link

@jwhitaker-gridcog jwhitaker-gridcog commented Dec 31, 2024

Allow OTEL instrumenter to work even with no DSN.

Context: we are writing tests for our Sentry integration itself, setting up a client like

events = []
c = sentry_sdk.Client(dsn=None, instrumenter='otel', transport=events.append)

, and verifying that events contains spans from OpenTelemetry such as

with tracer.start_as_current_span('fn'):
   raise Exception('boo')

assert events = [...]

This currently doesn't work because the Sentry OTEL integration has some hacks poking into the client and hard-returning if DSN is None.

I conjecture the hard-return can be removed - the check-DSN-to-avoid-sentry-otel-loops logic still works even without the DSN check in on_start().

jwhitaker-gridcog and others added 2 commits December 31, 2024 11:28
Context: we are writing tests for our Sentry integration itself,
setting up a client like

```py
events = []
c = sentry_sdk.Client(dsn=None, instrumenter='otel', transport=events.append)
```

, and verifying that events contains spans from OpenTelemetry such as

```py
with tracer.start_as_current_span('fn'):
   raise Exception('boo')

assert events = [...]
```

This currently doesn't work because the Sentry OTEL integration
has some hacks poking into the client and hard-exiting if DSN is None.

I conjecture this can be removed - the check-DSN-to-avoid-sentry-otel-loops
logic still works even without the DSN check in on_start().
@antonpirker antonpirker requested a review from a team as a code owner September 11, 2025 14:42
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: DSN Parsing Error Causes Application Crash

Removing the DSN validation try/except block in on_start() means malformed (non-None) DSN strings are no longer handled gracefully. This causes _is_sentry_span() to raise an unhandled exception when attempting to parse the DSN, potentially crashing the application.

sentry_sdk/integrations/opentelemetry/span_processor.py#L111-L125

def on_start(self, otel_span, parent_context=None):
# type: (OTelSpan, Optional[context_api.Context]) -> None
client = get_client()
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
return
if not otel_span.get_span_context().is_valid:
return
if self._is_sentry_span(otel_span):
return
trace_data = self._get_trace_data(otel_span, parent_context)

Fix in Cursor Fix in Web


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants