bugsnag / bugsnag-laravel

BugSnag notifier for the Laravel PHP framework. Monitor and report Laravel errors.
https://docs.bugsnag.com/platforms/php/laravel/
MIT License
876 stars 129 forks source link

Not reporting failed job on Laravel vapor #427

Closed usrNotFound closed 1 year ago

usrNotFound commented 3 years ago

This only happens on a project running on laravel-vapor

Describe the bug

Laravel vapor project won't report an error on bugsnag for failed queued job.

Steps to reproduce

  1. configure logging

            "driver" => "stack",
            "channels" => ["bugsnag", "stderr"],
            "ignore_exceptions" => false,
        ],
    
        "bugsnag" => [
            "driver" => "bugsnag",
        ],
  2. Add BugsnagServiceProvider to app.php

  3. setQUEUE_CONNECTION to `'redis', 'sqs' anything other than 'sync'

  4. Create a job and implement ShouldQueue with throw new Exception

  5. Run project and dispatch the job.

Environment

mattdyoung commented 3 years ago

We don't yet provide support for using Bugsnag in AWS Lambda environments such as Laravel Vapor.

We suspect the issue is likely to be that the process is being terminated before the error report is delivered to Bugsnag, as the report is being sent asynchronously.

In general for serverless environments, setting the batch sending option to false may help as this will send the report when the error occurs: https://docs.bugsnag.com/platforms/php/laravel/configuration-options/#batch-sending

This may not resolve the issue you're seeing for queued jobs though.

We'll be sure to update this issue if we release full support in the future.

rihardsgrislis commented 3 years ago

@usrNotFound Laravel changes your default logging configuration to the stderr channel, which is captured and logged by AWS CloudWatch. You can follow this guide: https://flareapp.io/docs/ignition-for-laravel/installation#using-flare-on-vapor and change it for Bugsnag.

fideloper commented 3 years ago

Both issues are true I believe - you need to configure your logging.php correctly for Vapor, and also disable batch sending.

I have the following config/logging.php (some stuff omitted):

<?php

return [
    'default' => env('LOG_CHANNEL', 'stack-'.env('APP_ENV')),

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'bugsnag'],
            'ignore_exceptions' => false,
        ],

        'stack-production' => [
            'driver' => 'stack',
            'channels' => ['single', 'stderr', 'bugsnag'],
            'ignore_exceptions' => false,
        ],

        'stack-staging' => [
            'driver' => 'stack',
            'channels' => ['single', 'stderr', 'bugsnag'],
            'ignore_exceptions' => false,
        ],
    ],
];

Web requests appear to send errors to Bugsnag just fine, but queue jobs do not.

In the past, I've seen this happen when __destruct() calls are never fired in PHP. This happens when running tinker sessions, and apparently also with queue jobs with Vapor.

Setting batch settings to false can indeed help this:

BUGSNAG_BATCH_SENDING=false
GrahamCampbell commented 3 years ago

You probs don't wanna write to single on vapor. It'll just fill your tmp directory. If you write a lot, you'll start getting 502s from api gateway.

fideloper commented 3 years ago

I was wondering about that - I've been assuming each lambda and its tmp drive is killed between each request. I guess that's not the case?

GrahamCampbell commented 3 years ago

No. They keep it around. This is how warm starts are implemented. Each lambda is not gonna share the same tmp directory, but the filesystem from one that has shutdown already can get reused for another lambda about to boot. :)

gareththackeray commented 1 year ago

This is now fixed in v2.25.1. Please see our docs for more information. Any problems please let us know.

aligajani commented 6 months ago

@gareththackeray You just linked localhost

gareththackeray commented 6 months ago

@gareththackeray You just linked localhost

Oops thanks. Fixed