The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

register

hook_after_dispatch

hook_on_message

handle

capture_request

capture_message

stacktrace_context

$app->sentry->stacktrace_context($exception)

Build the stacktrace context from current exception. See also Sentry::Raven-stacktrace_context|https://metacpan.org/pod/Sentry::Raven#Sentry::Raven-%3Estacktrace_context(-$frames-)>

exception_context

$app->sentry->exception_context($exception)

Build the exception context from current exception. See also Sentry::Raven-exception_context|https://metacpan.org/pod/Sentry::Raven#Sentry::Raven-%3Eexception_context(-$value,-%25exception_context-)>

user_context

$app->sentry->user_context($controller)

Build the user context from current controller. See also Sentry::Raven-user_context|https://metacpan.org/pod/Sentry::Raven#Sentry::Raven-%3Euser_context(-%25user_context-)>

request_context

$app->sentry->request_context($controller)

Build the request context from current controller. See also Sentry::Raven-request_context|https://metacpan.org/pod/Sentry::Raven#Sentry::Raven-%3Erequest_context(-$url,-%25request_context-)>

tags_context

$app->sentry->tags_context($controller)

Add some tags to the context. See also Sentry::Raven-3Emerge_tags|https://metacpan.org/pod/Sentry::Raven#$raven-%3Emerge_tags(-%25tags-)>

ignore

$app->sentry->ignore($exception)

Check if the exception should be ignored.

on_error

$app->sentry->on_error($message, %context)

Handle reporting to Sentry error.

NAME

Mojolicious::Plugin::GetSentry - Sentry client for Mojolicious

VERSION

version 1.0

SYNOPSIS

    # Mojolicious with config
    #
    $self->plugin('sentry' => {
        # Required field
        sentry_dsn  => 'DSN',

        # Not required
        log_levels => ['error', 'fatal'],
        timeout     => 3,
        logger      => 'root',
        platform    => 'perl',

        # And if you want to use custom handles
        # this is how you do it
        stacktrace_context => sub {
            my ($sentry, $exception) = @_;

            my $stacktrace = Devel::StackTrace::Extract::extract_stack_trace($exception);

            $sentry->raven->add_context(
                $sentry->raven->stacktrace_context($sentry->raven->_get_frames_from_devel_stacktrace($stacktrace))
            );
        },

        exception_context => sub {
            my ($sentry, $exception) = @_;

            $sentry->raven->add_context(
                $sentry->raven->exception_context($exception->message, type => ref($exception))
            );
        },

        user_context => {
            my ($sentry, $controller) = @_;

            $sentry->raven->add_context(
                $sentry->raven->user_context(
                    id          => 1,
                    ip_address  => '10.10.10.1',
                )
            );
        },

        request_context => sub {
            my ($sentry, $controller) = @_;

            if (defined($controller->req)) {
                my $request_context = {
                    method  => $controller->req->method,
                    headers => $controller->req->headers->to_hash,
                };

                $sentry->raven->add_context(
                    $sentry->raven->request_context($controller->url_for->to_abs, %$request_context)
                );

                return $request_context;
            }

            return {};
        },

        tags_context => sub {
            my ($sentry, $controller) = @_;

            $sentry->raven->merge_tags(
                account => $controller->current_user->account_id,
            );
        },

        ignore => sub {
            my ($sentry, $exception) = @_;

            return 1 if ($expection->message =~ /Do not log this error/);
        },

        on_error => sub {
            my ($self, $message) = (shift, shift);

            die "failed to submit event to sentry service:\n" . dump($sentry->raven->_construct_message_event($message, @_));
        }
    });

    # Mojolicious::Lite
    #
    plugin 'sentry' => {
        # Required field
        sentry_dsn  => 'DSN',

        # Not required
        log_levels => ['error', 'fatal'],
        timeout     => 3,
        logger      => 'root',
        platform    => 'perl',

        # And if you want to use custom handles
        # this is how you do it
        stacktrace_context => sub {
            my ($sentry, $exception) = @_;

            my $stacktrace = Devel::StackTrace::Extract::extract_stack_trace($exception);

            $sentry->raven->add_context(
                $sentry->raven->stacktrace_context($sentry->raven->_get_frames_from_devel_stacktrace($stacktrace))
            );
        },

        exception_context => sub {
            my ($sentry, $exception) = @_;

            $sentry->raven->add_context(
                $sentry->raven->exception_context($exception->message, type => ref($exception))
            );
        },

        user_context => {
            my ($sentry, $controller) = @_;

            $sentry->raven->add_context(
                $sentry->raven->user_context(
                    id          => 1,
                    ip_address  => '10.10.10.1',
                )
            );
        },

        request_context => sub {
            my ($sentry, $controller) = @_;

            if (defined($controller->req)) {
                my $request_context = {
                    method  => $controller->req->method,
                    headers => $controller->req->headers->to_hash,
                };

                $sentry->raven->add_context(
                    $sentry->raven->request_context($controller->url_for->to_abs, %$request_context)
                );

                return $request_context;
            }

            return {};
        },

        tags_context => sub {
            my ($sentry, $controller) = @_;

            $sentry->raven->merge_tags(
                account => $controller->current_user->account_id,
            );
        },

        ignore => sub {
            my ($sentry, $exception) = @_;

            return 1 if ($expection->message =~ /Do not log this error/);
        },

        on_error {
            my ($sentry, $method) = (shift, shift);

            die "failed to submit event to sentry service:\n" . dump($sentry->raven->_construct_message_event($message, @_));
        }
    };

DESCRIPTION

Mojolicious::Plugin::GetSentry is a plugin for the Mojolicious web framework which allow you use Sentry https://getsentry.com. See also Sentry::Raven

ATTRIBUTES

Mojolicious::Plugin::GetSentry implements the following attributes.

sentry_dsn

    Sentry DSN url

timeout

    Timeout specified in seconds

log_levels

    Which log levels needs to be sent to Sentry
    e.g.: ['error', 'fatal']

processors

    A list of processors to filter down Sentry event
    See also L<Sentry::Raven->processors|https://metacpan.org/pod/Sentry::Raven#$raven-%3Eadd_processors(-%5B-Sentry::Raven::Processor::RemoveStackVariables,-...-%5D-)>

raven

    Sentry::Raven instance

    See also L<Sentry::Raven|https://metacpan.org/pod/Sentry::Raven>

METHODS

Mojolicious::Plugin::GetSentry inherits all methods from Mojolicious::Plugin and implements the following new ones.

SOURCE REPOSITORY

https://github.com/crlcu/Mojolicious-Plugin-GetSentry

AUTHOR

Adrian Crisan, <adrian.crisan88@gmail.com>

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-getsentry at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mojolicious-Plugin-GetSentry. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Mojolicious::Plugin::GetSentry

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2018 Adrian Crisan.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.