Skip to content

fix(onboarding): Update ASP.NET Core snippets to minimal hosting - #127238

Merged
ric-oliv merged 2 commits into
masterfrom
fix/dotnet-aspnetcore-onboarding-snippets
Oct 13, 2026
Merged

ric-oliv merged 2 commits into
masterfrom
fix/dotnet-aspnetcore-onboarding-snippets

Conversation

@ric-oliv

@ric-oliv ric-oliv commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

The ASP.NET Core onboarding still shows the pre-.NET 6 template, so its snippets don't fit a project created with dotnet new web, and two of them don't compile:

  • The configure step defines CreateHostBuilder with Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(...). A minimal-hosting Program.cs has no class to put it in.
  • Adapting it by chaining .Build() onto builder.WebHost.UseSentry(...) builds an IWebHost instead of the WebApplication. That fails with CS1929 and, on .NET 10, also raises the ASPDEPR008 warning.
  • The tracing step says to add a middleware to Startup.cs, then shows no code.
  • The span sample is an MVC controller that doesn't compile:

    CS0161: 'HomeController.Person(string)': not all code paths return a value

  • The shared metrics verify snippet starts with using Sentry;. Pasted into Program.cs after builder.Build(), it fails:

    CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations

Changes

  • Configure: WebApplication.CreateBuilder(args), builder.WebHost.UseSentry(...), then var app = builder.Build(); as its own statement, with one sentence saying why.
  • Verify: the CaptureMessage call is shown between builder.Build() and app.Run(). The DI sentence now explains IHub in the text, and the unit-testing link sits on "easier to test".
  • Tracing: says that every request is traced automatically once TracesSampleRate is set. The span example is an app.MapGet endpoint that takes IHub as a parameter, replacing the MVC controller.
  • Metrics verify (shared by the .NET platforms): removed using Sentry;. The logs verify snippet never had it, and the Sentry package adds the Sentry namespace as an implicit using whenever ImplicitUsings is on, which every .NET 6+ template enables.
  • Samples: removed the two F# demo links (sentry-demos/fsharp, last updated in 2023, and sentry-demos/giraffe, in 2021).
  • Fallback version: 4.3.0 → 6.12.1.
  • Spec: a new case checks that the minimal-hosting configure snippet and the MapGet example render, and that CreateHostBuilder doesn't.

Testing

I took every snippet on the page, as rendered from these files with all products selected, and pasted it into a fresh dotnet new web project with Sentry.AspNetCore 6.12.1. It builds with no warnings on .NET 8, 10 and 11. Run against a local envelope receiver, the message, both logs, the counter, distribution and gauge, and the GET /person/{id} transaction with its additional-work span all arrive.

Refs getsentry/sentry-dotnet#5700

The ASP.NET Core onboarding still showed the pre-.NET 6 CreateHostBuilder
template, a tracing step pointing at Startup.cs with no code, and an MVC
span sample that didn't compile (CS0161). The shared .NET metrics verify
snippet started with `using Sentry;`, which fails with CS1529 when pasted
into Program.cs after builder.Build().

Show the WebApplication form with UseSentry and Build() as separate
statements, place the verify call between Build() and Run(), use an
app.MapGet endpoint taking IHub for the span example, drop the stale F#
sample links, and bump the fallback version to 6.12.1.

Refs getsentry/sentry-dotnet#5700

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 13, 2026
…ternals

The tracing step explained that UseSentry adds a middleware, and the
configure step explained the IWebHostBuilder return type. Neither tells a
new user anything they need. Say what they get instead: every request is
traced once TracesSampleRate is set, and chaining .Build() onto UseSentry
makes app.MapGet fail to compile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ric-oliv
ric-oliv marked this pull request as ready for review October 13, 2026 12:16
@ric-oliv
ric-oliv requested a review from a team as a code owner October 13, 2026 12:16

@bitsandfoxes bitsandfoxes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ric-oliv
ric-oliv merged commit a4a6d7b into master Oct 13, 2026
71 of 72 checks passed
@ric-oliv
ric-oliv deleted the fix/dotnet-aspnetcore-onboarding-snippets branch October 13, 2026 13:49

This branch was successfully deployed

1 active deployment
Preview — 68e4cd23 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants