Open henzeb opened 3 days ago
I thought I give it ago and this is what works for me. There may be some issues conserning Oom, as I haven't fully tested that yet, but this seems promising:
class DeferredBugsnagProvider extends BugsnagServiceProvider implements DeferrableProvider
{
public function register(): void
{
$this->app->bind(
'request',
fn() => new class () {
public function server(): string
{
return config('app.servername');
}
}
);
parent::register();
}
public function provides(): array
{
return [
'request',
'bugsnag',
'bugsnag.tracker',
'bugsnag.logger',
'bugsnag.multi'
];
}
}
You probably wonder what request is doing there: request
usually resolves to Illuminate\Http\Request, but Laravel Zero doesn't know this class as it is a console application. Since bugsnag only needs the server method, I added in an anonymous class that has one method. It can return anything you want.
Deferring Bugsnag is not a good idea, because it needs to be loaded early in the bootstrapping process, to enable it to intercept crashes during framework boot.
Deferring Bugsnag is not a good idea, because it needs to be loaded early in the bootstrapping process, to enable it to intercept crashes during framework boot.
I agree, but Laravel Zero won't let us do that in the current implementation. the Log component is bound AFTER the providers that are configured by the user. Let's hope this is a temporary workaround.
Description
In theory, Bugsnag laravel should work with Laravel Zero. However, the register provider flow of laravel zero, currently prevents us from using bugsnag. That flow is as follows:
As a result, "Target class [log] does not exist. " error is thrown. You can't prepend the log service provider in the configuration file or anywhere else, as the component service provider simply overwrites the current binding. this doesn't give any errors when using Log facade, but doesn't log anything to bugsnag either.
Describe the solution you'd like two things can be done:
Describe alternatives you've considered I've posted a similar bug report at the Laravel Zero github. Maybe there a solution may come up. for instance, a way to prepend providers. Although they already have the solution, which is the deferred service provider.