sentry v8.0.0 Sentry.Client
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
dsn()
Specs
result()
Specs
result() :: :sync | :none | :async
send_event_result()
Specs
Link to this section Functions
authorization_header(public_key, secret_key)
Specs
Generates a Sentry API authorization header.
get_dsn()
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}
maybe_call_after_send_event(result, event)
Specs
maybe_call_after_send_event(send_event_result(), Sentry.Event.t()) :: Sentry.Event.t()
maybe_call_before_send_event(event)
Specs
maybe_call_before_send_event(Sentry.Event.t()) :: Sentry.Event.t() | false
maybe_log_result(result)
render_event(event)
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.
request(url, headers, body)
Specs
Makes the HTTP request to Sentry using the configured HTTP client.
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.:syncwill make the API call synchronously, and return{:ok, event_id}if successful.:nonesends the event from an unlinked child process underSentry.TaskSupervisorand will return{:ok, ""}regardless of the result.:asyncwill 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/2for more information.:noneis 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
:stacktraceor:extrawill be passed toSentry.Event.create_event/1downstream. SeeSentry.Event.create_event/1for available options.