| 1 | package Sentry::SDK; | ||
| 2 | use Mojo::Base -base, -signatures; | ||
| 3 | |||
| 4 | use version 0.77; | ||
| 5 | use Mojo::Util 'dumper'; | ||
| 6 | use Sentry::Client; | ||
| 7 | use Sentry::Hub; | ||
| 8 | |||
| 9 | our $VERSION = version->declare('0.10.3'); | ||
| 10 | |||
| 11 | sub _call_on_hub ($method, @args) { | ||
| 12 | my $hub = Sentry::Hub->get_current_hub(); | ||
| 13 | |||
| 14 | if (my $cb = $hub->can($method)) { | ||
| 15 | return $cb->($hub, @args); | ||
| 16 | } | ||
| 17 | |||
| 18 | die | ||
| 19 | "No hub defined or $method was not found on the hub, please open a bug report."; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub _init_and_bind ($options) { | ||
| 23 | my $hub = Sentry::Hub->get_current_hub(); | ||
| 24 | my $client = Sentry::Client->new(_options => $options); | ||
| 25 | $hub->bind_client($client); | ||
| 26 | } | ||
| 27 | |||
| 28 | sub init ($package, $options = {}) { | ||
| 29 | $options->{default_integrations} //= []; | ||
| 30 | $options->{dsn} //= $ENV{SENTRY_DSN}; | ||
| 31 | $options->{traces_sample_rate} //= $ENV{SENTRY_TRACES_SAMPLE_RATE}; | ||
| 32 | $options->{release} //= $ENV{SENTRY_RELEASE}; | ||
| 33 | $options->{environment} //= $ENV{SENTRY_ENVIRONMENT}; | ||
| 34 | $options->{_metadata} //= {}; | ||
| 35 | $options->{_metadata}{sdk} | ||
| 36 | = { name => 'sentry.perl', packages => [], version => 'fixme' }; | ||
| 37 | |||
| 38 | _init_and_bind($options); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub capture_message ($self, $message, $capture_context = undef) { | ||
| 42 | my $level = ref($capture_context) ? undef : $capture_context; | ||
| 43 | |||
| 44 | _call_on_hub( | ||
| 45 | 'capture_message', | ||
| 46 | $message, $level, | ||
| 47 | { | ||
| 48 | originalException => $message, | ||
| 49 | capture_context => ref($capture_context) ? $capture_context : undef, | ||
| 50 | } | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | sub capture_event ($package, $event) { | ||
| 55 | _call_on_hub('capture_exception', $event); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub capture_exception ($package, $exception, $capture_context = undef) { | ||
| 59 | _call_on_hub('capture_exception', $exception, $capture_context); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub configure_scope ($package, $cb) { | ||
| 63 | Sentry::Hub->get_current_hub()->configure_scope($cb); | ||
| 64 | } | ||
| 65 | |||
| 66 | sub add_breadcrumb ($package, $crumb) { | ||
| 67 | Sentry::Hub->get_current_hub()->add_breadcrumb($crumb); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub start_transaction ($package, $context, $custom_sampling_context = undef) { | ||
| 71 | return _call_on_hub('start_transaction', $context, $custom_sampling_context); | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ | ||
| 77 | |||
| 78 | =encoding utf-8 | ||
| 79 | |||
| 80 | =head1 NAME | ||
| 81 | |||
| 82 | Sentry::SDK - sentry.io integration | ||
| 83 | |||
| 84 | =head1 SYNOPSIS | ||
| 85 | |||
| 86 | use Sentry::SDK; | ||
| 87 | |||
| 88 | =head1 DESCRIPTION | ||
| 89 | |||
| 90 | =head1 AUTHOR | ||
| 91 | |||
| 92 | Philipp Busse E<lt>pmb@heise.deE<gt> | ||
| 93 | |||
| 94 | =head1 COPYRIGHT | ||
| 95 | |||
| 96 | Copyright 2021- Philipp Busse | ||
| 97 | |||
| 98 | =head1 LICENSE | ||
| 99 | |||
| 100 | This library is free software; you can redistribute it and/or modify | ||
| 101 | it under the same terms as Perl itself. | ||
| 102 | |||
| 103 | =head1 SEE ALSO | ||
| 104 | |||
| 105 | =cut |