View Source Sentry.Event (Sentry v9.1.0)
Provides functions to create Sentry events from scratch, from exceptions, and so on.
This module also contains the main event struct. Events are the fundamental data that clients send to the Sentry server.
Link to this section Summary
Functions
The struct representing the event.
Creates an event struct out of collected context and options.
Transforms an exception to a Sentry event.
Link to this section Types
@type level() :: :fatal | :error | :warning | :info | :debug
The level of an event.
@type t() :: %Sentry.Event{ breadcrumbs: [Sentry.Interfaces.Breadcrumb.t()], contexts: Sentry.Interfaces.context(), culprit: term(), dist: String.t() | nil, environment: String.t() | nil, event_id: <<_::256>>, exception: [Sentry.Interfaces.Exception.t()], extra: map(), fingerprint: [String.t()], level: level() | nil, logger: String.t() | nil, message: String.t() | nil, modules: %{optional(String.t()) => String.t()}, original_exception: Exception.t() | nil, platform: :elixir, release: String.t() | nil, request: Sentry.Interfaces.Request.t() | nil, sdk: Sentry.Interfaces.SDK.t() | nil, server_name: String.t() | nil, source: atom(), tags: %{optional(String.t()) => String.t()}, timestamp: String.t() | number(), transaction: String.t() | nil, user: Sentry.Interfaces.user() | nil }
The type for the event struct.
All of the fields in this struct map directly to the fields described in the Sentry documentation. These fields are the exceptions, and are specific to the Elixir Sentry SDK:
:source- the source of the event.Sentry.LoggerBackendandSentry.LoggerHandlerset this to:logger, whileSentry.PlugCaptureandSentry.PlugContextset it to:plug. You can set it to any atom. See the:event_sourceoption increate_event/1andtransform_exception/2.:original_exception- the original exception that is being reported, if there's one. The Elixir Sentry SDK manipulates reported exceptions to make them fit the payload required by the Sentry API, and these end up in the:exceptionfield. The:original_exceptionfield, instead, contains the original exception as the raw Elixir term (such as%RuntimeError{...}).
See also %Sentry.Event{}.
Link to this section Functions
The struct representing the event.
You're not advised to manipulate this struct's fields directly. Instead,
use functions such as create_event/1 or transform_exception/2 for creating
events.
See the t/0 type for information on the fields and their types.
@spec create_event([option]) :: t() when option: {:user, Sentry.Interfaces.user()} | {:request, map()} | {:extra, Sentry.Context.extra()} | {:breadcrumbs, Sentry.Context.breadcrumb()} | {:tags, Sentry.Context.tags()} | {:level, level()} | {:fingerprint, [String.t()]} | {:message, String.t()} | {:event_source, atom()} | {:exception, Exception.t()} | {:stacktrace, Exception.stacktrace()}
Creates an event struct out of collected context and options.
Merging Options with Context and Config
Some of the options documented below are merged with the Sentry context, or with the Sentry context and the configuration. The option you pass here always has higher precedence, followed by the context and finally by the configuration.
See also
Sentry.Contextfor information on the Sentry context andSentryfor information on configuration.
options
Options
:exception- anException.t/0. This is the exception that gets reported in the:exceptionfield oft/0. The term passed here also ends up unchanged in the:original_exceptionfield oft/0. This option is required unless the:messageoption is present. This is not present by default.:stacktrace- a stacktrace, as inException.stacktrace/0. This is not present by default.:message- a message (String.t/0). This is not present by default.:extra- map of extra context, which gets merged with the current context (seeSentry.Context.set_extra_context/1). If fields collide, the ones in the map passed through this option have precedence over the ones in the context. Defaults to%{}.:user- map of user context, which gets merged with the current context (seeSentry.Context.set_user_context/1). If fields collide, the ones in the map passed through this option have precedence over the ones in the context. Defaults to%{}.:tags- map of tags context, which gets merged with the current context (seeSentry.Context.set_tags_context/1) and with the:tagsoption in the global Sentry configuration. If fields collide, the ones in the map passed through this option have precedence over the ones in the context, which have precedence over the ones in the configuration. Defaults to%{}.:request- map of request context, which gets merged with the current context (seeSentry.Context.set_request_context/1). If fields collide, the ones in the map passed through this option have precedence over the ones in the context. Defaults to%{}.:breadcrumbs- list of breadcrumbs. This list gets prepended to the list in the context (seeSentry.Context.add_breadcrumb/1). Defaults to[].:level- error level (seet/0). Defaults to:error.:fingerprint- list of the fingerprint for grouping this event (a list ofString.t/0). Defaults to["{{ default }}"].:event_source- the source of the event. This fills in the:sourcefield of the returned struct. This is not present by default.
examples
Examples
iex> event = create_event(exception: %RuntimeError{message: "oops"}, level: :warning)
iex> event.level
:warning
iex> hd(event.exception).type
"RuntimeError"
iex> event.original_exception
%RuntimeError{message: "oops"}
iex> event = create_event(message: "Unknown route", event_source: :plug)
iex> event.source
:plug
@spec transform_exception( Exception.t(), keyword() ) :: t()
Transforms an exception to a Sentry event.
This essentially defers to create_event/1, inferring some options from
the given exception.
options
Options
This function takes the same options as create_event/1.