Skip to content

Commit

Permalink
Allow OTEL instrumenter to work even with no DSN.
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
jwhitaker-gridcog committed Dec 31, 2024
1 parent bb85c26 commit eff3909
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 0 additions & 8 deletions sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ def on_start(self, otel_span, parent_context=None):
# type: (OTelSpan, Optional[context_api.Context]) -> None
client = get_client()

if not client.dsn:
return

try:
_ = Dsn(client.dsn)
except Exception:
return

if client.options["instrumenter"] != INSTRUMENTER.OTEL:
return

Expand Down
13 changes: 11 additions & 2 deletions tests/integrations/opentelemetry/test_span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,16 @@ def test_update_span_with_otel_data_db_query():
)


def test_on_start_transaction():
@pytest.mark.parametrize(
["dsn"],
[
pytest.param(
"https://[email protected]/123456", id="with a DSN"
),
pytest.param(None, id="with no DSN"),
],
)
def test_on_start_transaction(dsn):
otel_span = MagicMock()
otel_span.name = "Sample OTel Span"
otel_span.start_time = time.time_ns()
Expand All @@ -306,7 +315,7 @@ def test_on_start_transaction():

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
fake_client.dsn = "https://[email protected]/123456"
fake_client.dsn = dsn
sentry_sdk.get_global_scope().set_client(fake_client)

with mock.patch(
Expand Down

0 comments on commit eff3909

Please sign in to comment.