Skip to content

Commit eff3909

Browse files
Allow OTEL instrumenter to work even with no DSN.
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().
1 parent bb85c26 commit eff3909

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ def on_start(self, otel_span, parent_context=None):
113113
# type: (OTelSpan, Optional[context_api.Context]) -> None
114114
client = get_client()
115115

116-
if not client.dsn:
117-
return
118-
119-
try:
120-
_ = Dsn(client.dsn)
121-
except Exception:
122-
return
123-
124116
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
125117
return
126118

tests/integrations/opentelemetry/test_span_processor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,16 @@ def test_update_span_with_otel_data_db_query():
287287
)
288288

289289

290-
def test_on_start_transaction():
290+
@pytest.mark.parametrize(
291+
["dsn"],
292+
[
293+
pytest.param(
294+
"https://[email protected]/123456", id="with a DSN"
295+
),
296+
pytest.param(None, id="with no DSN"),
297+
],
298+
)
299+
def test_on_start_transaction(dsn):
291300
otel_span = MagicMock()
292301
otel_span.name = "Sample OTel Span"
293302
otel_span.start_time = time.time_ns()
@@ -306,7 +315,7 @@ def test_on_start_transaction():
306315

307316
fake_client = MagicMock()
308317
fake_client.options = {"instrumenter": "otel"}
309-
fake_client.dsn = "https://[email protected]/123456"
318+
fake_client.dsn = dsn
310319
sentry_sdk.get_global_scope().set_client(fake_client)
311320

312321
with mock.patch(

0 commit comments

Comments
 (0)