From 6b2c6f979d43d7eccc46fa8f8bfd152d758a1ac8 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Mon, 26 Oct 2026 15:39:49 -0700 Subject: [PATCH 01/16] docs(dotnet): Correct quick-start setup and verification Align setup examples and supported platforms with SDK 6.12.1. Clarify logging initialization, use the OTLP exporter for Blazor tracing, and verify each telemetry type. Refs #19990 --- .../platforms/dotnet/guides/android/index.mdx | 14 +++- docs/platforms/dotnet/guides/apple/index.mdx | 66 ++++++++++++--- docs/platforms/dotnet/guides/aspnet/index.mdx | 13 ++- .../dotnet/guides/aspnetcore/index.mdx | 9 ++- .../dotnet/guides/aws-lambda/index.mdx | 2 +- .../guides/azure-functions-worker/index.mdx | 2 +- .../dotnet/guides/blazor-server/index.mdx | 34 +++++--- .../guides/blazor-webassembly/index.mdx | 9 ++- .../dotnet/guides/entityframework/index.mdx | 26 +++--- .../guides/extensions-logging/index.mdx | 81 ++++++++++--------- .../guides/google-cloud-functions/index.mdx | 14 ++-- .../platforms/dotnet/guides/log4net/index.mdx | 50 +++++++++++- docs/platforms/dotnet/guides/maui/index.mdx | 6 +- docs/platforms/dotnet/guides/nlog/index.mdx | 41 ++++++---- .../platforms/dotnet/guides/serilog/index.mdx | 35 +++++--- .../dotnet/guides/winforms/index.mdx | 15 +++- docs/platforms/dotnet/guides/winui/index.mdx | 5 +- docs/platforms/dotnet/guides/wpf/index.mdx | 6 +- .../platforms/dotnet/guides/xamarin/index.mdx | 5 +- docs/platforms/dotnet/index.mdx | 6 +- .../getting-started-verify-data/dotnet.mdx | 9 +++ .../getting-started-verify-tracing/dotnet.mdx | 10 +++ 22 files changed, 322 insertions(+), 136 deletions(-) create mode 100644 platform-includes/getting-started-verify-data/dotnet.mdx create mode 100644 platform-includes/getting-started-verify-tracing/dotnet.mdx diff --git a/docs/platforms/dotnet/guides/android/index.mdx b/docs/platforms/dotnet/guides/android/index.mdx index 275826bcbcc2c..3066652db18f8 100644 --- a/docs/platforms/dotnet/guides/android/index.mdx +++ b/docs/platforms/dotnet/guides/android/index.mdx @@ -41,12 +41,17 @@ In your `MainActivity.cs` file, call `SentrySdk.Init` in the `OnCreate` event an The snippet also turns on: -- Tracing: via `TracesSampleRate` +- Tracing: via `TracesSampleRate` and `Native.EnableTracing` for the embedded Android SDK - Session Replay: via `Native.ExperimentalOptions.SessionReplay` Don't need a feature? Remove its options from the snippet. -```csharp +```csharp {filename:MainActivity.cs} +using Android.App; +using Android.OS; +using Sentry; +using Sentry.Android; + [Activity(Label = "@string/app_name", MainLauncher = true)] public class MainActivity : Activity { @@ -60,13 +65,14 @@ public class MainActivity : Activity // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. options.TracesSampleRate = 1.0; + options.Native.EnableTracing = true; #if DEBUG // Log debug information about the Sentry SDK options.Debug = true; #endif // Android specific .NET features are under the Android properties: - options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only + options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Attach logcat logs to handled and unhandled errors; default is None. options.Android.LogCatMaxLines = 1000; // Defaults to 1000 // Native Android SDK options are available via options.Native @@ -163,7 +169,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/docs/platforms/dotnet/guides/apple/index.mdx b/docs/platforms/dotnet/guides/apple/index.mdx index cacafbc17d0c4..82c186cd7e57b 100644 --- a/docs/platforms/dotnet/guides/apple/index.mdx +++ b/docs/platforms/dotnet/guides/apple/index.mdx @@ -22,12 +22,11 @@ Install-Package Sentry -Version {{@inject packages.version('sentry.dotnet') }} **Error Monitoring** starts working as soon as you call `SentrySdk.Init()`. **Logs** sent through `SentrySdk.Logger` and **Application Metrics** need no extra configuration. You'll learn how to send them in [Send Logs](#send-logs) and [Send Application Metrics](#send-application-metrics-). -This guide also enables **Tracing**, **Profiling**, and **Session Replay** (experimental). +This guide also enables **Tracing**. The iOS and Mac Catalyst setup enables **Profiling**, and the iOS setup enables experimental **Session Replay**. -On .NET for iOS, macOS, and Mac Catalyst, you also get: +On all three platforms, you get the features of the main [.NET SDK](/platforms/dotnet/) for your managed code. On iOS and Mac Catalyst, the embedded [Cocoa SDK](/platforms/apple/) also provides: -- All the features of our main [.NET SDK](/platforms/dotnet/), for your managed code -- Native crash reporting for Apple platforms, leveraging our [Cocoa SDK](/platforms/apple/) including: +- Native crash reporting, including: - Automatically [attach screenshots to Native exceptions](/platforms/apple/guides/ios/configuration/options/#attachScreenshot) - Detect [App Hangs](/platforms/apple/configuration/app-hangs/) - [Automatic performance tracing](/platforms/apple/tracing/) @@ -35,17 +34,23 @@ On .NET for iOS, macOS, and Mac Catalyst, you also get: - [Swizzling](/platforms/apple/configuration/swizzling/) - Automatic session tracking and [release health](/product/releases/) -In your `AppDelegate.cs` file, call `SentrySdk.Init` in the `FinishedLaunching` event and include any options you would like to set. The `Dsn` is the only required parameter. +### iOS and Mac Catalyst + +In your `AppDelegate.cs` file, call `SentrySdk.Init` in `FinishedLaunching`. Keep your existing window and application setup after the Sentry initialization. The `Dsn` is the only required setting. The snippet also turns on: -- Tracing: via `TracesSampleRate` +- Tracing: via `TracesSampleRate` and `Native.EnableTracing` for the embedded Cocoa SDK - Profiling: via `ProfilesSampleRate`. On iOS and Mac Catalyst, the SDK adds the native profiling integration automatically, so you don't need the `Sentry.Profiling` package. -- Session Replay: via `Native.ExperimentalOptions.SessionReplay` +- Session Replay on iOS: via `Native.ExperimentalOptions.SessionReplay` Don't need a feature? Remove its options from the snippet. -```csharp +```csharp {filename:AppDelegate.cs} +using Foundation; +using Sentry; +using UIKit; + [Register("AppDelegate")] public class AppDelegate : UIApplicationDelegate { @@ -60,6 +65,7 @@ public class AppDelegate : UIApplicationDelegate // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. options.TracesSampleRate = 1.0; + options.Native.EnableTracing = true; // Enables Profiling. // Set to 1.0 to profile 100% of captured transactions. options.ProfilesSampleRate = 1.0; @@ -75,9 +81,11 @@ public class AppDelegate : UIApplicationDelegate // https://docs.sentry.io/platforms/apple/guides/ios/configuration/options/#attachScreenshot options.Native.AttachScreenshot = true; - // Session Replay is currently available via the ExperimentalOptions +#if IOS + // Session Replay is available on iOS via ExperimentalOptions. options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0; options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0; +#endif options.SetBeforeSend(evt => { @@ -103,11 +111,43 @@ public class AppDelegate : UIApplicationDelegate For a full list of native options, see Apple Native Options. +### macOS + +For an AppKit application targeting `net*-macos`, initialize Sentry in `NSApplicationDelegate.DidFinishLaunching`. This target doesn't include the Cocoa integration's `options.Native` or `OnCrashedLastRun` APIs. + +```csharp {filename:AppDelegate.cs} +using AppKit; +using Foundation; +using Sentry; + +[Register("AppDelegate")] +public class AppDelegate : NSApplicationDelegate +{ + public override void DidFinishLaunching(NSNotification notification) + { + SentrySdk.Init(options => + { + options.Dsn = "___PUBLIC_DSN___"; + options.SendDefaultPii = true; + options.IsGlobalModeEnabled = true; + options.TracesSampleRate = 1.0; +#if DEBUG + options.Debug = true; +#endif + }); + + // Keep the rest of your application startup here. + } +} +``` + +For custom transactions, see [Verify Your Setup](#verify-your-setup). The Cocoa profiling and replay configuration above doesn't apply to this target. + ### Options The .NET for iOS, macOS, and Mac Catalyst integration is part of [Sentry](/platforms/dotnet/). Please refer to the documentation for that package for information about platform agnostic options. -For configuration of the embedded Sentry Cocoa SDK, see Apple Native Options. +For configuration of the embedded Sentry Cocoa SDK on iOS and Mac Catalyst, see Apple Native Options. ## Send Logs @@ -141,9 +181,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps @@ -152,4 +194,4 @@ At this point, you should have integrated Sentry into your .NET for iOS, macOS, - Explore [practical guides](/get-started/guides/) on what to monitor, log, track, and investigate after setup - Learn how to [manually capture errors](/platforms/dotnet/usage/) - Explore [Tracing](/platforms/dotnet/tracing/) -- Configure the embedded Cocoa SDK with Apple Native Options +- On iOS and Mac Catalyst, configure the embedded Cocoa SDK with Apple Native Options diff --git a/docs/platforms/dotnet/guides/aspnet/index.mdx b/docs/platforms/dotnet/guides/aspnet/index.mdx index a49d3a19ad296..eedf0ed6b9552 100644 --- a/docs/platforms/dotnet/guides/aspnet/index.mdx +++ b/docs/platforms/dotnet/guides/aspnet/index.mdx @@ -37,12 +37,11 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. -```csharp +```csharp {filename:Global.asax.cs} using System; using System.Web; +using Sentry; using Sentry.AspNet; -using Sentry.EntityFramework; // If you also installed Sentry.EntityFramework -using Sentry.Extensibility; public class MvcApplication : HttpApplication { @@ -64,8 +63,6 @@ public class MvcApplication : HttpApplication // We recommend reducing this value in production. options.TracesSampleRate = 1.0; - // If you also installed the Sentry.EntityFramework package - options.AddEntityFramework(); options.AddAspNet(); }); } @@ -90,6 +87,8 @@ public class MvcApplication : HttpApplication } ``` +If you also use Entity Framework 6, install `Sentry.EntityFramework` and add `options.AddEntityFramework()` to the same initialization callback. See the [Entity Framework guide](/platforms/dotnet/guides/entityframework/) for setup details. + ### Capturing the affected user When opting-in to [SendDefaultPii](#senddefaultpii), the SDK will automatically read the user from the request by inspecting `HttpContext.User`. Default claim values like `NameIdentifier` for the _Id_ will be used. @@ -104,7 +103,7 @@ options.SendDefaultPii = true; ### SendDefaultPii -Although this setting is part of the [Sentry](/platforms/dotnet/) package, in the context of ASP.NET Core, it means reporting the user by reading the frameworks `HttpContext.User`. The strategy to create the `SentryUser` can be customized. +Although this setting is part of the [Sentry](/platforms/dotnet/) package, in ASP.NET it also enables reporting the user from `HttpContext.User`. ### IncludeRequestPayload @@ -151,7 +150,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Troubleshooting diff --git a/docs/platforms/dotnet/guides/aspnetcore/index.mdx b/docs/platforms/dotnet/guides/aspnetcore/index.mdx index 4b33240722ece..71814952ee58f 100644 --- a/docs/platforms/dotnet/guides/aspnetcore/index.mdx +++ b/docs/platforms/dotnet/guides/aspnetcore/index.mdx @@ -18,7 +18,7 @@ dotnet add package Sentry.AspNetCore -v {{@inject packages.version('sentry.dotne ``` ```shell {tabTitle:Paket CLI} -paket add Sentry --version {{@inject packages.version('sentry.dotnet.aspnetcore') }} +paket add Sentry.AspNetCore --version {{@inject packages.version('sentry.dotnet.aspnetcore') }} ``` This package extends [Sentry.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/). This means that besides the ASP.NET Core related features, through this package you'll also get access to all the framework's logging integration and also the features available in the main [Sentry](/platforms/dotnet/) SDK. @@ -29,9 +29,9 @@ This package extends [Sentry.Extensions.Logging](/platforms/dotnet/guides/extens This guide also enables **Tracing**. -The simplest way to initialize Sentry in ASP.NET Core is by using the `UseSentry` extension method from the `Sentry.AspNetCore` package in conjunction with the [framework configuration system](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0). +The simplest way to initialize Sentry in ASP.NET Core is by using the `UseSentry` extension method from the `Sentry.AspNetCore` package in conjunction with the [framework configuration system](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/). -Call `UseSentry` with your DSN and the options you want. The SDK provides this as extension methods to support ASP.NET Core `2.X`, `3.X`, and `5.X` and later. +`Sentry.AspNetCore` 6.x requires .NET 8 or later. Call `UseSentry` with your DSN and the options you want. Applications on older .NET versions need a compatible older SDK version; see the Migration Guide. The snippet also turns on: @@ -82,6 +82,7 @@ public static IWebHost BuildWebHost(string[] args) => // We recommend reducing this value in production. options.TracesSampleRate = 1.0; }) + .Build(); ``` ### Additional configuration @@ -330,7 +331,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Samples diff --git a/docs/platforms/dotnet/guides/aws-lambda/index.mdx b/docs/platforms/dotnet/guides/aws-lambda/index.mdx index 088b899271e1f..43b80991a643b 100644 --- a/docs/platforms/dotnet/guides/aws-lambda/index.mdx +++ b/docs/platforms/dotnet/guides/aws-lambda/index.mdx @@ -115,7 +115,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Samples diff --git a/docs/platforms/dotnet/guides/azure-functions-worker/index.mdx b/docs/platforms/dotnet/guides/azure-functions-worker/index.mdx index 7fa4beee87e09..29b3ce66d19fd 100644 --- a/docs/platforms/dotnet/guides/azure-functions-worker/index.mdx +++ b/docs/platforms/dotnet/guides/azure-functions-worker/index.mdx @@ -119,7 +119,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Samples diff --git a/docs/platforms/dotnet/guides/blazor-server/index.mdx b/docs/platforms/dotnet/guides/blazor-server/index.mdx index c05548bffc813..0071c897b4859 100644 --- a/docs/platforms/dotnet/guides/blazor-server/index.mdx +++ b/docs/platforms/dotnet/guides/blazor-server/index.mdx @@ -73,16 +73,30 @@ However, on .NET 10 and later, Blazor emits OpenTelemetry activities for circuit #### Install OpenTelemetry -See OpenTelemetry Support for installation and setup instructions. +Install the OTLP exporter and OpenTelemetry instrumentation: + +```shell {tabTitle:.NET Core CLI} +dotnet add package Sentry.OpenTelemetry.Exporter -v {{@inject packages.version('sentry.dotnet') }} +dotnet add package OpenTelemetry.Extensions.Hosting +dotnet add package OpenTelemetry.Instrumentation.AspNetCore +``` + +```powershell {tabTitle:Package Manager} +Install-Package Sentry.OpenTelemetry.Exporter -Version {{@inject packages.version('sentry.dotnet') }} +Install-Package OpenTelemetry.Extensions.Hosting +Install-Package OpenTelemetry.Instrumentation.AspNetCore +``` + +See OpenTelemetry (OTLP) for sampling and trace propagation. #### Configure OpenTelemetry -Wire up Sentry as an OpenTelemetry exporter, subscribe to the Blazor activity sources, and register helper services for circuit and breadcrumb tracking: +Copy the [helper services](#circuit-lifecycle-tracking-services) into your application and add a `using` directive for their namespace. Then configure the OTLP exporter, subscribe to the Blazor activity sources, and register the helpers: ```csharp {filename:Program.cs} using Microsoft.AspNetCore.Components.Server.Circuits; using OpenTelemetry.Trace; -using Sentry.OpenTelemetry; +using Sentry; var builder = WebApplication.CreateBuilder(args); @@ -95,18 +109,14 @@ builder.Services.AddOpenTelemetry() tracing.AddSource("Microsoft.AspNetCore.Components"); tracing.AddSource("Microsoft.AspNetCore.Components.Server.Circuits"); tracing.AddAspNetCoreInstrumentation(); - // Export traces to Sentry - tracing.AddSentry(); + tracing.SetSampler(new ParentBasedSampler(new TraceIdRatioBasedSampler(0.1))); + tracing.AddSentryOtlpExporter("___PUBLIC_DSN___"); }); builder.WebHost.UseSentry(options => { options.Dsn = "___PUBLIC_DSN___"; - options.UseOpenTelemetry(); - // Enables Tracing. - // Set to 1.0 to capture 100% of spans for tracing. - // We recommend reducing this value in production. - options.TracesSampleRate = 0.1; + options.UseOtlp(); // Rewrites /_blazor SignalR transaction names to the actual Blazor route options.AddEventProcessor(new BlazorEventProcessor()); }); @@ -128,6 +138,8 @@ app.MapFallbackToPage("/_Host"); app.Run(); ``` +OpenTelemetry handles sampling in this configuration. Don't also set `TracesSampleRate` on the Sentry options. + #### Circuit Lifecycle Tracking Services The `BlazorSentryIntegration`, `SentryCircuitHandler`, and `BlazorEventProcessor` services shown above are not part of the Sentry integration. You can copy them from the [Blazor Server sample](https://github.com/getsentry/sentry-dotnet/tree/main/samples/Sentry.Samples.AspNetCore.Blazor.Server/Services) into your application if they prove useful for your use case. @@ -174,7 +186,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Samples diff --git a/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx b/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx index bafbb652e24b1..b71da37229294 100644 --- a/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx +++ b/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx @@ -56,12 +56,11 @@ builder.UseSentry(options => options.TracesSampleRate = 0.1; }); -// Captures logError and higher as events -builder.Logging.AddSentry(o => o.InitializeSdk = false); - await builder.Build().RunAsync(); ``` +`UseSentry` also registers the logging integration. Don't call `builder.Logging.AddSentry` separately. + ## Send Logs Use `Microsoft.Extensions.Logging` to send structured logs from your application. Set `EnableLogs = true` in your Sentry initialization. @@ -108,9 +107,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Samples diff --git a/docs/platforms/dotnet/guides/entityframework/index.mdx b/docs/platforms/dotnet/guides/entityframework/index.mdx index d08272d0a7fc5..0d5bfae99f3a0 100644 --- a/docs/platforms/dotnet/guides/entityframework/index.mdx +++ b/docs/platforms/dotnet/guides/entityframework/index.mdx @@ -5,7 +5,7 @@ description: Learn about Sentry's .NET integration with Entity Framework. og_image: /og-images/platforms-dotnet-guides-entityframework.png --- -Sentry provides an integration with `EntityFramework` through the of the [Sentry.EntityFramework NuGet package](https://www.nuget.org/packages/Sentry.EntityFramework). +Sentry provides an integration with Entity Framework 6 through the [Sentry.EntityFramework NuGet package](https://www.nuget.org/packages/Sentry.EntityFramework). > Looking for `EntityFramework Core`? If you're targeting .NET Core 3.1 or newer, that's already built in to the main Sentry .NET SDK. It's also enabled by default for our ASP.NET or ASP.NET Core integrations, even for older targets. For other scenarios, you may need to add the `Sentry.DiagnosticSource` package and call `AddDiagnosticSourceIntegration`, [as described here](/platforms/dotnet/tracing/instrumentation/automatic-instrumentation/#diagnosticsource-integration). (The rest of this page describes our EF6 integration, not EFCore.) @@ -40,7 +40,15 @@ Add the Entity Framework 6 support to your project in one step: ### Example configuration -For example, configuring an ASP.NET app with _global.asax_: +The following example configures an ASP.NET application in `Global.asax.cs`. In addition to `Sentry.EntityFramework`, install [Sentry.AspNet](/platforms/dotnet/guides/aspnet/), which provides request context, request-scoped data, and the HTTP transaction helpers used here: + +```powershell {tabTitle:Package Manager} +Install-Package Sentry.AspNet -Version {{@inject packages.version('sentry.dotnet.aspnet') }} +``` + +```shell {tabTitle:.NET Core CLI} +dotnet add package Sentry.AspNet -v {{@inject packages.version('sentry.dotnet.aspnet') }} +``` The snippet also turns on: @@ -48,9 +56,10 @@ The snippet also turns on: Don't need a feature? Remove its options from the snippet. -```csharp {filename:global.asax} +```csharp {filename:Global.asax.cs} using System; using System.Configuration; +using Sentry; using Sentry.AspNet; public class MvcApplication : System.Web.HttpApplication @@ -69,7 +78,7 @@ public class MvcApplication : System.Web.HttpApplication // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. options.TracesSampleRate = 1.0; - // Add the EntityFramework integration + options.AddAspNet(); options.AddEntityFramework(); }); } @@ -85,10 +94,9 @@ public class MvcApplication : System.Web.HttpApplication { Context.FinishSentryTransaction(); } - public override void Dispose() + protected void Application_End() { - _sentrySdk.Dispose(); - base.Dispose(); + _sentrySdk?.Dispose(); } } ``` @@ -127,11 +135,11 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Sample -Check out a complete working [sample](https://github.com/getsentry/sentry-dotnet-ef/tree/master/samples/Sentry.Samples.AspNet.Mvc) to see it in action. +See the [Entity Framework sample](https://github.com/getsentry/sentry-dotnet/tree/main/samples/Sentry.Samples.EntityFramework) for a standalone application using this integration. ![Sample breadcrumbs in Sentry](./img/dotnet-entityframework.png) diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index 058be82f62cc9..a6170167df953 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -38,54 +38,42 @@ This package extends `Sentry` main SDK. That means that besides the logging rela -Messages logged from assemblies with the name starting with `Sentry` will not generate events. +The integration excludes the Sentry SDK's own logger categories to avoid capturing its diagnostic messages as events. Application categories that happen to start with `Sentry` aren't excluded solely because of that prefix. ## Configure -There are two ways to add this integration into your project. In both cases it means calling an extension method. The places where it's available are: +Call `AddSentry` on an `ILoggingBuilder`, either through a generic host or `LoggerFactory.Create`. This registers the providers for error events, breadcrumbs, and structured logs. -- `ILoggingBuilder` -- `ILoggerFactory` +The legacy `ILoggerFactory.AddSentry` extension registers only the error-event and breadcrumb provider. Use `LoggerFactory.Create` with `builder.AddSentry` to capture structured logs too. ASP.NET Core's `UseSentry` already registers the providers, so it doesn't need a separate `AddSentry` call. -The `ILoggingBuilder` extension is useful when using a `WebHostBuilder` or a `HostBuilder`, also known as _Generic host_. This extension method is used by the ASP.NET Core integration under the hood to automatically. - -The extension to `ILoggerFactory` is a convenient way when only the `LoggerFactory` is being used, without any framework integration. +### Example configuration -In both cases the method call is: +#### Through `ILoggingBuilder` -**AddSentry()** +This example uses a generic host from the `Microsoft.Extensions.Hosting` package: -### Example configuration +```csharp {filename:Program.cs} +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; -#### Through `ILoggingBuilder` +var builder = Host.CreateApplicationBuilder(args); +builder.Logging.AddConfiguration(builder.Configuration); +builder.Logging.AddSentry(); -```csharp -public static Task Main() - => new HostBuilder() - .ConfigureHostConfiguration(c => - { - c.SetBasePath(Directory.GetCurrentDirectory()); - c.AddJsonFile("appsettings.json", optional: false); - }) - .ConfigureLogging((c, l) => - { - l.AddConfiguration(c.Configuration); - // Adding Sentry integration to Microsoft.Extensions.Logging - l.AddSentry(); - }) - .Build(); +using var host = builder.Build(); +await host.RunAsync(); ``` -In this example, a _generic host_ is being built and the MEL integration with Sentry added through `ConfigureLogging`. The example also demonstrates how to bind the `appsettings.json` configuration to make the values available to the Sentry integration. +The host loads `appsettings.json` and environment variables. Sentry reads its options from the `Sentry` configuration section. With this approach, options like `Dsn`, `SendDefaultPii`, `MinimumBreadcrumbLevel`, to name a few, can be set in `appsettings.json`. Example using `appsettings.json`: -```json +```json {filename:appsettings.json} { "Logging": { "LogLevel": { @@ -95,6 +83,7 @@ Example using `appsettings.json`: }, "Sentry": { "Dsn": "___PUBLIC_DSN___", + "EnableLogs": true, "SendDefaultPii": true, "MinimumBreadcrumbLevel": "Debug", "MinimumEventLevel": "Warning", @@ -109,11 +98,20 @@ Above we set the application wide minimum log level to `Debug` and we configure ```csharp -using (var loggerFactory = new LoggerFactory() - .AddConsole(LogLevel.Trace) - .AddSentry(o => o.Dsn = "___PUBLIC_DSN___")) +using Microsoft.Extensions.Logging; + +using (var loggerFactory = LoggerFactory.Create(builder => +{ + builder.SetMinimumLevel(LogLevel.Information); + builder.AddSentry(options => + { + options.Dsn = "___PUBLIC_DSN___"; + options.EnableLogs = true; + }); +})) { - var logger = loggerFactory.CreateLogger(); + var logger = loggerFactory.CreateLogger("Example"); + logger.LogInformation("Order processed {OrderId}", "order-123"); } ``` @@ -127,15 +125,19 @@ In cases where `AddSentry` is called without arguments, it's worth noting that a -The SDK needs to be initialized only once. If the `DSN` is made available to this integration, by default it **will** initialize the SDK. If you do not wish to initialize the SDK via this configuration, set the `InitializeSdk` flag to **false**. Not providing a DSN or leaving it as an _empty string_ will disable the SDK. +Initialize the SDK once. `ILoggingBuilder.AddSentry` initializes it by default and can resolve a DSN from configuration or `SENTRY_DSN`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN isn't a substitute for this flag. An explicitly empty DSN disables the SDK. For example: ```csharp -using (var loggerFactory = new LoggerFactory() - .AddSentry(o => o.InitializeSdk = false)) +using (var loggerFactory = LoggerFactory.Create(builder => + builder.AddSentry(options => + { + options.InitializeSdk = false; + options.EnableLogs = true; + }))) { } ``` @@ -175,9 +177,14 @@ options.TagFilters.Add("PROC_"); ## Verify -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. +After creating a logger with one of the configurations above, send an informational log and an error to verify both providers: + +```csharp +logger.LogInformation("Sentry logging verification"); +logger.LogError("Sentry error-event verification"); +``` - +Check **Logs** for the informational log and **Issues** for the error event. Run this code before disposing the host or logger factory. ## Samples diff --git a/docs/platforms/dotnet/guides/google-cloud-functions/index.mdx b/docs/platforms/dotnet/guides/google-cloud-functions/index.mdx index 9b0f8af3ffd38..98cec74c19281 100644 --- a/docs/platforms/dotnet/guides/google-cloud-functions/index.mdx +++ b/docs/platforms/dotnet/guides/google-cloud-functions/index.mdx @@ -30,7 +30,7 @@ This package extends `Sentry.AspNetCore`, which in turn extends `Sentry`'s main -Messages logged from assemblies with the name starting with `Sentry` will not generate events. +The logging integration excludes the Sentry SDK's own logger categories to avoid capturing its diagnostic messages as events. @@ -104,10 +104,12 @@ using Microsoft.AspNetCore.Http; public class Function : IHttpFunction { + public Task HandleAsync(HttpContext context) => + context.Response.WriteAsync("Hello from Google Cloud Functions"); } ``` -Some of the settings require actual code. For those, like the `BeforeSend` callback, you will need to create a new class implementing the abstract class `FunctionsStartup` to set it up: +Some settings, such as the `BeforeSend` callback, require code. Keep the `SentryStartup` assembly registration above and add another `FunctionsStartup` registration for your custom configuration: ```csharp using Google.Cloud.Functions.Hosting; @@ -144,13 +146,13 @@ Much of the behavior of the Google cloud functions integration with Sentry can b When opting in to `SendDefaultPii`, the SDK will automatically read the user from the request by inspecting `HttpContext.User`. Default claim values like `NameIdentifier` for the _Id_ will be used. -If you wish to change the behavior of how to read the user from the request, you can register a new `IUserFactory` into the container: +To customize how Sentry reads the user from the request, implement `ISentryUserFactory` and register it in the container. Keep the `SentryStartup` registration when adding this startup class: ```csharp using Google.Cloud.Functions.Hosting; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using Sentry.AspNetCore; +using Sentry; [assembly: FunctionsStartup(typeof(UserFactoryStartup))] @@ -159,7 +161,7 @@ public class UserFactoryStartup : FunctionsStartup public override void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) { base.ConfigureServices(context, services); - services.AddSingleton(); + services.AddSingleton(); } } ``` @@ -191,7 +193,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/docs/platforms/dotnet/guides/log4net/index.mdx b/docs/platforms/dotnet/guides/log4net/index.mdx index 99c61499a86b4..4205ab6278133 100644 --- a/docs/platforms/dotnet/guides/log4net/index.mdx +++ b/docs/platforms/dotnet/guides/log4net/index.mdx @@ -52,16 +52,60 @@ In the example above, the `SendIdentity` flag was switched on. The SDK then will ### DSN -Also in the example above, you can find the DSN being set. That will instruct the `SentryAppender` to initialize the SDK. +The appender initializes the SDK lazily when it processes its first log entry and no SDK is already enabled. Setting `Dsn` in the configuration doesn't initialize the SDK immediately. This is only one of the ways to initialize the SDK. If you wish to configure the SDK programmatically, you could **leave the DSN out** from the appender configuration section. The SDK needs to be initialized only **once** and since other integrations (like ASP.NET) are also able to initialize the SDK, you only need to pass the DSN to one of these integrations. One common case to not add the DSN to the XML configuration file (which would initialize it via the log4net integration) is to have full access to the [SDK option](/platforms/dotnet/guides/log4net/configuration/options/). +### Structured Logs + +To send structured logs, initialize Sentry in code before logging and omit `Dsn` from the appender configuration: + +```csharp +SentrySdk.Init(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + options.EnableLogs = true; +}); +``` + +If another integration already initializes Sentry, set `EnableLogs = true` there instead. The appender uses the existing SDK. + ## Verify -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. +Ensure log4net loads your configuration and the appender is referenced by a logger. For example, add this inside your `` element alongside the appender: + +```xml {filename:app.config} + + + + +``` + +Run this code during application startup to initialize through the appender and verify error capture: + +```csharp +using System; +using log4net; +using log4net.Config; +using Sentry; + +XmlConfigurator.Configure(); +var logger = LogManager.GetLogger("SentryVerification"); + +try +{ + throw new InvalidOperationException("Sentry log4net verification"); +} +catch (Exception exception) +{ + logger.Error("Sentry error-event verification", exception); +} + +SentrySdk.FlushAsync().GetAwaiter().GetResult(); +``` - +Check **Issues** for the error event. If you enabled structured logs, also check **Logs**. A direct `SentrySdk.CaptureException` call won't initialize the appender, so it can't verify this setup before the first log entry. ## Sample diff --git a/docs/platforms/dotnet/guides/maui/index.mdx b/docs/platforms/dotnet/guides/maui/index.mdx index 1688daecfafc0..4ad7dc8cf6fb3 100644 --- a/docs/platforms/dotnet/guides/maui/index.mdx +++ b/docs/platforms/dotnet/guides/maui/index.mdx @@ -6,6 +6,8 @@ description: "Learn about Sentry's .NET integration with .NET Multi-platform App Sentry has an integration for the [.NET Multi-platform App UI (MAUI)](https://dotnet.microsoft.com/apps/maui) through the [Sentry.Maui NuGet package](https://www.nuget.org/packages/Sentry.Maui). +`Sentry.Maui` 6.x requires .NET MAUI 9 or later. For .NET MAUI 8, use a compatible 5.x SDK version. + **Overview of the features** - Easy MAUI integration by calling `UseSentry` on your `MauiAppBuilder` @@ -79,7 +81,7 @@ public static MauiApp CreateMauiApp() options.AttachScreenshot = true; // Other Sentry options can be set here. - }) + }); // ... the remainder of your MAUI app setup @@ -176,7 +178,7 @@ Let's test your setup and confirm that data reaches your Sentry project. ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/docs/platforms/dotnet/guides/nlog/index.mdx b/docs/platforms/dotnet/guides/nlog/index.mdx index c597b48a3b510..7768fa043767e 100644 --- a/docs/platforms/dotnet/guides/nlog/index.mdx +++ b/docs/platforms/dotnet/guides/nlog/index.mdx @@ -18,7 +18,7 @@ By default, Sentry will keep any message with log level `Info` or higher as a `B The default value to report a log entry as an event to Sentry is `Error`. -This means that out of the box, any `Error` call will create an `Event` which will include all log messages of level `Info`, `Warn` and also `Error` and `Critical`. +This means that out of the box, any `Error` call will create an `Event` which will include all log messages of level `Info`, `Warn`, `Error`, and `Fatal` stored as breadcrumbs. Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). @@ -36,12 +36,6 @@ dotnet add package Sentry.NLog -v {{@inject packages.version('sentry.dotnet.nlog This package extends `Sentry` main SDK. That means that besides the logging related features, through this package you'll also get access to all API and features available in the main `Sentry` SDK. - - -Messages logged from assemblies with the name starting with `Sentry` will not generate events. - - - ## Configure @@ -50,13 +44,16 @@ For more information on how to dynamically set event data via `NLog.config`, see -You can configure the Sentry NLog target via code as follows: +If another integration already initializes Sentry, add the NLog target without reinitializing the SDK. Enable `EnableLogs` on the options used by that integration to send structured logs. ```csharp -LogManager.Configuration = new LoggingConfiguration(); -LogManager.Configuration - .AddSentry(options => +using NLog; +using NLog.Config; + +var configuration = new LoggingConfiguration(); +configuration.AddSentry(options => { + options.InitializeSdk = false; // Optionally specify a separate format for message options.Layout = "${message}"; // Optionally specify a separate format for breadcrumbs @@ -72,6 +69,7 @@ LogManager.Configuration // All Sentry Options are accessible here. }); +LogManager.Configuration = configuration; ``` It's also possible to initialize the SDK through the NLog integration (as opposed to using `SentrySdk.Init`). @@ -79,18 +77,19 @@ This is useful when NLog is the only integration being used in your application. ```csharp -LogManager.Configuration = new LoggingConfiguration(); -LogManager.Configuration - .AddSentry(o => +var configuration = new LoggingConfiguration(); +configuration.AddSentry(o => { // The NLog integration will initialize the SDK if DSN is set: o.Dsn = "___PUBLIC_DSN___"; + o.EnableLogs = true; }); +LogManager.Configuration = configuration; ``` -The SDK needs to be initialized only once. If a `DSN` is made available to this integration, by default it **will** initialize the SDK. If you do not wish to initialize the SDK via this integration, set the `InitializeSdk` flag to **false**. Not providing a DSN or leaving it as `null` instructs the integration not to initialize the SDK and unless another integration initializes it or you call `SentrySdk.Init`, the SDK will stay disabled. +Initialize the SDK once. `InitializeSdk` defaults to `true`, and initialization can resolve a DSN from `SENTRY_DSN` even when you omit `Dsn`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN doesn't prevent reinitialization and can replace the existing SDK configuration. @@ -121,6 +120,7 @@ The SDK can also be configured via `NLog.config` XML file: +With `EnableLogs = true`, the informational message appears in **Logs**. The error message also creates an event in **Issues**. Call `LogManager.Shutdown()` when your application exits to dispose the target and flush pending data. ## Samples diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index be1d4e29a9ed2..6a3a131cd0347 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -18,7 +18,7 @@ By default, any message with log level `Information` or higher will be kept as a The default value to report a log entry as an event to Sentry is `Error`. -This means that out of the box, any `LogError` call will create an `Event` which will include breadcrumbs for all prior log messages of level `Information`, `Warning`, `Error` and `Critical`. +This means that out of the box, any `Log.Error` call will create an `Event` which will include breadcrumbs for prior log messages of level `Information`, `Warning`, `Error`, and `Fatal`. Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/). You can control which logs are captured using the [Serilog MinimumLogLevel](https://github.com/serilog/serilog/wiki/Configuration-Basics#minimum-level). @@ -38,18 +38,23 @@ This package extends `Sentry` main SDK. That means that besides the logging rela -Messages logged from assemblies with the name starting with `Sentry` will not generate events. +The integration excludes the Sentry SDK's own logger categories to avoid capturing its diagnostic messages as events. Application categories that happen to start with `Sentry` aren't excluded solely because of that prefix. ## Configure -You can configure the Sentry Serilog sink as follows: +If another integration already initializes Sentry, configure the Serilog sink without reinitializing the SDK. Enable `EnableLogs` on the options used by that integration to send structured logs. ```csharp +using Serilog; +using Serilog.Events; + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() .WriteTo.Sentry(o => { + o.InitializeSdk = false; // Debug and higher are stored as breadcrumbs (default is Information) o.MinimumBreadcrumbLevel = LogEventLevel.Debug; // Warning and higher is sent as event (default is Error) @@ -78,12 +83,16 @@ Log.Logger = new LoggerConfiguration() } ``` -It's also possible to initialize the SDK through the Serilog integration. This is useful when the Serilog is the only integration being used in your application. To initialize the Sentry SDK through the Serilog integration, provide it with the DSN: +When Serilog owns initialization, provide the DSN and enable structured logs in the sink configuration: ```csharp Log.Logger = new LoggerConfiguration() - .WriteTo.Sentry(o => o.Dsn = "___PUBLIC_DSN___") + .WriteTo.Sentry(o => + { + o.Dsn = "___PUBLIC_DSN___"; + o.EnableLogs = true; + }) .CreateLogger(); ``` @@ -95,7 +104,8 @@ Log.Logger = new LoggerConfiguration() { "Name": "Sentry", "Args": { - "dsn": "___PUBLIC_DSN___" + "dsn": "___PUBLIC_DSN___", + "enableLogs": true } } ] @@ -105,7 +115,9 @@ Log.Logger = new LoggerConfiguration() -The SDK only needs to be initialized once. If a `DSN` is made available to this integration, by default it **will** initialize the SDK. If you do not wish to initialize the SDK via this integration, set the `InitializeSdk` flag to **false**. Not providing a DSN or leaving it as `null` instructs the integration not to initialize the SDK and unless another integration initializes it or you call `SentrySdk.Init`, the SDK will stay disabled. +Initialize the SDK once. The C# callback overload defaults `InitializeSdk` to `true` and can resolve a DSN from `SENTRY_DSN`. Set `InitializeSdk = false` when another integration or `SentrySdk.Init` owns initialization. Omitting the DSN from that callback doesn't prevent reinitialization. + +The configuration-file overload infers initialization from its `dsn` argument. In the first JSON example, Sentry must already be initialized elsewhere; supplying `dsn`, as in the second example, enables initialization through the sink. @@ -141,9 +153,14 @@ An optional `LoggingLevelSwitch` that allows the sink's minimum level to be chan ## Verify -This snippet includes an intentional error, so you can test that everything is working as soon as you set it up. +After configuring Serilog, send an informational log and an error: + +```csharp +Log.Information("Sentry logging verification"); +Log.Error("Sentry error-event verification"); +``` - +With `EnableLogs = true`, the informational message appears in **Logs**. The error message also creates an event in **Issues**. Call `Log.CloseAndFlush()` when your application exits to dispose the sink and flush pending data. ## Samples diff --git a/docs/platforms/dotnet/guides/winforms/index.mdx b/docs/platforms/dotnet/guides/winforms/index.mdx index 0c2e5915b5bd2..704b5222daa62 100644 --- a/docs/platforms/dotnet/guides/winforms/index.mdx +++ b/docs/platforms/dotnet/guides/winforms/index.mdx @@ -36,6 +36,7 @@ Don't need a feature? Remove its options from the snippet. ```csharp using System; using System.Windows.Forms; +using Sentry; namespace WindowsFormsApp1 { @@ -130,8 +131,11 @@ Module Program ' Adds request URL and headers, IP and name for users, etc. .SendDefaultPii = True, + ' Enable tracing; reduce this value in production. + .TracesSampleRate = 1.0, + ' Enable Global Mode since this is a client app - .IsGlobalModeEnabled = True, + .IsGlobalModeEnabled = True ' any other options you need go here } @@ -191,8 +195,11 @@ Namespace My ' Adds request URL and headers, IP and name for users, etc. .SendDefaultPii = True, + ' Enable tracing; reduce this value in production. + .TracesSampleRate = 1.0, + ' Enable Global Mode since this is a client app - .IsGlobalModeEnabled = True, + .IsGlobalModeEnabled = True ' any other options you need go here } @@ -257,9 +264,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Resources diff --git a/docs/platforms/dotnet/guides/winui/index.mdx b/docs/platforms/dotnet/guides/winui/index.mdx index 16f84ae9841b2..4ff5a86fec780 100644 --- a/docs/platforms/dotnet/guides/winui/index.mdx +++ b/docs/platforms/dotnet/guides/winui/index.mdx @@ -83,6 +83,7 @@ Do not initialize the SDK in the `OnLaunched` event of the application or the `H ```csharp // Add these to your existing using statements. +using System.Security; using Sentry.Protocol; using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs; @@ -181,9 +182,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/docs/platforms/dotnet/guides/wpf/index.mdx b/docs/platforms/dotnet/guides/wpf/index.mdx index f9a1444911649..2edb664cae488 100644 --- a/docs/platforms/dotnet/guides/wpf/index.mdx +++ b/docs/platforms/dotnet/guides/wpf/index.mdx @@ -28,6 +28,8 @@ Don't need a feature? Remove its options from the snippet. ```csharp using System.Windows; +using System.Windows.Threading; +using Sentry; public partial class App : Application { @@ -97,9 +99,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/docs/platforms/dotnet/guides/xamarin/index.mdx b/docs/platforms/dotnet/guides/xamarin/index.mdx index 2e7800b29932c..03e78239148a7 100644 --- a/docs/platforms/dotnet/guides/xamarin/index.mdx +++ b/docs/platforms/dotnet/guides/xamarin/index.mdx @@ -8,7 +8,7 @@ Sentry's .NET SDK works with Xamarin applications through the [Sentry Xamarin Nu The SDK is compatible with the following versions or higher: -- Xamarin.Android 9.0 +- Xamarin.Android 11.0 - Xamarin.iOS 10.14 - Universal Windows Platform 10.0.16299 - Tizen 4.0 @@ -37,7 +37,8 @@ Don't need a feature? Remove its options from the snippet. ```csharp SentryXamarin.Init(options => { - options.AddXamarinFormsIntegration(); + // Add this only if you installed Sentry.Xamarin.Forms: + // options.AddXamarinFormsIntegration(); // Tells which project in Sentry to send events to: options.Dsn = "___PUBLIC_DSN___"; // When configuring for the first time, to see what the SDK is doing: diff --git a/docs/platforms/dotnet/index.mdx b/docs/platforms/dotnet/index.mdx index d6803feaf506d..5973764f5dd46 100644 --- a/docs/platforms/dotnet/index.mdx +++ b/docs/platforms/dotnet/index.mdx @@ -69,7 +69,7 @@ SentrySdk.Init(options => -Profiling for .NET is in Alpha and needs .NET 8 or later. On .NET Framework, `Sentry.Profiling` installs without a warning, but `AddProfilingIntegration()` doesn't compile. +Profiling for .NET is in Alpha. The `Sentry.Profiling` package requires .NET 8 or later and doesn't support .NET Framework. For iOS and Mac Catalyst, use the built-in profiler described in the [Apple guide](/platforms/dotnet/guides/apple/#configure). @@ -125,9 +125,11 @@ Let's test your setup and confirm that data reaches your Sentry project. + + ### View Captured Data in Sentry -Open your Sentry project to view the captured event. + ## Next Steps diff --git a/platform-includes/getting-started-verify-data/dotnet.mdx b/platform-includes/getting-started-verify-data/dotnet.mdx new file mode 100644 index 0000000000000..9580025e958ee --- /dev/null +++ b/platform-includes/getting-started-verify-data/dotnet.mdx @@ -0,0 +1,9 @@ +Run any log and metric examples you've added after SDK initialization. To verify automatic tracing, exercise an instrumented operation, such as an incoming HTTP request or a supported UI interaction. + +Logs and metrics are batched. In an async test method, flush pending data before a short-lived test exits: + +```csharp +await SentrySdk.FlushAsync(); +``` + +Check **Issues** for the captured error, **Logs** for log messages, **Metrics** for application metrics, and **Traces** for sampled transactions. Error capture alone doesn't verify the other features. diff --git a/platform-includes/getting-started-verify-tracing/dotnet.mdx b/platform-includes/getting-started-verify-tracing/dotnet.mdx new file mode 100644 index 0000000000000..eca84a6033c5f --- /dev/null +++ b/platform-includes/getting-started-verify-tracing/dotnet.mdx @@ -0,0 +1,10 @@ +To verify tracing for code without automatic instrumentation, create and finish a test transaction after initializing Sentry: + +```csharp +var transaction = SentrySdk.StartTransaction("quickstart-test", "test"); +transaction.Finish(); +``` + +`TracesSampleRate` controls sampling; it doesn't create transactions by itself. See Custom Instrumentation to trace work in your application. + +If you enabled profiling, run a longer sampled transaction after the profiler has initialized. A short verification transaction might finish before the profiler collects any samples. From 7b0eac8498cbeda9c671e58221ba4b3c59aa98bf Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:20:20 -0700 Subject: [PATCH 02/16] Update docs/platforms/dotnet/guides/android/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/android/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/android/index.mdx b/docs/platforms/dotnet/guides/android/index.mdx index 3066652db18f8..e4f1e573b298b 100644 --- a/docs/platforms/dotnet/guides/android/index.mdx +++ b/docs/platforms/dotnet/guides/android/index.mdx @@ -65,7 +65,6 @@ public class MainActivity : Activity // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. options.TracesSampleRate = 1.0; - options.Native.EnableTracing = true; #if DEBUG // Log debug information about the Sentry SDK options.Debug = true; From acf936885215862803e90fe3a422641f5c6d5ad2 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:20:33 -0700 Subject: [PATCH 03/16] Update docs/platforms/dotnet/guides/apple/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/apple/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/apple/index.mdx b/docs/platforms/dotnet/guides/apple/index.mdx index 82c186cd7e57b..6263d3a4ba979 100644 --- a/docs/platforms/dotnet/guides/apple/index.mdx +++ b/docs/platforms/dotnet/guides/apple/index.mdx @@ -40,7 +40,7 @@ In your `AppDelegate.cs` file, call `SentrySdk.Init` in `FinishedLaunching`. Kee The snippet also turns on: -- Tracing: via `TracesSampleRate` and `Native.EnableTracing` for the embedded Cocoa SDK +- Tracing: via `TracesSampleRate` - Profiling: via `ProfilesSampleRate`. On iOS and Mac Catalyst, the SDK adds the native profiling integration automatically, so you don't need the `Sentry.Profiling` package. - Session Replay on iOS: via `Native.ExperimentalOptions.SessionReplay` From 09b622bfaf0dd25fdeeecc6bcd8deb7c7cf79384 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:20:47 -0700 Subject: [PATCH 04/16] Update docs/platforms/dotnet/guides/nlog/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/nlog/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/nlog/index.mdx b/docs/platforms/dotnet/guides/nlog/index.mdx index 7768fa043767e..182741be80a47 100644 --- a/docs/platforms/dotnet/guides/nlog/index.mdx +++ b/docs/platforms/dotnet/guides/nlog/index.mdx @@ -89,7 +89,7 @@ LogManager.Configuration = configuration; -Initialize the SDK once. `InitializeSdk` defaults to `true`, and initialization can resolve a DSN from `SENTRY_DSN` even when you omit `Dsn`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN doesn't prevent reinitialization and can replace the existing SDK configuration. +Initialize the SDK once. `InitializeSdk` defaults to `true`, and initialization can resolve a DSN from `SENTRY_DSN` even when you omit `Dsn`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN doesn't prevent reinitialization: the target either uses `SENTRY_DSN` and replaces the existing SDK configuration, or fails to initialize because no DSN was found. From 1efae19d21bfc77dfad1694c9e4624d2009b8f76 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:20:57 -0700 Subject: [PATCH 05/16] Update docs/platforms/dotnet/guides/aspnetcore/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/aspnetcore/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/aspnetcore/index.mdx b/docs/platforms/dotnet/guides/aspnetcore/index.mdx index 71814952ee58f..d8301dda91873 100644 --- a/docs/platforms/dotnet/guides/aspnetcore/index.mdx +++ b/docs/platforms/dotnet/guides/aspnetcore/index.mdx @@ -31,7 +31,7 @@ This guide also enables **Tracing**. The simplest way to initialize Sentry in ASP.NET Core is by using the `UseSentry` extension method from the `Sentry.AspNetCore` package in conjunction with the [framework configuration system](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/). -`Sentry.AspNetCore` 6.x requires .NET 8 or later. Call `UseSentry` with your DSN and the options you want. Applications on older .NET versions need a compatible older SDK version; see the Migration Guide. +`Sentry.AspNetCore` 6.x requires .NET 8 or later. Call `UseSentry` with your DSN and the options you want. For .NET 6 or 7, use `Sentry.AspNetCore` 4.x. The snippet also turns on: From 1a60662b439e021399a3834851e872b06049bed2 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:21:39 -0700 Subject: [PATCH 06/16] Update docs/platforms/dotnet/guides/winui/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/winui/index.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/platforms/dotnet/guides/winui/index.mdx b/docs/platforms/dotnet/guides/winui/index.mdx index 4ff5a86fec780..86f90536fa229 100644 --- a/docs/platforms/dotnet/guides/winui/index.mdx +++ b/docs/platforms/dotnet/guides/winui/index.mdx @@ -84,6 +84,7 @@ Do not initialize the SDK in the `OnLaunched` event of the application or the `H ```csharp // Add these to your existing using statements. using System.Security; +using Sentry; using Sentry.Protocol; using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs; From d758533c53ba3ca80e7ccc24f7524960a9f4fcd2 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:21:50 -0700 Subject: [PATCH 07/16] Update docs/platforms/dotnet/guides/android/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/android/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/android/index.mdx b/docs/platforms/dotnet/guides/android/index.mdx index e4f1e573b298b..7a328d3ab60dd 100644 --- a/docs/platforms/dotnet/guides/android/index.mdx +++ b/docs/platforms/dotnet/guides/android/index.mdx @@ -41,7 +41,7 @@ In your `MainActivity.cs` file, call `SentrySdk.Init` in the `OnCreate` event an The snippet also turns on: -- Tracing: via `TracesSampleRate` and `Native.EnableTracing` for the embedded Android SDK +- Tracing: via `TracesSampleRate` - Session Replay: via `Native.ExperimentalOptions.SessionReplay` Don't need a feature? Remove its options from the snippet. From e42f6dba8c8f5b6c57d667fd88207187bad6f625 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:21:59 -0700 Subject: [PATCH 08/16] Update docs/platforms/dotnet/guides/apple/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/apple/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/apple/index.mdx b/docs/platforms/dotnet/guides/apple/index.mdx index 6263d3a4ba979..82589252a17af 100644 --- a/docs/platforms/dotnet/guides/apple/index.mdx +++ b/docs/platforms/dotnet/guides/apple/index.mdx @@ -29,7 +29,7 @@ On all three platforms, you get the features of the main [.NET SDK](/platforms/d - Native crash reporting, including: - Automatically [attach screenshots to Native exceptions](/platforms/apple/guides/ios/configuration/options/#attachScreenshot) - Detect [App Hangs](/platforms/apple/configuration/app-hangs/) - - [Automatic performance tracing](/platforms/apple/tracing/) + - Opt-in [automatic performance tracing](/platforms/apple/tracing/). See `Native.EnableTracing`. - [Automatic breadcrumbs](/platforms/apple/enriching-events/breadcrumbs/#automatic-breadcrumbs) - [Swizzling](/platforms/apple/configuration/swizzling/) - Automatic session tracking and [release health](/product/releases/) From b357bf0d4c479620e7e5666055b88144f78afb79 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:22:14 -0700 Subject: [PATCH 09/16] Update docs/platforms/dotnet/guides/apple/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/apple/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/apple/index.mdx b/docs/platforms/dotnet/guides/apple/index.mdx index 82589252a17af..025420afd9fd2 100644 --- a/docs/platforms/dotnet/guides/apple/index.mdx +++ b/docs/platforms/dotnet/guides/apple/index.mdx @@ -65,7 +65,6 @@ public class AppDelegate : UIApplicationDelegate // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. options.TracesSampleRate = 1.0; - options.Native.EnableTracing = true; // Enables Profiling. // Set to 1.0 to profile 100% of captured transactions. options.ProfilesSampleRate = 1.0; From 3683127fe8467eb04488e1e68947aa20b006f9ca Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:22:23 -0700 Subject: [PATCH 10/16] Update docs/platforms/dotnet/guides/serilog/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/serilog/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index 6a3a131cd0347..595e94954d19f 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -115,7 +115,7 @@ Log.Logger = new LoggerConfiguration() -Initialize the SDK once. The C# callback overload defaults `InitializeSdk` to `true` and can resolve a DSN from `SENTRY_DSN`. Set `InitializeSdk = false` when another integration or `SentrySdk.Init` owns initialization. Omitting the DSN from that callback doesn't prevent reinitialization. +Initialize the SDK once. The C# callback overload defaults `InitializeSdk` to `true` and can resolve a DSN from `SENTRY_DSN`. Set `InitializeSdk = false` when another integration or `SentrySdk.Init` owns initialization. Omitting the DSN from that callback doesn't prevent reinitialization: it uses `SENTRY_DSN` if set and replaces the existing SDK configuration, and otherwise throws because no DSN was found. The configuration-file overload infers initialization from its `dsn` argument. In the first JSON example, Sentry must already be initialized elsewhere; supplying `dsn`, as in the second example, enables initialization through the sink. From 2143b718f338b3f55d72fb4eec039170a578a8b2 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:22:45 -0700 Subject: [PATCH 11/16] Update docs/platforms/dotnet/guides/blazor-webassembly/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/blazor-webassembly/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx b/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx index b71da37229294..9f416bd84e987 100644 --- a/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx +++ b/docs/platforms/dotnet/guides/blazor-webassembly/index.mdx @@ -53,7 +53,7 @@ builder.UseSentry(options => // Enables Tracing. // Set to 1.0 to capture 100% of spans for tracing. // We recommend reducing this value in production. - options.TracesSampleRate = 0.1; + options.TracesSampleRate = 1.0; }); await builder.Build().RunAsync(); From 10e570872ae0c3f099feba7089b90e2f1d139d27 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:23:08 -0700 Subject: [PATCH 12/16] Update docs/platforms/dotnet/guides/extensions-logging/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/extensions-logging/index.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index a6170167df953..876fda1207299 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -59,6 +59,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; var builder = Host.CreateApplicationBuilder(args); +// Lets Sentry read the top-level "Sentry" section of appsettings.json builder.Logging.AddConfiguration(builder.Configuration); builder.Logging.AddSentry(); From 82dce914026199a3893be40f469c51caf70ba039 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:23:37 -0700 Subject: [PATCH 13/16] Update docs/platforms/dotnet/guides/extensions-logging/index.mdx Co-authored-by: Ricardo Colombo Oliveira --- docs/platforms/dotnet/guides/extensions-logging/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/extensions-logging/index.mdx b/docs/platforms/dotnet/guides/extensions-logging/index.mdx index 876fda1207299..7a9816b209243 100644 --- a/docs/platforms/dotnet/guides/extensions-logging/index.mdx +++ b/docs/platforms/dotnet/guides/extensions-logging/index.mdx @@ -126,7 +126,7 @@ In cases where `AddSentry` is called without arguments, it's worth noting that a -Initialize the SDK once. `ILoggingBuilder.AddSentry` initializes it by default and can resolve a DSN from configuration or `SENTRY_DSN`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN isn't a substitute for this flag. An explicitly empty DSN disables the SDK. +Initialize the SDK once. `ILoggingBuilder.AddSentry` initializes it by default and can resolve a DSN from configuration or `SENTRY_DSN`. If another integration or `SentrySdk.Init` owns initialization, set `InitializeSdk = false`. Omitting the DSN isn't a substitute for this flag: if no DSN is found, initialization throws. An explicitly empty DSN disables the SDK. From 45a029ff0a03c76e394fb90707446aa2062b47df Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Thu, 29 Oct 2026 11:33:32 -0700 Subject: [PATCH 14/16] docs(dotnet): Fix VB setup and ASP.NET SDK lifetime Use With statement blocks in both WinForms VB examples so comments and blank lines remain valid. Keep the ASP.NET and Entity Framework SDK handles static so shutdown disposes the initialized SDK across HttpApplication instances. --- docs/platforms/dotnet/guides/aspnet/index.mdx | 2 +- .../dotnet/guides/entityframework/index.mdx | 2 +- .../dotnet/guides/winforms/index.mdx | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/platforms/dotnet/guides/aspnet/index.mdx b/docs/platforms/dotnet/guides/aspnet/index.mdx index eedf0ed6b9552..9c4255fbcd01d 100644 --- a/docs/platforms/dotnet/guides/aspnet/index.mdx +++ b/docs/platforms/dotnet/guides/aspnet/index.mdx @@ -45,7 +45,7 @@ using Sentry.AspNet; public class MvcApplication : HttpApplication { - private IDisposable _sentry; + private static IDisposable _sentry; protected void Application_Start() { diff --git a/docs/platforms/dotnet/guides/entityframework/index.mdx b/docs/platforms/dotnet/guides/entityframework/index.mdx index 0d5bfae99f3a0..02568c407640b 100644 --- a/docs/platforms/dotnet/guides/entityframework/index.mdx +++ b/docs/platforms/dotnet/guides/entityframework/index.mdx @@ -64,7 +64,7 @@ using Sentry.AspNet; public class MvcApplication : System.Web.HttpApplication { - private IDisposable _sentrySdk; + private static IDisposable _sentrySdk; protected void Application_Start() { diff --git a/docs/platforms/dotnet/guides/winforms/index.mdx b/docs/platforms/dotnet/guides/winforms/index.mdx index 704b5222daa62..2113a6d6dd3cc 100644 --- a/docs/platforms/dotnet/guides/winforms/index.mdx +++ b/docs/platforms/dotnet/guides/winforms/index.mdx @@ -124,21 +124,21 @@ Module Program Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException) ' Configure the options for Sentry - Dim sentryOptions = New SentryOptions With - { - .Dsn = "___PUBLIC_DSN___", + Dim sentryOptions As New SentryOptions() + With sentryOptions + .Dsn = "___PUBLIC_DSN___" ' Adds request URL and headers, IP and name for users, etc. - .SendDefaultPii = True, + .SendDefaultPii = True ' Enable tracing; reduce this value in production. - .TracesSampleRate = 1.0, + .TracesSampleRate = 1.0 ' Enable Global Mode since this is a client app .IsGlobalModeEnabled = True ' any other options you need go here - } + End With ' Initialize Sentry and run the main form of the application Using SentrySdk.Init(sentryOptions) @@ -188,21 +188,21 @@ Namespace My Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup ' Configure the options for Sentry - Dim sentryOptions = New SentryOptions With - { - .Dsn = "___PUBLIC_DSN___", + Dim sentryOptions As New SentryOptions() + With sentryOptions + .Dsn = "___PUBLIC_DSN___" ' Adds request URL and headers, IP and name for users, etc. - .SendDefaultPii = True, + .SendDefaultPii = True ' Enable tracing; reduce this value in production. - .TracesSampleRate = 1.0, + .TracesSampleRate = 1.0 ' Enable Global Mode since this is a client app .IsGlobalModeEnabled = True ' any other options you need go here - } + End With ' Initialize Sentry _sentry = SentrySdk.Init(sentryOptions) From 1d6bf1c7ed22d763d433c8095ef43814d2f5e178 Mon Sep 17 00:00:00 2001 From: Shannon Anahata Date: Mon, 9 Nov 2026 14:24:36 -0800 Subject: [PATCH 15/16] Update docs/platforms/dotnet/guides/nlog/index.mdx Co-authored-by: Alex Krawiec --- docs/platforms/dotnet/guides/nlog/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/nlog/index.mdx b/docs/platforms/dotnet/guides/nlog/index.mdx index 182741be80a47..b50cab82b089c 100644 --- a/docs/platforms/dotnet/guides/nlog/index.mdx +++ b/docs/platforms/dotnet/guides/nlog/index.mdx @@ -44,7 +44,7 @@ For more information on how to dynamically set event data via `NLog.config`, see -If another integration already initializes Sentry, add the NLog target without reinitializing the SDK. Enable `EnableLogs` on the options used by that integration to send structured logs. +If another integration already initializes Sentry, add the NLog target without reinitializing the SDK. Set `EnableLogs = true` on the options used by that integration to send structured logs. ```csharp using NLog; From 5c5239b5f8f6291bd874dc9d4b584e7814f4daba Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 11 Nov 2026 10:12:08 +1300 Subject: [PATCH 16/16] docs(dotnet): Mark Android native tracing as opt-in Activity lifecycle and User Interaction tracing come from the embedded Android SDK, which only traces when Native.EnableTracing is set. Co-Authored-By: Claude Opus 5.5 --- docs/platforms/dotnet/guides/android/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/dotnet/guides/android/index.mdx b/docs/platforms/dotnet/guides/android/index.mdx index 7a328d3ab60dd..3d2aa82fedf3d 100644 --- a/docs/platforms/dotnet/guides/android/index.mdx +++ b/docs/platforms/dotnet/guides/android/index.mdx @@ -32,7 +32,7 @@ On .NET for Android, you also get: - [Capture Application Not Responding (ANR) errors](/platforms/android/configuration/app-not-respond/) when the app is unresponsive - Automatically [attach screenshots to Java exceptions](/platforms/android/enriching-events/screenshots/) - Automatic breadcrumbs for Activity lifecycle, App lifecycle, System and Network events and User Interactions - - Automatic [Activity lifecycle tracing](/platforms/android/tracing/instrumentation/automatic-instrumentation/#activity-instrumentation) and [User Interaction tracing](/platforms/android/tracing/instrumentation/automatic-instrumentation/#user-interaction-instrumentation) + - Opt-in automatic [Activity lifecycle tracing](/platforms/android/tracing/instrumentation/automatic-instrumentation/#activity-instrumentation) and [User Interaction tracing](/platforms/android/tracing/instrumentation/automatic-instrumentation/#user-interaction-instrumentation) through the embedded Android SDK. See `Native.EnableTracing`. - Device Root checking - Native crash reporting for Android, leveraging our [Android NDK](/platforms/android/configuration/using-ndk/) - Automatic session tracking and [release health](/product/releases/)