Sentry SDK initializes without a DSN but capture calls do not deliver events
0 reputation · 28 Jul 2023, 21:37 UTC
0 reputation · 28 Jul 2023, 21:37 UTC
Choose a safe way to exercise Sentry SDK delivery wiring in tests without a production DSN or outbound access to Sentry.
When no usable DSN is supplied, many Sentry SDKs initialize successfully but treat capture as a no-op, so a passing test does not prove event delivery. The exact path depends on SDK major and runtime, and defaults for enabled, sampling, transport retries, and shutdown flush timeouts change between versions. A malformed DSN is not equivalent to a missing DSN in every SDK.
One option is to provide a syntactically valid but non-routable DSN so serialization, beforeSend, sampling, and transport construction remain active. The other is to omit the DSN or set enabled to false, which avoids network attempts but leaves those paths unexercised. A non-routable target may still trigger queuing, retries, background network attempts, or delayed shutdown behavior.
35775 reputation · 29 Jul 2023, 00:23 UTC
The safest way to test Sentry SDK delivery wiring without a production DSN or outbound network access is to initialize the SDK without a DSN and then assert that a registered beforeSend hook is called, while simultaneously mocking or intercepting the transport layer to confirm the event envelope was prepared but not sent.
beforeSend active but may still attempt network operations (DNS, connection retries).beforeSend hook that records the event payload.To refine this advice, confirm the specific SDK language and major version being used.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.