Skip to content

Add a non-logging way to initialise Sentry in generic host apps #5572

Description

@jamescrosswell

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeFeatureNew feature or requestNext MajorChanges scheduled for the next Major release.Waiting for: Product Owner

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions