Repository navigation
docs(dotnet): Add a Generic Host guide for SDK 7.0.0 - #20311
jamescrosswell wants to merge 1 commit into
Conversation
Documents Sentry.Extensions.Hosting, which sentry-dotnet 7.0.0 adds: UseSentry on IHostApplicationBuilder and IHostBuilder, configuration, environment, startup and shutdown, ClearProviders(), web and MAUI apps, Aspire service defaults, the .NET Framework gap and replacing SentrySdk.Init. Adds a config intro for the guide's options page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
The new Generic Host guide (#20311) starts Sentry with UseSentry, so its logs usage page should show the ILogger section like the other host integrations, and its requirements start at 7.0.0. Also say that generic host apps set EnableLogs to send ILogger entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
||
| On .NET Framework, `UseSentry` is only available on `IHostBuilder`. The package supports Microsoft.Extensions.Hosting 3.1 and later there, and `IHostApplicationBuilder` only exists from 8.0. An app that uses `Host.CreateApplicationBuilder()` can switch to `Host.CreateDefaultBuilder()`, as in the `IHostBuilder` example [above](#configure). | ||
|
|
||
| The app can also keep `Host.CreateApplicationBuilder()`, initialize Sentry with `SentrySdk.Init`, and add the logging integration with `builder.Logging.AddSentry()`. It then doesn't read the `Sentry` section, and Sentry doesn't start and close with the host. `Logging.AddSentry()` doesn't register `IHub`, `ISentryClient`, or `Func<IHub>`, so register them if your services inject them: |
There was a problem hiding this comment.
Readers coming from Send Logs will look for EnableLogs here, and the IHub error is what people search for when they miss the registrations. What do you think about naming both?
| The app can also keep `Host.CreateApplicationBuilder()`, initialize Sentry with `SentrySdk.Init`, and add the logging integration with `builder.Logging.AddSentry()`. It then doesn't read the `Sentry` section, and Sentry doesn't start and close with the host. `Logging.AddSentry()` doesn't register `IHub`, `ISentryClient`, or `Func<IHub>`, so register them if your services inject them: | |
| The app can also keep `Host.CreateApplicationBuilder()`, initialize Sentry with `SentrySdk.Init`, and add the logging integration with `builder.Logging.AddSentry()`. It then doesn't read the `Sentry` section, and Sentry doesn't start and close with the host. It also sends `ILogger` entries as logs, and `EnableLogs` can't turn that off, because it only exists on the `UseSentry` options. `Logging.AddSentry()` doesn't register `IHub`, `ISentryClient`, or `Func<IHub>`. If your services inject them, register them, or the host fails to start with `Unable to resolve service for type 'Sentry.IHub'`: |
There was a problem hiding this comment.
Logging.AddSentry()doesn't registerIHub,ISentryClient, orFunc<IHub>. If your services inject them, register them, or the host fails to start withUnable to resolve service for type 'Sentry.IHub':
That's a bit confusing to me. I think it should probably be in it's own section and we should just tell people what to do in order to get it right... it starts getting confusing when we describe all the things that could go wrong and what happens in those situations.
Depends if we're writing this for humans or LLMs though. LLMs are fine with a long list of seemingly unrelated statements. The docs here are generally to help people get up and running quickly though - LLMs can just read the source code to debug issues.
|
|
||
| ### Replacing SentrySdk.Init | ||
|
|
||
| If your app calls `SentrySdk.Init`, remove that call when you add `UseSentry`, and move its options into the `UseSentry` callback or the `Sentry` section. Whichever initialization runs last wins, and the two don't merge their options. |
There was a problem hiding this comment.
Apps that call SentrySdk.Init with Logging.AddSentry(), like the fallback above, stop sending logs after the switch until they set EnableLogs. Maybe worth a sentence here:
| If your app calls `SentrySdk.Init`, remove that call when you add `UseSentry`, and move its options into the `UseSentry` callback or the `Sentry` section. Whichever initialization runs last wins, and the two don't merge their options. | |
| If your app calls `SentrySdk.Init`, remove that call when you add `UseSentry`, and move its options into the `UseSentry` callback or the `Sentry` section. Whichever initialization runs last wins, and the two don't merge their options. If it also calls `Logging.AddSentry()`, remove that call too. That setup sends `ILogger` entries as logs without any option, while `UseSentry` needs `EnableLogs` set to `true`. |
There was a problem hiding this comment.
If it also calls
Logging.AddSentry(), remove that call too. That setup sendsILoggerentries as logs without any option, whileUseSentryneedsEnableLogsset totrue.
Again, this starts to confuse me... reading the whole paragraph I come away not knowing what it was trying to tell me - possibly it's trying to communicate 3 different things, none of which I feel like I can digest without source code samples.... like:
## Correct
Do this...
## False
Don't do this or this will happen
## False
Don't do this or that will happen
I think that kind of prose is appropriate in github issues where we're trying to get to the bottom issues but we should try to keep the docs here as clear and concise as possible. It it's hard to read, that maybe indicates we've stuffed up the API design.
| } | ||
| ``` | ||
|
|
||
| `EnableLogs` doesn't change how errors and breadcrumbs are captured. Entries at `Error` and above are sent as events, and entries at `Information` and above are kept as breadcrumbs. To change that, set `MinimumEventLevel` and `MinimumBreadcrumbLevel`. |
There was a problem hiding this comment.
AddLogEntryFilter works on the UseSentry options too. If #19961 drops its Generic Host content, this page is the only place left that shows it. Maybe something like:
| `EnableLogs` doesn't change how errors and breadcrumbs are captured. Entries at `Error` and above are sent as events, and entries at `Information` and above are kept as breadcrumbs. To change that, set `MinimumEventLevel` and `MinimumBreadcrumbLevel`. | |
| `EnableLogs` doesn't change how errors and breadcrumbs are captured. Entries at `Error` and above are sent as events, and entries at `Information` and above are kept as breadcrumbs. To change that, set `MinimumEventLevel` and `MinimumBreadcrumbLevel`. | |
| To drop specific entries before they become breadcrumbs or events, add a filter with `AddLogEntryFilter`. Return `true` to drop the entry: | |
| ```csharp {filename:Program.cs} | |
| using Sentry.Extensions.Logging; | |
| builder.UseSentry(options => | |
| { | |
| options.AddLogEntryFilter((category, level, eventId, exception) => | |
| exception is OperationCanceledException); | |
| }); | |
| ``` |
There was a problem hiding this comment.
To drop specific entries before they become breadcrumbs or events, add a filter with
AddLogEntryFilter
This bit's good. We could link to the docs for that option rather than trying to re-explain it here (which means two different copies of the same explanation to keep in sync)?
Warning
Do not merge before sentry-dotnet 7.0.0 is released (planned 2026-11-30).
DESCRIBE YOUR PR
Adds a Generic Host guide for
Sentry.Extensions.Hosting, which sentry-dotnet 7.0.0 adds (getsentry/sentry-dotnet#5739). In 7.0.0,Logging.AddSentry()no longer initializes the SDK. Worker services, console apps on the generic host, Windows services and Azure Functions (isolated) apps callUseSentryfrom this package instead. The page is written for 7.x. The docs aren't versioned, so this stays a draft until 7.0.0 ships.The guide follows the quick start template from #19990 and covers:
UseSentryonIHostApplicationBuilderandIHostBuilder, theSentryandLogging:Sentrysections, and why not to callLogging.AddSentry()as well"Dsn": "", and when the SDK starts (Build()) and closes (ApplicationStopped)ClearProviders()ordering (fix(hosting): start the SDK during Build() even when the app clears or replaces logger providers sentry-dotnet#5772, fix(logging): make Logging.AddSentry() work after UseSentry and ClearProviders() sentry-dotnet#5776, fix(logging): warn when ClearProviders() removes the logger providers UseSentry added sentry-dotnet#5789, docs: add an ASP.NET Core NLog sample and stop advising AddSentry() when another integration handles ILogger sentry-dotnet#5821)UseSentrycall that Aspire'sAddServiceDefaultsneedsSentrySdk.InitandLogging.AddSentry()fallback and itsHubAdapter.Instanceregistrations (feat(mel)!: Logging.AddSentry() no longer registers IHub or ISentryClient sentry-dotnet#5740)SentrySdk.Init, briefly. The migration guide (docs(dotnet): Add 6.x to 7.x migration guide for 7.0.0-rc.2 #20143) covers upgrades.It also adds
platform-includes/configuration/config-intro/dotnet.extensions-hosting.mdx, so the guide's Options page starts withUseSentryinstead ofSentrySdk.Init.Closes getsentry/sentry-dotnet#5707
Notes for review
index.mdx. The platform keydotnet.extensions-hostingcomes from the folder name, guides withoutsidebar_order, like the other .NET guides, are listed by title, and the icon falls back to the .NET one, as for the Microsoft.Extensions.Logging, Serilog and NLog guides. The page is new, so it needs no redirects.packages.version('sentry.dotnet'), because the release registry has nosentry.dotnet.extensions.hostingentry yet. Until 7.0.0 is out, the preview shows 6.12.1, which doesn't exist for this package. Once the registry has the package, switch to its own key. Thesdk:frontmatter already usessentry.dotnet.extensions.hosting(fromConstants.cs). Without a registry entry, the page just has no package details box.dotnet.extensions-hosting. I left them alone, since other PRs own them:platform-includes/logs/setup/dotnet.mdxfalls into theSentrySdk.Initsection instead ofUseSentrywithEnableLogs. docs(dotnet): Update logging docs for SDK 7.0.0 #19925 is adding the key to the host sections.platform-includes/logs/options/dotnet.mdxshows the genericEnableLogstext and leaves out "Configure Microsoft.Extensions.Logging Filters". Same PR.platform-includes/logs/usage/dotnet.mdxshows only theSentrySdk.LoggerAPIs. The key belongs in theILoggersection too.platform-includes/logs/requirements/dotnet.mdxsays logs need SDK version 5.14.0. This package starts at 7.0.0.version7source:"Dsn": ""turns the SDK off, butSENTRY_DSNstill wins over an emptyDsn(SettingLocator.GetDsn). The page says so.Logging:Sentryonly acceptsLogLevel,MinimumBreadcrumbLevelandMinimumEventLevel. Any other key makesBuild()throwNotSupportedException. With no DSN anywhere,Build()throwsArgumentNullException.Sentry.AspNetCore'sUseSentrytwice still sends each error twice (a follow-up in feat: add Sentry.Extensions.Hosting with UseSentry for generic host apps sentry-dotnet#5739). The Aspire section says not to call it again inProgram.cs.logging.AddSentry(...). docs(dotnet): Update logging docs for SDK 7.0.0 #19925 owns it.Sentry.Samples.GenericHostsample link belongs here too, since the sample now callsUseSentry.UseSentrysetup.platform-includes/logs/integrations/dotnet.mdx: add Generic Host to the list.docs/product/logs/getting-started/index.mdxanddocs/product/metrics/getting-started/index.mdx: add Generic Host to the .NET lists.main, whereSentry.Samples.GenericHostkeeps the 6.x setup untilversion7is merged.version7, on net10.0, and on net48 for theIHostBuilderexample and the .NET Framework fallback. On net48,UseSentryonHostApplicationBuilderfails with CS1929, as the page says.IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs to go live.
Select exactly one option. For deadlines, replace
YYYY-MM-DDwith the due date. You can update this information later by editing the PR description.🤖 Generated with Claude Code