Skip to content

refactor: migrate DotNet sdks to inline product options syntax #13415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/platforms/dotnet/guides/aspnet/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ as well as your logs as breadcrumbs. The logging integrations also capture event
You configure the SDK in the `Global.asax.cs`:


```csharp {"onboardingOptions": {"performance": "22-25, 35-44"}}
```csharp
using System;
using System.Web;
using Sentry.AspNet;
Expand All @@ -56,9 +56,11 @@ public class MvcApplication : HttpApplication
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;

// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance

// If you also installed the Sentry.EntityFramework package
options.AddEntityFramework();
Expand All @@ -69,6 +71,7 @@ public class MvcApplication : HttpApplication
// Global error catcher
protected void Application_Error() => Server.CaptureLastError();

// ___PRODUCT_OPTION_START___ performance
protected void Application_BeginRequest()
{
Context.StartSentryTransaction();
Expand All @@ -78,6 +81,7 @@ public class MvcApplication : HttpApplication
{
Context.FinishSentryTransaction();
}
// ___PRODUCT_OPTION_END___ performance

protected void Application_End()
{
Expand Down
12 changes: 9 additions & 3 deletions docs/platforms/dotnet/guides/aspnetcore/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The framework takes configuration settings from `appsettings.json`, environment
An example of some of the options that can be configured via `appsettings.json`:


```json {filename:appsettings.json} {"onboardingOptions": {"performance": "10"}}
```json {filename:appsettings.json}
"Sentry": {
"Dsn": "___PUBLIC_DSN___",
"SendDefaultPii": true,
Expand All @@ -79,7 +79,9 @@ An example of some of the options that can be configured via `appsettings.json`:
"AttachStackTrace": true,
"Debug": true,
"DiagnosticLevel": "Error",
// ___PRODUCT_OPTION_START___ performance
"TracesSampleRate": 1.0
// ___PRODUCT_OPTION_END___ performance
},
```

Expand Down Expand Up @@ -107,11 +109,13 @@ ASP.NET Core will automatically read this environment variable and bind it to th

Finally, any settings that can be configured via `appsettings.json` or environment variables can also be configured via code. Some settings can only be configured in code, such as the `BeforeSend` callback:

```csharp {"onboardingOptions": {"performance": "4"}}
```csharp
.UseSentry(options =>
{
options.SendDefaultPii = true; // Adds request URL and headers, IP and name for users, etc.
// ___PRODUCT_OPTION_START___ performance
options.TracesSampleRate = 1.0; // Set this to configure automatic tracing
// ___PRODUCT_OPTION_END___ performance
options.SetBeforeSend((@event, hint) =>
{
// Never report server names
Expand All @@ -121,10 +125,12 @@ Finally, any settings that can be configured via `appsettings.json` or environme
})
```

```fsharp {"onboardingOptions": {"performance": "3"}}
```fsharp
.UseSentry (fun options ->
options.SendDefaultPii <- true // Adds request URL and headers, IP and name for users, etc.
// ___PRODUCT_OPTION_START___ performance
options.TracesSampleRate <- 1.0 // Set this to configure automatic tracing
// ___PRODUCT_OPTION_END___ performance
options.SetBeforeSend(fun event hint ->
// Never report server names
event.ServerName <- null
Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/aws-lambda/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ All `ASP.NET Core` configurations are valid here. But one configuration in parti
`FlushOnCompletedRequest` ensures all events are flushed out. This is because the general ASP.NET Core hooks for when the process is exiting are not guaranteed to run in a serverless environment. This setting ensures that no event is lost if AWS recycles the process.


```csharp {"onboardingOptions": {"performance": "14-17"}}
```csharp
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
Expand All @@ -49,10 +49,12 @@ public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFu
o.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
o.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
o.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
// Required in Serverless environments
options.FlushOnCompletedRequest = true;
})
Expand Down
8 changes: 6 additions & 2 deletions docs/platforms/dotnet/guides/azure-functions-worker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This package extends [Sentry.Extensions.Logging](/platforms/dotnet/guides/extens

Sentry integration with Azure Functions is done by calling `.UseSentry()` and specifying the options, for example:

```csharp {"onboardingOptions": {"performance": "12-14"}}
```csharp
using Sentry.Azure.Functions.Worker;

var builder = FunctionsApplication.CreateBuilder(args);
Expand All @@ -45,9 +45,11 @@ builder.UseSentry(options =>
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
});

builder.Build().Run();
Expand All @@ -59,7 +61,7 @@ If using the ASP.NET Core integration add `UseSentry` to the `ConfigureFunctions

</Alert>

```csharp {"onboardingOptions": {"performance": "13-15"}}
```csharp
using Sentry.Azure.Functions.Worker;

var host = new HostBuilder()
Expand All @@ -72,9 +74,11 @@ var host = new HostBuilder()
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
});
})
.Build();
Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/blazor-webassembly/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sentry integration with Blazor WebAssembly is done by calling `.UseSentry()` and



```csharp {"onboardingOptions": {"performance": "9"}}
```csharp
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.UseSentry(options =>
{
Expand All @@ -37,7 +37,9 @@ builder.UseSentry(options =>
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
options.TracesSampleRate = 0.1;
// ___PRODUCT_OPTION_END___ performance
});

// Captures logError and higher as events
Expand Down
6 changes: 5 additions & 1 deletion docs/platforms/dotnet/guides/entityframework/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Add the Entity Framework 6 support to your project in one step:

For example, configuring an ASP.NET app with _global.asax_:

```csharp {filename:global.asax} {"onboardingOptions": {"performance": "17-19, 28-37"}}
```csharp {filename:global.asax}
using System;
using System.Configuration;
using Sentry.AspNet;
Expand All @@ -62,9 +62,11 @@ public class MvcApplication : System.Web.HttpApplication
options.Dsn = ConfigurationManager.AppSettings["SentryDsn"];
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
// Add the EntityFramework integration
options.AddEntityFramework();
});
Expand All @@ -73,6 +75,7 @@ public class MvcApplication : System.Web.HttpApplication
// Global error catcher
protected void Application_Error() => Server.CaptureLastError();

// ___PRODUCT_OPTION_START___ performance
protected void Application_BeginRequest()
{
Context.StartSentryTransaction();
Expand All @@ -83,6 +86,7 @@ public class MvcApplication : System.Web.HttpApplication
Context.FinishSentryTransaction();
}

// ___PRODUCT_OPTION_END___ performance
public override void Dispose()
{
_sentrySdk.Dispose();
Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/maui/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This package extends [Sentry.Extensions.Logging](/platforms/dotnet/guides/extens
In your `MauiProgram.cs` file, call `UseSentry` on your `MauiAppBuilder`, and include any options you would like to set. The `Dsn` is the only required parameter.


```csharp {"onboardingOptions": {"performance": "22-25"}}
```csharp
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
Expand All @@ -67,9 +67,11 @@ public static MauiApp CreateMauiApp()
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;

// ___PRODUCT_OPTION_START___ performance
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance

// Other Sentry options can be set here.
})
Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/uwp/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The SDK should be initialized in the constructor of your application class (usua
</Alert>


```csharp {"onboardingOptions": {"performance": "20-23"}}
```csharp
using Sentry.Protocol;
using UnhandledExceptionEventArgs = Windows.UI.Xaml.UnhandledExceptionEventArgs;

Expand All @@ -48,10 +48,12 @@ sealed partial class App : Application
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;

// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;

// ___PRODUCT_OPTION_END___ performance
// Enable Global Mode since this is a client app.
options.IsGlobalModeEnabled = true;

Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/winforms/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You should also set `Application.SetUnhandledExceptionMode(UnhandledExceptionMod
A complete example of the recommended startup is as follows:


```csharp {"onboardingOptions": {"performance": "34-37"}}
```csharp
using System;
using System.Windows.Forms;

Expand Down Expand Up @@ -64,10 +64,12 @@ namespace WindowsFormsApp1
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;

// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
TracesSampleRate = 1.0,

// ___PRODUCT_OPTION_END___ performance
// Enable Global Mode since this is a client app
IsGlobalModeEnabled = true,

Expand Down
8 changes: 6 additions & 2 deletions docs/platforms/dotnet/guides/winui/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In addition to capturing errors, you can monitor interactions between multiple s

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

```csharp {"onboardingOptions": {"performance": "19-22"}}
```csharp
using Sentry.Protocol;

sealed partial class App : Application
Expand All @@ -50,10 +50,12 @@ sealed partial class App : Application

// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance

// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance

// Enable Global Mode since this is a client app.
options.IsGlobalModeEnabled = true;
Expand All @@ -80,7 +82,7 @@ Do not initialize the SDK in the `OnLaunched` event of the application or the `H
</Alert>


```csharp {"onboardingOptions": {"performance": "21-24"}}
```csharp
// Add these to your existing using statements.
using Sentry.Protocol;
using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;
Expand All @@ -100,10 +102,12 @@ sealed partial class App : Application

// Adds request URL and headers, IP and name for users, etc.
o.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance

// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
o.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance

// Enable Global Mode since this is a client app.
o.IsGlobalModeEnabled = true;
Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/wpf/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The SDK should be initialized in the constructor of your application class (usua
The SDK automatically handles `AppDomain.UnhandledException`. On WPF, for production apps (when no debugger is attached), WPF catches exception to show the dialog to the user. You can also configure your app to capture those exceptions before the dialog shows up:


```csharp {"onboardingOptions": {"performance": "18-21"}}
```csharp
using System.Windows;

public partial class App : Application
Expand All @@ -48,10 +48,12 @@ public partial class App : Application
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;

// ___PRODUCT_OPTION_START___ performance
// Set traces_sample_rate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;

// ___PRODUCT_OPTION_END___ performance
// Enable Global Mode since this is a client app
options.IsGlobalModeEnabled = true;

Expand Down
4 changes: 3 additions & 1 deletion docs/platforms/dotnet/guides/xamarin/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ After you’ve completed setting up a project in Sentry, Sentry will give you a
You should initialize the SDK as early as possible, for an example, the start of OnCreate
on MainActivity for Android, and, the top of FinishedLaunching on AppDelegate for iOS).

```csharp {"onboardingOptions": {"performance": "10-13"}}
```csharp
SentryXamarin.Init(options =>
{
options.AddXamarinFormsIntegration();
Expand All @@ -36,10 +36,12 @@ SentryXamarin.Init(options =>
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// Set TracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
options.TracesSampleRate = 1.0;
// ___PRODUCT_OPTION_END___ performance
});
// App code

Expand Down
6 changes: 5 additions & 1 deletion docs/platforms/dotnet/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,21 @@ Install the **NuGet** package to add the Sentry dependency:
To capture all errors, even the one during the startup of your application, you should initialize the Sentry .NET SDK as soon as possible.


```csharp {"onboardingOptions": {"performance": "7-8", "profiling": "9-10"}}
```csharp
SentrySdk.Init(options =>
{
options.Dsn = "https://[email protected]/5428537";
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
options.SendDefaultPii = true;
// ___PRODUCT_OPTION_START___ performance
// A fixed sample rate of 1.0 - 100% of all transactions are getting sent
options.TracesSampleRate = 1.0f;
// ___PRODUCT_OPTION_END___ performance
// ___PRODUCT_OPTION_START___ profiling
// A sample rate for profiling - this is relative to TracesSampleRate
options.ProfilesSampleRate = 1.0f;
// ___PRODUCT_OPTION_END___ profiling
});
```

Expand Down