Skip to content
Snippets Groups Projects
Verified Commit a470d136 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Hack knihovny pro Sentry a napojeni

parent 9273c60f
No related branches found
No related tags found
No related merge requests found
Pipeline #6916 passed
...@@ -20,6 +20,11 @@ sub startup { ...@@ -20,6 +20,11 @@ sub startup {
} }
} }
$self->plugin('SentrySDK', {
dsn => $cfg->{sentry_dsn},
traces_sample_rate => 1,
}) if $cfg->{sentry_dsn};
# migrace schematu # migrace schematu
my $pg = Mojo::Pg->new my $pg = Mojo::Pg->new
->dsn($cfg->{db_dsn}) ->dsn($cfg->{db_dsn})
......
package Mojolicious::Plugin::SentrySDK;
use Mojo::Base 'Mojolicious::Plugin', -signatures;
use Sentry::SDK;
use Try::Tiny;
sub register ($self, $app, $conf) {
$app->hook(
before_server_start => sub ($server, $app) {
Sentry::SDK->init($conf);
}
);
$app->hook(
around_action => sub ($next, $c, $action, $last) {
return $next->() unless $last;
my $req = $c->req;
Sentry::Hub->get_current_hub()->with_scope(sub ($scope) {
my %cookies = map { ($_->name, $_->value) } ($req->cookies // [])->@*;
my $transaction = Sentry::SDK->start_transaction(
{
name => $c->match->endpoint->pattern->unparsed || '/',
op => 'http.server',
request => {
url => $req->url->to_abs->to_string,
cookies => \%cookies,
method => $req->method,
query_string => $req->url->query->to_hash,
headers => $req->headers->to_hash,
env => \%ENV,
},
},
);
Sentry::SDK->configure_scope(sub ($scope) {
$scope->set_span($transaction);
});
try {
$next->();
} catch {
Sentry::SDK->capture_exception($_);
$c->reply->exception($_)
} finally {
my $status = $c->res->code;
$transaction->set_http_status($status) if $status;
$transaction->finish();
}
});
}
);
}
1;
=encoding utf8
=head1 NAME
Mojolicious::Plugin::SentrySDK - Sentry plugin for Mojolicious
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 OPTIONS
=head2 register
my $config = $plugin->register(Mojolicious->new);
my $config = $plugin->register(Mojolicious->new, \%options);
Register Sentry in L<Mojolicious> application.
=head1 SEE ALSO
L<Sentry::SDK>.
=cut
openapi: 3.0.3 openapi: 3.0.3
info: info:
version: "2.7.2" version: "2.8.0"
title: CF Online title: CF Online
description: CF Online description: CF Online
license: license:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment