NAME

Sentry::SDK - sentry.io integration

SYNOPSIS

use Sentry::SDK;

Sentry::SDK->init({
  dsn => "https://examplePublicKey@o0.ingest.sentry.io/0",

  # Adjust this value in production
  traces_sample_rate => 1.0,
});

DESCRIPTION

FUNCTIONS

init

Sentry::SDK->init(\%options);

Initializes the Sentry SDK in your app. The following options are provided:

dsn

The DSN tells the SDK where to send the events. If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.

release

Sets the release. Defaults to the SENTRY_RELEASE environment variable.

environment

Sets the environment. This string is freeform and not set by default. A release can be associated with more than one environment to separate them in the UI (think staging vs prod or similar).

By default the SDK will try to read this value from the SENTRY_ENVIRONMENT environment variable.

traces_sample_rate

A number between 0 and 1, controlling the percentage chance a given transaction will be sent to Sentry. (0 represents 0% while 1 represents 100%.) Applies equally to all transactions created in the app. This must be defined to enable tracing.

before_send

Sentry::SDK->init({
  before_send => sub ($event, $hint) {

    # discard event we don't care about
    if (ref($hint->{original_exception}) eq 'My::Ignorable::Exception') {
      return undef;
    }

    # add a custom tag otherwise
    $event->tags->{foo} = 'bar';

    return $event;
  };
});

beforeSend is called immediately before the event is sent to the server, so it’s the final place where you can edit its data. It receives the event object as a parameter, so you can use that to modify the event’s data or drop it completely (by returning undef) based on custom logic and the data available on the event.

integrations

Sentry::SDK->init({
  integrations => [My::Integration->new],
});

Enables your custom integration. Optional.

default_integrations

This can be used to disable integrations that are added by default. When set to a falsy value, no default integrations are added.

debug

Enables debug printing.

add_breadcrumb

Sentry::SDK->add_breadcrumb({
  category => "auth",
  message => "Authenticated user " . user->{email},
  level => Sentry::Severity->Info,
});

You can manually add breadcrumbs whenever something interesting happens. For example, you might manually record a breadcrumb if the user authenticates or another state change happens.

capture_exception

eval {
  $app->run();
};
if ($@) {
  Sentry::SDK->capture_exception($@);
}

You can pass an error object to capture_exception() to get it captured as event. It's possible to throw strings as errors.

capture_message

Sentry::SDK->capture_message("Something went wrong");

Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. Typically messages are not emitted, but they can be useful for some teams.

capture_event

Sentry::SDK->capture_event(\%data);

Captures a manually created event and sends it to Sentry.

configure_scope

Sentry::SDK->configure_scope(sub ($scope) {
  $scope->set_tag(foo => "bar");
  $scope->set_user({id => 1, email => "john.doe@example.com"});
});

When an event is captured and sent to Sentry, event data with extra information will be merged from the current scope. The configure_scope function can be used to reconfigure the current scope. This for instance can be used to add custom tags or to inform sentry about the currently authenticated user. See Sentry::Hub::Scope for further information.

start_transaction

my $transaction = Sentry::SDK->start_transaction({
  name => 'MyScript',
  op => 'http.server',
});

Sentry::SDK->configure_scope(sub ($scope) {
  $scope->set_span($transaction);
});

# ...

$transaction->set_http_status(200);
$transaction->finish();

Is needed for recording tracing information. Transactions are usually handled by the respective framework integration. See Sentry::Tracing::Transaction.

AUTHOR

Philipp Busse <pmb@heise.de>

COPYRIGHT

Copyright 2021- Philipp Busse

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO