@@ -32,6 +32,11 @@ def mock_otlp_ingest():
3232 url = "https://bla.ingest.sentry.io/api/12312012/integration/otlp/v1/traces/" ,
3333 status = 200 ,
3434 )
35+ responses .add (
36+ responses .POST ,
37+ url = "https://my-collector.example.com/v1/traces" ,
38+ status = 200 ,
39+ )
3540
3641 yield
3742
@@ -233,6 +238,67 @@ def test_propagator_inject_continue_trace(sentry_init):
233238 detach (token )
234239
235240
241+ def test_collector_url_sets_endpoint (sentry_init ):
242+ sentry_init (
243+ dsn = "https://mysecret@bla.ingest.sentry.io/12312012" ,
244+ integrations = [
245+ OTLPIntegration (collector_url = "https://my-collector.example.com/v1/traces" )
246+ ],
247+ )
248+
249+ tracer_provider = get_tracer_provider ()
250+ assert isinstance (tracer_provider , TracerProvider )
251+
252+ (span_processor ,) = tracer_provider ._active_span_processor ._span_processors
253+ assert isinstance (span_processor , BatchSpanProcessor )
254+
255+ exporter = span_processor .span_exporter
256+ assert isinstance (exporter , OTLPSpanExporter )
257+ assert exporter ._endpoint == "https://my-collector.example.com/v1/traces"
258+ assert exporter ._headers is None or "X-Sentry-Auth" not in exporter ._headers
259+
260+
261+ def test_collector_url_takes_precedence_over_dsn (sentry_init ):
262+ sentry_init (
263+ dsn = "https://mysecret@bla.ingest.sentry.io/12312012" ,
264+ integrations = [
265+ OTLPIntegration (collector_url = "https://my-collector.example.com/v1/traces" )
266+ ],
267+ )
268+
269+ tracer_provider = get_tracer_provider ()
270+ assert isinstance (tracer_provider , TracerProvider )
271+
272+ (span_processor ,) = tracer_provider ._active_span_processor ._span_processors
273+ exporter = span_processor .span_exporter
274+ assert isinstance (exporter , OTLPSpanExporter )
275+ # Should use collector_url, NOT the DSN-derived endpoint
276+ assert exporter ._endpoint == "https://my-collector.example.com/v1/traces"
277+ assert (
278+ exporter ._endpoint
279+ != "https://bla.ingest.sentry.io/api/12312012/integration/otlp/v1/traces/"
280+ )
281+
282+
283+ def test_collector_url_none_falls_back_to_dsn (sentry_init ):
284+ sentry_init (
285+ dsn = "https://mysecret@bla.ingest.sentry.io/12312012" ,
286+ integrations = [OTLPIntegration (collector_url = None )],
287+ )
288+
289+ tracer_provider = get_tracer_provider ()
290+ assert isinstance (tracer_provider , TracerProvider )
291+
292+ (span_processor ,) = tracer_provider ._active_span_processor ._span_processors
293+ exporter = span_processor .span_exporter
294+ assert isinstance (exporter , OTLPSpanExporter )
295+ assert (
296+ exporter ._endpoint
297+ == "https://bla.ingest.sentry.io/api/12312012/integration/otlp/v1/traces/"
298+ )
299+ assert "X-Sentry-Auth" in exporter ._headers
300+
301+
236302def test_capture_exceptions_enabled (sentry_init , capture_events ):
237303 sentry_init (
238304 dsn = "https://mysecret@bla.ingest.sentry.io/12312012" ,
0 commit comments