View Source Sentry.Test.Config (Sentry v13.0.1)
Provides per-test configuration isolation for the Sentry SDK.
When test_mode: true is configured, the SDK automatically uses this module
as the :namespace resolver, enabling tests to override Sentry configuration
on a per-test basis without affecting other tests, even when running with
async: true.
Usage
Use put/1 in your test setup blocks to set per-test configuration overrides:
setup do
Sentry.Test.Config.put(dsn: "http://public:secret@localhost:#{bypass.port}/1")
endHow It Works
Each test's overrides live in a Sentry.Test.Scope struct stored in
:persistent_term under {:sentry_test_scope, test_pid}. The namespace/1
function asks Sentry.Test.Scope.Registry to resolve a scope for the
current process by trying three strategies in order:
Walking
[self() | Process.get(:"$callers", [])].- Walking the
:"$ancestors"chain transitively against each scope'sallowed_pids(populated viaallow/2and by the auto-allow of globally-supervised pids on the firstput/1call). - Walking the
:"$ancestors"chain against each scope's owner pid — covers GenServers started viastart_supervised/1.
Globally-supervised processes (:logger, :logger_sup,
Sentry.Supervisor) have no caller/ancestor link back to any test.
put/1 auto-soft-allows them onto the calling scope so strategy 2
routes their config queries to the right test transparently, without
requiring downstream suites to call allow/2 themselves.
Overrides are automatically cleaned up when the test exits via
ExUnit.Callbacks.on_exit/1.
Summary
Functions
Allows allowed_pid to read the configuration of owner_pid's test scope.
Activates per-test configuration isolation if test_mode: true is configured
and no custom :namespace resolver has been explicitly set.
Resolves config namespace for the current process.
Sets per-test configuration overrides for the current test process.
Functions
Allows allowed_pid to read the configuration of owner_pid's test scope.
Use this when a supervised process (such as a GenServer started via
start_supervised!/1) does not inherit the test process's $callers chain
and cannot be reached via the $ancestors walk (for example, a
globally-registered process started at application boot).
The mapping is automatically cleaned up when the test exits.
Example
scheduler_pid = Sentry.TelemetryProcessor.get_scheduler(processor_name)
Sentry.Test.Config.allow(self(), scheduler_pid)
@spec maybe_activate() :: :ok
Activates per-test configuration isolation if test_mode: true is configured
and no custom :namespace resolver has been explicitly set.
Called automatically by Sentry.Application on startup. You do not need to
call this manually.
Resolves config namespace for the current process.
Returns {:ok, value} if an override is found, or :default to fall back
to global configuration.
@spec put(keyword()) :: :ok
Sets per-test configuration overrides for the current test process.
Each key-value pair is validated through Sentry.Config.validate!/1 before
being stored. Overrides are automatically cleaned up when the test exits.
Example
setup do
Sentry.Test.Config.put(
dsn: "http://public:secret@localhost:#{bypass.port}/1",
send_result: :sync
)
end