refactor(test): rework Sentry.Test to use Bypass-based HTTP testing#1030
Merged
refactor(test): rework Sentry.Test to use Bypass-based HTTP testing#1030
Conversation
fa888c5 to
aa225a0
Compare
aa225a0 to
d6c78a8
Compare
4db6836 to
44bcb01
Compare
44bcb01 to
b7291dd
Compare
12ea13f to
2d7fdbe
Compare
c3a29ea to
5ee699d
Compare
5ee699d to
9efc083
Compare
e0458c4 to
5690133
Compare
Rewrite Sentry.Test to use Bypass for HTTP-level testing instead of in-memory event collection via NimbleOwnership. Events now travel the full pipeline (Client -> Transport -> HTTP) and are captured at the Bypass endpoint, while before_send callbacks capture full Elixir structs for assertion convenience. Key changes: - Rewrite Sentry.Test with Bypass-backed setup_sentry/1 as primary API - Remove maybe_collect/1 calls from Client and Scheduler - Remove test_mode? bypass from Sentry.capture_exception/capture_message - Deprecate test_mode config option - Remove nimble_ownership dependency - Convert all test files to use Bypass-based assertions - Add Bypass envelope collector helpers to test support modules - Update integration tests to use HTTP envelope assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
For some reason this is needed in integration tests
…pop_sentry_transactions, and pop_sentry_logs
587c617 to
ceb4ba4
Compare
e88434f to
c7b049a
Compare
sl0thentr0py
approved these changes
Apr 8, 2026
sl0thentr0py
reviewed
Apr 8, 2026
| try do | ||
| backend.handle_event(log_event, config, handler_id) | ||
| rescue | ||
| _ -> :ok |
Member
There was a problem hiding this comment.
so this will swallow internal problems completely silently?
Collaborator
Author
There was a problem hiding this comment.
@sl0thentr0py so, sometimes logger handler would crash when running tests, and I thought we don't want that given the general contract of making sure our tooling doesn't crash people's code, but this is for sure out of scope here, so I reverted it, and taking a note instead.
Member
There was a problem hiding this comment.
we should not crash people's code indeed, but if there's an underlying problem with the handler we need to fix that first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the in-memory event interception approach in
Sentry.Testwith real HTTP-level testing via Bypass. Events now flow through the full SDK pipeline—encoding, envelope construction, and HTTP transport—before being captured by a local Bypass server and decoded back into structs for assertions.Motivation
The previous
Sentry.Testimplementation usedNimbleOwnershipand an in-process collection mechanism that short-circuited theClient.encode_and_send/4path. This meant test assertions ran against events that never passed through the actual transport layer, masking potential serialization or envelope-packaging bugs.Furthermore, there were various issues with config isolation causing test flakiness.
Key changes
Sentry.Testrewrite — The module now spins up a per-test Bypass instance viasetup_sentry/1, wiresbefore_send/before_send_logcallbacks to capture event structs, and points the DSN at the local endpoint. Collection state is stored in an isolated ETS table per test process.Sentry.Test.Registry(new) — A GenServer started in the OTP supervision tree whentest_mode: true. It manages the ETS table for collectors and boots a global default Bypass instance so that tests withoutsetup_sentry/1still get a valid DSN (preserving the old{:ok, ""}return value).Sentry.Clientsimplified — AllSentry.Test.maybe_collect/1branches removed fromencode_and_send/4. Events always go through the normal transport path; test capture happens at the HTTP boundary instead.nimble_ownershipdependency removed — No longer needed since collection is ETS-based rather than ownership-based. ETS is simpler and avoids the complexity of ownership transfer/allowance bookkeeping across process boundaries; since events are now captured at the HTTP layer by Bypass (which already handles multi-process requests), a shared ETS table keyed by test PID provides natural isolation without extra machinery.Backward compatibility —
start_collecting_sentry_reports/0,pop_sentry_reports/0,pop_sentry_transactions/0, andpop_sentry_logs/0continue to work. Theowner_pidparameter on these functions is deprecated (no longer meaningful with ETS-based collection). A dedicatedtest_backward_compat_test.exsvalidates the legacy workflow.Follow-up
A separate PR will be opened later on with convenient helpers and improved tests that cover more ground giving us more confidence with the full stack exercised during tests.
It will also make it much nicer to use Sentry test mode in user's test suites 🎉