Version 7 of the Sentry SDK for .NET adds support for .NET 11 and gives Sentry a single place to be initialized. It contains breaking changes, so read the upgrade notes below before you upgrade.
This is a release candidate, built against .NET 11 RC 2.
Highlights
- .NET 11. The SDK targets
net11.0alongside .NET 8, 9 and 10, including Android, iOS and Mac Catalyst apps on .NET 11, with support for its new Android assembly store format and Zstandard-compressed assemblies. - One place to initialize Sentry. The
Microsoft.Extensions.Logging, Serilog, NLog and log4net integrations now only capture logs, breadcrumbs and events; they no longer start the SDK. Initialize Sentry withSentrySdk.InitorUseSentry, and configure it from theSentrysection ofappsettings.json. UseSentryfor generic host apps. The newSentry.Extensions.Hostingpackage addsUseSentrytoHost.CreateApplicationBuilderandIHostBuilder, for worker services, console apps, Azure Functions (isolated) and Windows services. ASP.NET Core apps can callbuilder.UseSentry(...)onWebApplicationBuilderand keep chaining.- Cron monitors from code.
SentrySdk.WithMonitorandSentrySdk.WithMonitorAsyncrun a job, send its check-ins, and can create the monitor along with its schedule. Hangfire recurring jobs marked with[SentryMonitorSlug]send their cron schedule automatically. - Less noise in tracing. Requests that end in 301, 305–399 or 401–404 are no longer traced by default.
- The right environment everywhere. ASP.NET Core, generic host apps, Blazor WebAssembly and Google Cloud Functions take the Sentry environment from the host environment, and logs, metrics, sessions and check-ins use an environment set on the scope.
Upgrading from 6.x
Target frameworks
- Mobile targets require .NET 10 or later:
net9.0-android,net9.0-ios,net9.0-maccatalystandnet9.0-windowsare no longer supported. - On .NET 11, the minimum Android API level is 24 (Android 7.0) and the minimum Mac Catalyst version is 17.0.
- Other targets are unchanged: .NET 8 and later, .NET Standard 2.0 and 2.1, and .NET Framework 4.6.2.
Initializing Sentry
- Serilog's
WriteTo.Sentry(...), NLog's Sentry target, log4net'sSentryAppenderandLogging.AddSentry(...)no longer initialize the SDK. Initialize Sentry first withSentrySdk.Init, orUseSentryin ASP.NET Core, MAUI, Blazor WebAssembly and generic host apps, and moveDsn,Release,Environmentand other SDK settings there. A DSN still set on one of these integrations fails with a message explaining what to change (to prevent SDK users being blind-sided by this change). Logging:Sentryinappsettings.jsonnow only sets log levels:MinimumEventLevel,MinimumBreadcrumbLeveland theLogLevelrules. Move any other key to theSentrysection; the app fails at startup until you do.SentryLoggingOptions,SentrySerilogOptionsandSentryNLogOptionsno longer derive fromSentryOptions. Serilog'sApplySerilogScopeToEvents()is renamedUseSerilog().- NLog flushes Sentry using
SentryOptions.FlushTimeout, which defaults to 2 seconds. The NLog target used to wait up to 15. Logging.AddSentry()no longer registersIHub,ISentryClientorFunc<IHub>in the service collection;UseSentrydoes. An app that initializes Sentry withSentrySdk.Initand injects them now fails when they're resolved. Switch toUseSentry, or registerHubAdapter.Instancefor each type yourself.- In an app that calls both
UseSentryandLogging.AddSentry(), theLogging.AddSentry()call now does nothing. Move its settings to the host's options, such asSentryAspNetCoreOptions, and remove the call. - In MAUI, options set in the
UseSentrycallback now overrideappsettings.json, as they do in ASP.NET Core.
Removed and changed APIs
SentryOptions.EnableLogsis removed. WithSentrySdk.Initand the logging integrations, logs are always sent; drop them withSetBeforeSendLog(_ => null). ASP.NET Core, MAUI and Blazor WebAssembly keep the opt-in: setEnableLogson their options or in theSentrysection, as in 6.x.SentryOptions.EnableMetricsis removed. ReturnnullfromSetBeforeSendMetricto drop metrics.Scope.Release,Scope.DistributionandSentryOptions.ApplyDefaultTagsare removed. SetReleaseandDistributiononSentryOptions.DefaultTagsare still applied.SentryOptions.ScopeObserver,EnableScopeSyncandCrashedLastRunare now internal.- On iOS and Mac Catalyst,
SentryOptions.Native.EnableAppHangTrackingV2is removed; useEnableAppHangTracking.SentryOptions.Native.AddInAppExclude(string), which had no effect, is removed too. Envelope.FromEvent,Envelope.FromFeedbackandEnvelope.FromTransactiontake theIDiagnosticLoggeras their last parameter.- The OTLP exporter no longer sets a global OpenTelemetry propagator, and its
defaultTextMapPropagatorparameter is removed. The propagator should be configured via the OpenTelemetry SDK instead.Sentry.OpenTelemetryandSentry.OpenTelemetry.Exporternow require OpenTelemetry 1.12.0 or later.
Changes in behavior
- Requests that end in 301, 305–399 or 401–404 are no longer traced. To trace them again, call
options.TraceIgnoreStatusCodes.Clear(). - Apps that use the
ISentryBuilderoverloads ofUseSentry(including gRPC apps), Blazor WebAssembly or Google Cloud Functions, and don't set an environment, now report the host environment, such asdevelopmentorstaging, instead ofproduction. Update alerts and filters that rely on the old value. - Events, transactions, logs and metrics report the SDK name of the integration that initialized Sentry, such as
sentry.dotnet.aspnetcore, rather than the logging integration that captured them. - On Android and iOS,
SENTRY_RELEASEtakes precedence over the release derived from the app package. - Hangfire recurring jobs marked with
[SentryMonitorSlug]send their schedule and time zone, which updates existing monitors on the next run. To keep managing schedules in Sentry, opt out withUseSentry(o => o.SendMonitorConfig = false).
Breaking Changes 🛠
builder.Logging.AddSentry()no longer registersIHub,ISentryClientorFunc<IHub>in the service collection.UseSentryregisters them; apps that initialize Sentry withSentrySdk.Initand inject them now register them themselves by @jamescrosswell in #5740- fix(maui)!: options set in UseSentry now take precedence over appsettings.json by @jamescrosswell in #5658
- The
Microsoft.Extensions.Loggingintegration no longer initializes the SDK. Sentry must now be initialized separately from the logging integration (usingSentrySdk.InitorUseSentry) by @jamescrosswell in #5595 - Sentry's logging configuration section (
Logging:Sentry) now only configures the logging integration. Core SDK settings there, such asDsn, no longer have any effect and fail at startup with migration guidance: move them to theSentrysection, or pass them where Sentry is initialized by @jamescrosswell in #5595 - Blazor WebAssembly's logger now respects the
MinimumEventLevel,MinimumBreadcrumbLevel, log entry filters andConfigureScopecallbacks set inUseSentryby @jamescrosswell in #5595 - feat(log4net)!: the Sentry appender no longer initializes the SDK by @jamescrosswell in #5592
- feat(nlog)!: the Sentry target no longer initializes the SDK by @jamescrosswell in #5585
- feat(serilog)!: the Sentry sink no longer initializes the SDK by @jamescrosswell in #5573
- feat!: set the Sentry environment from the host environment in every ASP.NET Core UseSentry overload, Blazor WebAssembly and Google Cloud Functions by @jamescrosswell in #5703
- fix!: apps that call both UseSentry and Logging.AddSentry() no longer capture each error, breadcrumb and log twice by @jamescrosswell in #5694
- feat!: remove SentryOptions.EnableMetrics by @ric-oliv in #5690
- feat!: EnableLogs moves from SentryOptions to ASP.NET Core, MAUI and Blazor, where logs are opt-in by @ric-oliv in #5642
Scope.ReleaseandScope.Distributionhave been removed, andReleaseandDistributionhave moved fromIEventLiketoITransactionData. Set them onSentryOptionsinstead. by @jamescrosswell in #5671SentryOptions.ApplyDefaultTagshas been removed. Default tags set inSentryOptions.DefaultTagsare still applied to events and transactions. by @jamescrosswell in #5671- Logs, metrics, sessions, check-ins and trace propagation now use an environment set on the scope, as events already did. Setting
Scope.Environmenttonullclears the override. by @jamescrosswell in #5671 - Events, transactions, logs and metrics all report the SDK name of the integration that initialized Sentry, such as
sentry.dotnet.aspnetcore. Blazor WebAssembly now reportssentry.dotnet.aspnetcore.blazor.webassembly. by @jamescrosswell in #5671 - On Android and iOS,
SENTRY_RELEASEnow takes precedence over the default release derived from the app package. by @jamescrosswell in #5671 Envelope.FromEvent,Envelope.FromFeedbackandEnvelope.FromTransactionnow take theIDiagnosticLoggeras their last parameter, afterattachments(andsessionUpdate). This only affects code that creates envelopes directly and passes these arguments positionally; those calls no longer compile, so reorder the arguments or pass them by name. by @jamescrosswell in #5669// Before Envelope.FromEvent(@event, logger, attachments, sessionUpdate); Envelope.FromTransaction(transaction, logger, attachments); // After Envelope.FromEvent(@event, attachments, sessionUpdate, logger); Envelope.FromTransaction(transaction, attachments, logger);
- Removed
SentryOptions.Native.EnableAppHangTrackingV2on iOS and Mac Catalyst (useEnableAppHangTrackinginstead) by @jamescrosswell in #5654 - Removed
SentryOptions.Native.AddInAppExclude(string)on iOS, which had no effect by @jamescrosswell in #5654 - feat!: don't trace 301, 305-399 or 401-404 responses by default by @jamescrosswell in #5632
- feat!:
SentryOptions.ScopeObserver,EnableScopeSyncandCrashedLastRunare now internal by @jamescrosswell in #5631 - feat!: stop deserializing "critical" breadcrumb level by @jamescrosswell in #5630
Features ✨
- Hangfire recurring jobs marked with
[SentryMonitorSlug]now send their cron schedule and time zone with the check-in, so Sentry creates the monitor if it doesn't exist yet. This is on by default: on upgrade, existing monitors take their schedule and time zone from the recurring job on its next run (other monitor settings are kept). To keep managing schedules in Sentry, opt out withUseSentry(o => o.SendMonitorConfig = false). by @wedamija in #5665 - feat(aspnetcore): add UseSentry overloads on WebApplicationBuilder by @ric-oliv in #5720
- feat(otel): raise the OpenTelemetry floor to 1.12.0 by @jamescrosswell in #5560
- feat: add support for .NET 11 RC 2 by @jamescrosswell in #5725
- feat: add Sentry.Extensions.Hosting with UseSentry for generic host apps by @ric-oliv in #5739
- feat: add SentrySdk.WithMonitor to run a job with cron check-ins and create the monitor from code by @wedamija in #5664
- feat: Support reading .NET 11 Android assembly stores by @jamescrosswell in #5577
- feat: Support Zstandard-compressed assemblies on Android (.NET 11) by @jamescrosswell in #5575
- feat: add support for .NET 11 RC 1 by @jamescrosswell in #5566
- feat: Accept Android assembly store v4 versions by @jamescrosswell in #5574
- feat: Logs are always enabled and
SentryOptions.EnableLogsis ignored by @jamescrosswell in #5504 - Support for .NET 11 by @jamescrosswell in #5529
- Mobile targets now require .NET 10 or later -
net9.0-android,net9.0-ios,net9.0-maccatalystandnet9.0-windowshave been dropped. by @jamescrosswell in #5529 - On .NET 11 the minimum Android API level is now 24 (Android 7.0) and the minimum MacCatalyst version is 17.0. by @jamescrosswell in #5529
- Non-mobile targets continue to support .NET 8 and later. by @jamescrosswell in #5529
Fixes 🐛
- fix(maui): report in_foreground for apps using the UIScene lifecycle by @jamescrosswell in #5730
- fix(aspnetcore): start the SDK when the host starts, not on the first request by @ric-oliv in #5721
- fix(otlp): don't configure an automatic OTel propagator by @jamescrosswell in #5319
- fix: upload symbols and create releases when publishing Native AOT with the .NET 11 SDK by @jamescrosswell in #5731
- fix: don't upload pre-trim PDBs for trimmed iOS and Mac Catalyst builds by @jamescrosswell in #5732
- fix: avoid first-chance exception when getting length of non-seekable attachment streams by @bitsandfoxes in #5736