Sentry.Client (sentry v8.0.6) View Source
This module interfaces directly with Sentry via HTTP.
The client itself can be configured via the :client
configuration. It must implement the Sentry.HTTPClient
behaviour and it defaults to Sentry.HackneyClient
.
It makes use of Task.Supervisor
to allow sending tasks
synchronously or asynchronously, and defaulting to asynchronous.
See 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: {MyModule, :before_send},
before_send_event: {MyModule, :after_send}
where:
defmodule MyModule do
def before_send(event) do
metadata = Map.new(Logger.metadata)
%{event | extra: Map.merge(event.extra, metadata)}
end
def after_send_event(event, result) do
case result do
{:ok, id} ->
Logger.info("Successfully sent event!")
_ ->
Logger.info(fn -> "Did not successfully send event! #{inspect(event)}" end)
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 the configured HTTP client.
Attempts to send the event to the Sentry API up to 4 times with exponential backoff.
Link to this section Types
Specs
Specs
result() :: :sync | :none | :async
Specs
Link to this section Functions
Specs
Generates a Sentry API authorization header.
Specs
get_dsn() :: dsn() | {:error, :invalid_dsn}
Get a Sentry DSN which is simply a URI.
{PROTOCOL}://{PUBLIC_KEY}[:{SECRET_KEY}]@{HOST}/{PATH}{PROJECT_ID}
Specs
maybe_call_after_send_event(send_event_result(), Sentry.Event.t()) :: Sentry.Event.t()
Specs
maybe_call_before_send_event(Sentry.Event.t()) :: Sentry.Event.t() | false
Specs
render_event(Sentry.Event.t()) :: map()
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.
Specs
Makes the HTTP request to Sentry using the configured HTTP client.
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 should be awaited upon to receive the result asynchronously. If you do not callTask.await/2
, messages will be leaked to the inbox of the current process. SeeTask.Supervisor.async_nolink/2
for more information.:none
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.