bugsnag-laravel icon indicating copy to clipboard operation
bugsnag-laravel copied to clipboard

Not reporting failed job on Laravel vapor

Open usrNotFound opened this issue 4 years ago • 6 comments

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",
        ],
  1. Add BugsnagServiceProvider to app.php
  2. setQUEUE_CONNECTION to `'redis', 'sqs' anything other than 'sync'
  3. Create a job and implement ShouldQueue with throw new Exception
  4. Run project and dispatch the job.

Environment

  • Bugsnag version: 2.21.0
  • PHP version: 7.4
  • Composer version: 2
  • Laravel version: 6.20
  • Lumen version (if any):

usrNotFound avatar Jan 04 '21 05:01 usrNotFound

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.

mattdyoung avatar Jan 06 '21 12:01 mattdyoung

@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.

rihardsgrislis avatar Apr 30 '21 14:04 rihardsgrislis

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

fideloper avatar Jun 18 '21 19:06 fideloper

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.

GrahamCampbell avatar Jun 18 '21 19:06 GrahamCampbell

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?

fideloper avatar Jun 18 '21 19:06 fideloper

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. :)

GrahamCampbell avatar Jun 18 '21 19:06 GrahamCampbell

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

gareththackeray avatar Jan 17 '23 13:01 gareththackeray