@@ -5,12 +5,32 @@ defmodule Sentry.Test do
55 ## Usage
66
77 This module is based on **collecting** reported events and then retrieving
8- them to perform assertions. You can start collecting events from a process
8+ them to perform assertions. The functionality here is only available if the
9+ `:test_mode` configuration option is set to `true`—see
10+ [`Sentry`'s configuration section](sentry.html#module-configuration).
11+ You can start collecting events from a process
912 by calling `start_collecting_sentry_reports/0`. Then, you can use Sentry
1013 as normal and report events (through functions such as `Sentry.capture_message/1`
1114 or `Sentry.capture_exception/1`). Finally, you can retrieve the collected events
1215 by calling `pop_sentry_reports/0`.
1316
17+ > #### Test Mode and DSN {: .info}
18+ >
19+ > If `:test_mode` is `true`, the `:dsn` option behaves differently. When `:dsn` is
20+ > not set or `nil` and you're collecting events, you'll still be able to collect
21+ > events—even if under normal circumstances a missing `:dsn` means events don't get
22+ > reported. If `:dsn` is `nil` and you're not collecting events, the event is simply
23+ > ignored. See the table below for a summary for this behavior.
24+
25+ | `:test_mode` | `:dsn` | Collecting events? | Behavior |
26+ |--------------|--------|--------------------|--------------------------------------------------------|
27+ | `true` | `nil` | yes | Event is collected |
28+ | `true` | `nil` | no | Event is ignored (silently) |
29+ | `true` | set | yes | Event is collected |
30+ | `true` | set | no | Makes HTTP request to configured DSN (could be Bypass) |
31+ | `false` | `nil` | irrelevant | Ignores event |
32+ | `false` | set | irrelevant | Makes HTTP request to configured DSN (could be Bypass) |
33+
1434 ## Examples
1535
1636 Let's imagine writing a test using the functions in this module. First, we need to
@@ -64,6 +84,7 @@ defmodule Sentry.Test do
6484 @ spec maybe_collect ( Sentry.Event . t ( ) ) :: :collected | :not_collecting
6585 def maybe_collect ( % Sentry.Event { } = event ) do
6686 if Sentry.Config . test_mode? ( ) do
87+ dsn_set? = not is_nil ( Sentry.Config . dsn ( ) )
6788 ensure_ownership_server_started ( )
6889
6990 case NimbleOwnership . fetch_owner ( @ server , callers ( ) , @ key ) do
@@ -81,8 +102,13 @@ defmodule Sentry.Test do
81102 raise ArgumentError , "cannot collect Sentry reports: #{ Exception . message ( error ) } "
82103 end
83104
84- :error ->
105+ :error when dsn_set? ->
85106 :not_collecting
107+
108+ # If the :dsn option is not set and we didn't capture the event, it's alright,
109+ # we can just swallow it.
110+ :error ->
111+ :collected
86112 end
87113 else
88114 :not_collecting
0 commit comments