sentry v7.2.4 Sentry.Client
This module is the default client for sending an event to Sentry via HTTP.
It makes use of Task.Supervisor
to allow sending tasks synchronously or asynchronously, and defaulting to asynchronous. See Sentry.Client.send_event/2
for more information.
Configuration
:before_send_event
- allows performing operations on the event before it is sent. Accepts an anonymous function or a {module, function} tuple, and the event will be passed as the only argument.:after_send_event
- callback that is called after attempting to send an event. Accepts an anonymous function or a {module, function} tuple. The result of the HTTP call as well as the event will be passed as arguments. The return value of the callback is not returned.
Example configuration of putting Logger metadata in the extra context:
config :sentry,
before_send_event: fn(event) ->
metadata = Map.new(Logger.metadata)
%{event | extra: Map.merge(event.extra, metadata)}
end,
after_send_event: fn(event, result) ->
case result do
{:ok, id} ->
Logger.info("Successfully sent event!")
_ ->
Logger.info(fn -> "Did not successfully send event! #{inspect(event)}" end)
end
end
Link to this section Summary
Functions
Generates a Sentry API authorization header.
Get a Sentry DSN which is simply a URI.
Transform the Event struct into JSON map.
Makes the HTTP request to Sentry using hackney.
Attempts to send the event to the Sentry API up to 4 times with exponential backoff.
Link to this section Types
Link to this section Functions
authorization_header(public_key, secret_key)
Generates a Sentry API authorization header.
Get a Sentry DSN which is simply a URI.
{PROTOCOL}://{PUBLIC_KEY}[:{SECRET_KEY}]@{HOST}/{PATH}{PROJECT_ID}
hackney_pool_name()
maybe_call_after_send_event(result, event)
maybe_call_after_send_event(send_event_result(), Sentry.Event.t()) :: Sentry.Event.t()
maybe_call_before_send_event(event)
maybe_call_before_send_event(Sentry.Event.t()) :: Sentry.Event.t() | false
maybe_log_result(result)
Transform the Event struct into JSON map.
Most Event attributes map directly to JSON map, with stacktrace being the exception. If the event does not have stacktrace frames, it should not be included in the JSON body.
request(url, headers, body)
Makes the HTTP request to Sentry using hackney.
Hackney options can be set via the hackney_opts
configuration option.
send_event(event, opts \\ [])
Attempts to send the event to the Sentry API up to 4 times with exponential backoff.
The event is dropped if it all retries fail. Errors will be logged unless the source is the Sentry.LoggerBackend, which can deadlock by logging within a logger.
Options
:result
- Allows specifying how the result should be returned. Options include:sync
,:none
, and:async
.:sync
will make the API call synchronously, and return{:ok, event_id}
if successful.:none
sends the event from an unlinked child process underSentry.TaskSupervisor
and will return{:ok, ""}
regardless of the result.:async
will start an unlinked task and return a tuple of{:ok, Task.t}
on success where the Task can be awaited upon to receive the result asynchronously. When used in an OTP behaviour like GenServer, the task will send a message that needs to be matched withGenServer.handle_info/2
. SeeTask.Supervisor.async_nolink/2
for more information.:async
is the default.:sample_rate
- The sampling factor to apply to events. A value of 0.0 will deny sending any events, and a value of 1.0 will send 100% of events.- Other options, such as
:stacktrace
or:extra
will be passed toSentry.Event.create_event/1
downstream. SeeSentry.Event.create_event/1
for available options.