Set Up Profiling

Learn how to enable profiling in your app if it is not already set up.

With profiling, Sentry allows you to collect and analyze performance profiles from real user devices in production to give you a complete picture of how your application performs in a variety of environments.

Sentry profiling for .NET is available in Alpha on .NET 6.0+ (tested on .NET 7.0 & .NET 8.0 as well) for:

  • Windows
  • Linux
  • macOS
  • iOS
  • Mac Catalyst

To enable profiling, set the ProfilesSampleRate. Additionally, for all platforms except iOS/Mac Catalyst, you need to add a dependency on the Sentry.Profiling NuGet package.

Copied
dotnet add package Sentry.Profiling

Profiling depends on Sentry’s tracing product being enabled beforehand. To enable tracing in the SDK, set the TracesSampleRate option to the desired value.

Copied
SentrySdk.Init(options =>
{
    // ... usual setup options omitted for clarity (see Getting Started) ...

    // Sample rate for your transactions, e.g. value 0.1 means we want to report 10% of transactions.
    // Setting 1.0 means all transactions are profiled.
    // We recommend adjusting this value in production.
    options.TracesSampleRate = 1.0;

    // Sample rate for profiling, applied on top of othe TracesSampleRate,
    // e.g. 0.2 means we want to profile 20 % of the captured transactions.
    // We recommend adjusting this value in production.
    options.ProfilesSampleRate = 1.0;

    // Attach the profiling integration.
    options.AddProfilingIntegration();

    // On Windows, Linux, and macOS, the profiler is initialized asynchronously by default.
    // Alternatively, you can switch to synchronous initialization by adding a timeout argument.
    // The SDK waits up to the specified timeout for the .NET runtime profiler to start up before continuing.
    // e.g. options.AddProfilingIntegration(TimeSpan.FromMilliseconds(500));
    // Note: the timeout has no effect on iOS and MacCatalyst, which use native profiling and always start synchronously.
});

Check out the tracing setup documentation for more detailed information on how to configure sampling. Setting the traces sample rate to 1.0 means all transactions will be captured. Setting the profiles sample rate to 1.0 means all captured transactions will be profiled.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").