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:
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<SentryLoggingOptions> 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<TOptions> 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.
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:There is no
UseSentry()outside ASP.NET Core. That path also gives these usersappsettings.jsonbinding for free, becauseAddSentryregistersIOptions<SentryLoggingOptions>and binds theSentryconfiguration section.Once #5245 lands,
builder.Logging.AddSentry()only wires up the logger provider. Generic-host users would be left callingSentrySdk.Initand 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 possiblyIHostBuilder), analogous toUseSentry()for ASP.NET Core:ServiceCollectionExtensions.AddSentry<TOptions>plumbing (the same path ASP.NET Core and MAUI use)Sentryconfiguration section, soappsettings.jsonkeeps workingbuilder.Logging.AddSentry()is not also neededsamples/Sentry.Samples.GenericHostis the case to design against.Open questions:
Sentry.Extensions.Loggingdoesn't currently referenceMicrosoft.Extensions.Hosting.Abstractions, so either it takes that dependency or this becomes a newSentry.Extensions.Hostingpackagebuilder.UseSentry()for consistency with ASP.NET Core and MAUI, orbuilder.Services.AddSentry()This should ship in the same release as #5245 so the removal never goes out without the replacement.