npx skills add ...
npx skills add getsentry/sentry-for-claude --skill sentry-dotnet-sdk
npx skills add getsentry/sentry-for-claude --skill sentry-dotnet-sdk
Full Sentry SDK setup for .NET. Use when asked to "add Sentry to .NET", "install Sentry for C#", or configure error monitoring, tracing, profiling, logging, or crons for ASP.NET Core, MAUI, WPF, WinForms, Blazor, Azure Functions, or any other .NET application.
The same skill content is published under more than one repo. The install counts are split across them; any of these commands works.
All Skills > SDK Setup > .NET SDK
Opinionated wizard that scans your .NET project and guides you through complete Sentry setup: error monitoring, distributed tracing, profiling, structured logging, and cron monitoring across all major .NET frameworks.
SentrySdk.Init, UseSentry, Sentry.AspNetCore, or Sentry.MauiSentryOptions, BeforeSend, TracesSampleRate, or symbol uploadNote: SDK version and APIs below reflect
SentryNuGet packages ≥6.1.0 (OTLP export requires ≥6.5.0). Always verify against docs.sentry.io/platforms/dotnet/ before implementing.
Run these commands to understand the project before making any recommendations:
What to determine:
| Question | Impact |
|---|---|
| Framework type? | Determines correct package and init pattern |
| .NET version? | .NET 8+ recommended; .NET Framework 4.6.2+ supported |
| Sentry already installed? | Skip install, go to feature config |
| Logging library (Serilog, NLog)? | Recommend matching Sentry sink/target |
| Async/hosted app (ASP.NET Core)? | UseSentry() on WebHost; no IsGlobalModeEnabled needed |
| Desktop app (WPF, WinForms, WinUI)? | Must set IsGlobalModeEnabled = true |
| Serverless (Azure Functions, Lambda)? | Must set FlushOnCompletedRequest = true |
| Frontend directory found? | Trigger Phase 4 cross-link |
Framework → Package mapping:
| Detected | Package to install |
|---|---|
Sdk="Microsoft.NET.Sdk.Web" (ASP.NET Core) | Sentry.AspNetCore |
App.xaml.cs with Application base | Sentry (WPF) |
[STAThread] in Program.cs | Sentry (WinForms) |
MauiProgram.cs | Sentry.Maui |
WebAssemblyHostBuilder | Sentry.AspNetCore.Blazor.WebAssembly |
FunctionsStartup | Sentry.Extensions.Logging + Sentry.OpenTelemetry |
HttpApplication / Global.asax | Sentry.AspNet |
| Generic host / Worker Service | Sentry.Extensions.Logging |
Present a concrete recommendation based on what you found. Lead with a proposal — don't ask open-ended questions.
Recommended (core coverage):
Optional (enhanced observability):
Recommendation logic:
| Feature | Recommend when... |
|---|---|
| Error Monitoring | Always — non-negotiable baseline |
| Tracing | Always for ASP.NET Core — request traces, EF Core spans, HttpClient spans are high-value |
| Logging | App uses ILogger<T>, Serilog, NLog, or log4net |
| Profiling | Performance-critical service on .NET 6+ |
| Metrics | App needs custom business metrics (request counts, queue depths, response times) |
| Crons | App uses Hangfire, Quartz.NET, or scheduled Azure Functions |
Propose: "I recommend setting up Error Monitoring + Tracing + Logging. Want me to also add Profiling or Crons?"
You need to run this yourself — the wizard opens a browser for login and requires interactive input that the agent can't handle. Copy-paste into your terminal:
It handles login, org/project selection, DSN configuration, and MSBuild symbol upload setup for readable stack traces in production.
Once it finishes, come back and skip to Verification.
If the user skips the wizard, proceed with Option 2 (Manual Setup) below.
Program.csappsettings.json (alternative configuration):
Environment variables (double underscore as separator):
App.xaml.cs⚠️ Critical: Initialize in the constructor, NOT in
OnStartup(). The constructor fires earlier, catching more failure modes.
Program.csMauiProgram.csProgram.csProgram.csRecommended: Install
Sentry.OpenTelemetry.Exporter(≥6.5.0) for OTLP export. Alternatively, useSentry.OpenTelemetryfor the bridge pattern.
LambdaEntryPoint.csGlobal.asax.csWithout debug symbols, stack traces show only method names — no file names or line numbers. The SDK uploads PDB files (and optionally sources) via MSBuild properties on Release builds:
Upload needs a SENTRY_AUTH_TOKEN set in CI (a secret). For creating the token and the CI wiring, see sentry-source-maps. The SentryCreateRelease / SentrySetCommits properties also create a release with suspect commits — see sentry-releases.
Load the corresponding reference file and follow its steps:
| Feature | Reference file | Load when... |
|---|---|---|
| Error Monitoring | references/error-monitoring.md | Always — CaptureException, scopes, enrichment, filtering |
| Tracing | references/tracing.md | Server apps, distributed tracing, EF Core spans, custom instrumentation |
| Profiling | references/profiling.md | Performance-critical apps on .NET 6+ |
| Logging | references/logging.md | ILogger<T>, Serilog, NLog, log4net integration |
| Metrics | references/metrics.md | Custom counters, gauges, distributions; EmitCounter, EmitGauge, EmitDistribution |
| Crons | references/crons.md | Hangfire, Quartz.NET, or scheduled function monitoring |
For each feature: read the reference file, follow its steps exactly, and verify before moving on.
SentryOptions| Option | Type | Default | Env Var | Notes |
|---|---|---|---|---|
Dsn | string | — | SENTRY_DSN | Required. SDK disabled if unset. |
Debug | bool | false | — | SDK diagnostic output. Disable in production. |
DiagnosticLevel | SentryLevel | Debug | — | Debug, Info, Warning, Error, Fatal |
Release | string | auto | SENTRY_RELEASE | Auto-detected from assembly version + git SHA |
Environment | string | "production" | SENTRY_ENVIRONMENT | "debug" when debugger attached |
Dist | string | — | — | Build variant. Max 64 chars. |
SampleRate | float | 1.0 | — | Error event sampling rate 0.0–1.0 |
TracesSampleRate | double | 0.0 | — | Transaction sampling. Must be > 0 to enable. |
TracesSampler | Func<SamplingContext, double> | — | — | Per-transaction dynamic sampler; overrides TracesSampleRate |
ProfilesSampleRate | double | 0.0 | — | Fraction of traced transactions to profile. Requires Sentry.Profiling. |
SendDefaultPii | bool | false | — | Include user IP, name, email |
AttachStacktrace | bool | true | — | Attach stack trace to all messages |
MaxBreadcrumbs | int | 100 | — | Max breadcrumbs stored per event |
IsGlobalModeEnabled | bool | false* | — | *Auto-true for MAUI, Blazor WASM. Must be true for WPF, WinForms, Console. |
AutoSessionTracking | bool | false* | — | *Auto-true for MAUI. Enable for Release Health. |
CaptureFailedRequests | bool | true | — | Auto-capture HTTP client errors |
CacheDirectoryPath | string | — | — | Offline event caching directory |
ShutdownTimeout | TimeSpan | — | — | Max wait for event flush on shutdown |
HttpProxy | string | — | — | Proxy URL for Sentry requests |
EnableBackpressureHandling | bool | true | — | Auto-reduce sample rates on delivery failures |
TraceIgnoreStatusCodes | IList<HttpStatusCodeRange> | [] | — | Drop transactions whose HTTP response status matches any range; e.g., [404] or [(500, 599)] |
StrictTraceContinuation | bool | false | — | When true, starts a new trace if exactly one side (SDK or incoming sentry-org_id baggage) has an org ID. A full mismatch (both present but different) always starts a new trace regardless of this setting. (requires ≥6.6.0) |
OrgId | string | auto | — | Organization ID for trace validation; auto-parsed from DSN subdomain (e.g., o123.ingest.sentry.io → "123"). Recommended to set explicitly for self-hosted Sentry, local Relay, or custom domains (requires ≥6.6.0) |
SentryAspNetCoreOptions)| Option | Type | Default | Notes |
|---|---|---|---|
MaxRequestBodySize | RequestSize | None | None, Small (~4 KB), Medium (~10 KB), Always |
MinimumBreadcrumbLevel | LogLevel | Information | Min log level for breadcrumbs |
MinimumEventLevel | LogLevel | Error | Min log level to send as Sentry event |
CaptureBlockingCalls | bool | false | Detect .Wait() / .Result threadpool starvation |
FlushOnCompletedRequest | bool | false | Required for Lambda / serverless |
IncludeActivityData | bool | false | Capture System.Diagnostics.Activity values |
SentryMauiOptions)| Option | Type | Default | Notes |
|---|---|---|---|
IncludeTextInBreadcrumbs | bool | false | Text from Button, Label, Entry elements. ⚠️ PII risk. |
IncludeTitleInBreadcrumbs | bool | false | Titles from Window, Page elements. ⚠️ PII risk. |
IncludeBackgroundingStateInBreadcrumbs | bool | false | Window.Backgrounding event state. ⚠️ PII risk. |
| Variable | Purpose |
|---|---|
SENTRY_DSN | Project DSN |
SENTRY_RELEASE | App version (e.g. my-app@1.2.3) |
SENTRY_ENVIRONMENT | Deployment environment name |
SENTRY_AUTH_TOKEN | MSBuild / sentry-cli symbol upload auth token |
ASP.NET Core: use double underscore __ as hierarchy separator:
| Property | Type | Default | Description |
|---|---|---|---|
SentryOrg | string | — | Sentry organization slug |
SentryProject | string | — | Sentry project slug |
SentryUploadSymbols | bool | false | Upload PDB files for line numbers in stack traces |
SentryUploadSources | bool | false | Upload source files for source context |
SentryCreateRelease | bool | false | Auto-create a Sentry release during build |
SentrySetCommits | bool | false | Associate git commits with the release |
SentryUrl | string | — | Self-hosted Sentry URL |
After wizard or manual setup, add a test throw and remove it after verifying:
Then check your Sentry Issues dashboard — the error should appear within ~30 seconds.
Verification checklist:
| Check | How |
|---|---|
| Exceptions captured | Throw a test exception, verify in Sentry Issues |
| Stack traces readable | Check that file names and line numbers appear |
| Tracing active | Check Performance tab for transactions |
| Logging wired | Log an error via ILogger, check it appears as Sentry breadcrumb |
| Symbol upload working | Stack trace shows Controllers/HomeController.cs:42 not <unknown> |
After completing .NET setup, check for companion frontend projects:
If a frontend is found, suggest the matching SDK skill:
| Frontend detected | Suggest skill |
|---|---|
Next.js ("next" in package.json) | sentry-nextjs-sdk |
React SPA ("react" without "next") | @sentry/react — see docs.sentry.io/platforms/javascript/guides/react/ |
| Vue.js | @sentry/vue — see docs.sentry.io/platforms/javascript/guides/vue/ |
| Nuxt | @sentry/nuxt — see docs.sentry.io/platforms/javascript/guides/nuxt/ |
Connecting frontend and backend with the same Sentry project enables distributed tracing — a single trace view spanning browser, .NET server, and any downstream APIs.
| Issue | Cause | Solution |
|---|---|---|
| Events not appearing | DSN misconfigured | Set Debug = true and check console output for SDK diagnostic messages |
| Stack traces show no file/line | PDB files not uploaded | Add SentryUploadSymbols=true to .csproj; set SENTRY_AUTH_TOKEN in CI |
| WPF/WinForms exceptions missing | IsGlobalModeEnabled not set | Set options.IsGlobalModeEnabled = true in SentrySdk.Init() |
| Lambda/serverless events lost | Container freezes before flush | Set options.FlushOnCompletedRequest = true |
| WPF UI-thread exceptions missing | DispatcherUnhandledException not wired | Register App.DispatcherUnhandledException in constructor (not OnStartup) |
| Duplicate HTTP spans in Azure Functions | Both Sentry and OTel instrument HTTP | Set options.DisableSentryHttpMessageHandler = true |
TracesSampleRate has no effect | Rate is 0.0 (default) | Set TracesSampleRate > 0 to enable tracing |
appsettings.json values ignored | Config key format wrong | Use flat key "Sentry:Dsn" or env var Sentry__Dsn (double underscore) |
BeforeSend drops all events | Hook returns null unconditionally | Verify your filter logic; return null only for events you want to drop |
| MAUI native crashes not captured | Wrong package | Confirm Sentry.Maui is installed (not just Sentry) |