getsentry / getsentry/sentry-dotnet
Add a non-logging way to initialise Sentry in generic host apps
- Dominant language
- C#
- Stars
- 770
- Forks
- 248
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 49
Description
### Description
Companion to #5245, which removes the ability to initialise the SDK from the logging integrations in v7.
In a generic-host app (`Host.CreateApplicationBuilder()`, worker services, etc.) the only way to initialise Sentry today is through the Microsoft.Extensions.Logging integration:
```csharp
var builder = Host.CreateApplicationBuilder();
builder.Logging.AddSentry(dsn); // initialises the SDK
```
There is no `UseSentry()` outside ASP.NET Core. That path also gives these users `appsettings.json` binding for free, because `AddSentry` registers `IOptions` and binds the `Sentry` configuration section.
Once #5245 lands, `builder.Logging.AddSentry()` only wires up the logger provider. Generic-host users would be left calling `SentrySdk.Init` and binding configuration into it by hand — a capability removed without a replacement.
### Proposal
Add a host-level, non-logging way to initialise Sentry for generic-host apps, e.g. an extension on `IHostApplicationBuilder` (and possibly `IHostBuilder`), analogous to `UseSentry()` for ASP.NET Core:
- initialises the SDK through the existing `ServiceCollectionExtensions.AddSentry` plumbing (the same path ASP.NET Core and MAUI use)
- binds the `Sentry` configuration section, so `appsettings.json` keeps working
- registers the logger provider, so that `builder.Logging.AddSentry()` is not also needed
`samples/Sentry.Samples.GenericHost` is the case to design against.
Open questions:
- which package it lives in — `Sentry.Extensions.Logging` doesn't currently reference `Microsoft.Extensions.Hosting.Abstractions`, so either it takes that dependency or this becomes a new `Sentry.Extensions.Hosting` package
- naming: `builder.UseSentry()` for consistency with ASP.NET Core and MAUI, or `builder.Services.AddSentry()`
This should ship in the same release as #5245 so the removal never goes out without the replacement.
Contributor guide
Research direction
Start with samples/Sentry.Samples.GenericHost and the existing ServiceCollectionExtensions.AddSentry plumbing, then compare the ASP.NET Core and MAUI initialization paths. Review #5245 and the package dependency options before settling the host API and package location. Done means generic-host apps can initialize Sentry, bind the Sentry configuration section, and register the logger provider without manually calling SentrySdk.Init or AddSentry().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100