Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core - be able to use Bugsnag in singleton services and static contexts #130

Open
LoremFooBar opened this issue Oct 17, 2020 · 4 comments
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature

Comments

@LoremFooBar
Copy link

LoremFooBar commented Oct 17, 2020

Description

I would like to add Bugsnag to a reverse proxy project (.NET Core 3.1). Since this is not a classic MVC/WebAPI project, there are no controllers, and most of the code runs in a static context. The Bugsnag.AspNet.Core package adds the Bugsnag client as scoped service, which makes it difficult to use in static contexts (from singleton services for example).

Describe the solution you'd like

Be able to register Bugsnag client as singleton service and use IHttpContextAccessor to access request information where needed.

Describe alternatives you've considered

  1. Manually setup Bugsnag without the Bugsnag.AspNet.Core package - not great for me because I would like Bugsnag integration to be as easy as possible in all of our projects.
  2. Create and publish my own package - this will probably be my temporary solution, eventually I would be happy to contribute my work back to this project.

Update - I created a package where the only change is adding Bugsnag.IClient as a singleton instead of a scoped service, and looks like everything just works.

@johnkiely1
Copy link
Member

Hi @Lazyboy1 ,

Thanks for raising this. we will look into this when we can.
For now, it sounds like you have it working as you need it to, so by all means stick with that approach.

@johnkiely1 johnkiely1 added the needs discussion Requires internal analysis/discussion label Oct 20, 2020
@maciej-januchowski
Copy link

Another similar use case would be using Bugsnag inside service registered as IHostedService. Since IHostedService is registered as singleton it is also not possible to use scoped Bugsnag inside of it.

@aycron-dev
Copy link

Is there any way to Identify the Users Automatically, on one piece of code using:

_bugsnag.BeforeNotify(report =>
{
report.Event.User = new Bugsnag.Payload.User
{
Id = "45556",
Name = "Bob Smith",
Email = "[email protected]"
};
});

I think that the only way is to make the service Singleton

@yousif-bugsnag
Copy link
Contributor

Hi @aycron-dev, You're correct, there isn't a way to do that currently since the Bugsnag client is scoped to the lifetime of a single request. We're going to look into adding support for registering Bugsnag as a singleton when priorities allow.

@yousif-bugsnag yousif-bugsnag added backlog We hope to fix this feature/bug in the future feature request Request for a new feature and removed needs discussion Requires internal analysis/discussion labels Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

5 participants