Skip to content
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

feat: dotnet profiling docs #8862

Merged
merged 10 commits into from
Jan 23, 2024
1 change: 1 addition & 0 deletions src/docs/product/profiling/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Profiling depends on Sentry's performance monitoring product being enabled befor
- [React Native](/platforms/react-native/profiling/) [beta]
- [Flutter](/platforms/flutter/profiling/) [experimental, iOS and macOS only]
vaind marked this conversation as resolved.
Show resolved Hide resolved
- Standalone and server apps
- [.NET](/platforms/dotnet/profiling/) [experimental]
- [Node.js](/platforms/node/profiling/)
- [Python](/platforms/python/profiling/)
- [PHP](/platforms/php/profiling/)
Expand Down
1 change: 1 addition & 0 deletions src/docs/product/profiling/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description: "Profiling offers a deeper level of visibility on top of traditiona
- [iOS (Swift and Objective-C only)](/platforms/apple/profiling/)
- [Flutter [experimental, iOS and macOS only]](/platforms/flutter/profiling/)
- [Python](/platforms/python/profiling/)
- [.NET [experimental]](/platforms/dotnet/profiling/)
- [Node.js](/platforms/node/profiling/)
- [PHP (including Laravel and Symfony)](/platforms/php/profiling/)
- [Browser JavaScript [beta]](/platforms/javascript/profiling/)
Expand Down
69 changes: 69 additions & 0 deletions src/platforms/dotnet/profiling/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: Set Up Profiling
description: "Learn how to enable profiling in your app if it is not already set up."
sidebar_order: 5000
---

<PlatformContent includePath="profiling/index/preface" />

With [profiling](/product/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.

<Note>

.NET profiling alpha is available .NET 6.0+ (tested on .NET 7.0 & .NET 8.0 as well) for:
vaind marked this conversation as resolved.
Show resolved Hide resolved
- Windows
- Linux
- macOS
- iOS
- macCatalyst
vaind marked this conversation as resolved.
Show resolved Hide resolved

</Note>

## Enable Profiling

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.
vaind marked this conversation as resolved.
Show resolved Hide resolved

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

```csharp {tabTitle:iOS/macCatalyst}
vaind marked this conversation as resolved.
Show resolved Hide resolved
using Sentry;

SentrySdk.Init(options =>
vaind marked this conversation as resolved.
Show resolved Hide resolved
{
// ... 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. 1.0 is 100%
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, i.e. 2 % of all transactions.
options.ProfilesSampleRate = 0.2;
});
```

```csharp {tabTitle:Windows/Linux/macOS}
using Sentry;

vaind marked this conversation as resolved.
Show resolved Hide resolved
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.
options.TracesSampleRate = 0.1;
vaind marked this conversation as resolved.
Show resolved Hide resolved
vaind marked this conversation as resolved.
Show resolved Hide resolved

// Sample rate for profiling, applied on top of othe TracesSampleRate,
// e.g. 0.2 means we want to profile 20 % of the captured transactions, i.e. 2 % of all transactions.
options.ProfilesSampleRate = 0.2;

// Requires NuGet package: Sentry.Profiling
// Note: by default, the profiler is initialized asynchronously, this can be tuned by passing an desired initialization timeout to the constructor.
options.AddIntegration(new ProfilingIntegration());
vaind marked this conversation as resolved.
Show resolved Hide resolved
});
```

###

Check out the <PlatformLink to="/performance/">performance setup documentation</PlatformLink> 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.
27 changes: 27 additions & 0 deletions src/platforms/dotnet/profiling/troubleshooting/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Troubleshooting
description: "Learn how to troubleshoot your profiling setup."
sidebar_order: 5000
---

### Profiles are not showing up

If you don't see any profiling data in [sentry.io](https://sentry.io), you can try the following:

- Ensure that performance monitoring <PlatformLink to="/performance/">is enabled</PlatformLink>.
- Ensure that the automatic instrumentation is sending performance data to Sentry by going to the **Performance** page in [sentry.io](https://sentry.io).
- If the automatic instrumentation is not sending performance data, try using <PlatformLink to="/performance/instrumentation/custom-instrumentation">custom instrumentation</PlatformLink>.
- Enable <PlatformLink to="/configuration/options/#debug">debug mode</PlatformLink> in the SDK and check the logs.
- If the transactions happen too soon after `Sentry.Init()`, they may not be captured yet.
This is because the `ProfilingIntegration()` from `Sentry.Profiling` NuGet package initializes asynchronously by default.
If you'd like to initialize it synchronously, set the desired timeout constructor argument.
vaind marked this conversation as resolved.
Show resolved Hide resolved
Note: this doesn't apply to iOS/macCatalyst whic use native profiling and are initialized synchronously.
vaind marked this conversation as resolved.
Show resolved Hide resolved
- Maybe you're trying to capture profiles on a platform that is currently **not** supported, notably:
- .NET Framework; we only support .NET 6.0, .NET 7.0 and .NET 8.0
- NativeAOT - this is only supported for iOS and macCatalyst (alongside MonoAOT)
vaind marked this conversation as resolved.
Show resolved Hide resolved
- Android - currently not supported at all

### `Unknown` frames

Some frames will show up as `unknown` in the UI. This is because the SDK does not have information about the stack frame.
Usually, these are anonymous helper JIT-generated methods and present among `System` stack frames.
11 changes: 11 additions & 0 deletions src/wizard/dotnet/profiling-onboarding/dotnet/0.alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: .NET
doc_link: https://docs.sentry.io/platforms/dotnet/profiling/
support_level: alpha
type: language
---

<div class='alert warning'>
Profiling in .NET is currently available in alpha for .NET 6.0+ on Windows, Linux, macOS, iOS and macCatalyst.
vaind marked this conversation as resolved.
Show resolved Hide resolved
There may be some bugs. We recognize the irony.
</div>
11 changes: 11 additions & 0 deletions src/wizard/dotnet/profiling-onboarding/dotnet/1.install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: .NET
doc_link: https://docs.sentry.io/platforms/dotnet/profiling/
support_level: alpha
type: language
---

#### Install

For the Profiling integration to work, you must use the `Sentry` and `Sentry.Profiling` NuGet packages (minimum version v4.0.0) and Sentry.
Learn more about installation methods in our [full documentation](https://docs.sentry.io/platforms/dotnet/#install).
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: .NET
doc_link: https://docs.sentry.io/platforms/dotnet/profiling/
support_level: alpha
type: language
---

#### Configure Performance

Sentry’s performance monitoring product has to be enabled in order for Profiling to work. To enable performance monitoring in the SDK:

```csharp
using Sentry;

vaind marked this conversation as resolved.
Show resolved Hide resolved
SentrySdk.Init(options =>
{
// A Sentry Data Source Name (DSN) is required.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
options.Dsn = "___PUBLIC_DSN___";

// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
// This might be helpful, or might interfere with the normal operation of your application.
// We enable it here for demonstration purposes when first trying Sentry.
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
options.Debug = true;

// This option is recommended. It enables Sentry's "Release Health" feature.
options.AutoSessionTracking = true;

// This option will enable Sentry's tracing features. You still need to start transactions and spans.
options.EnableTracing = true;
vaind marked this conversation as resolved.
Show resolved Hide resolved

// We recommend adjusting this value in production:
options.TracesSampleRate = 1.0;
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: .NET
doc_link: https://docs.sentry.io/platforms/dotnet/profiling/
support_level: alpha
type: language
---

#### Configure Profiling

Add the `ProfilesSampleRate` option to your SDK config.

```csharp
using Sentry;

vaind marked this conversation as resolved.
Show resolved Hide resolved
SentrySdk.Init(options =>
{
// A Sentry Data Source Name (DSN) is required.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
options.Dsn = "___PUBLIC_DSN___";

// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
// This might be helpful, or might interfere with the normal operation of your application.
// We enable it here for demonstration purposes when first trying Sentry.
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
options.Debug = true;

// This option is recommended. It enables Sentry's "Release Health" feature.
options.AutoSessionTracking = true;

// This option will enable Sentry's tracing features. You still need to start transactions and spans.
options.EnableTracing = true;
vaind marked this conversation as resolved.
Show resolved Hide resolved

// We recommend adjusting this value in production:
options.TracesSampleRate = 1.0;

// The sampling rate for profiling is relative to TracesSampleRate.
// Setting to 1.0 will profile 100% of sampled transactions.
// We recommend adjusting this value in production:
options.ProfilesSampleRate = 1.0;

// Windows, Linux and macOS profiling requires NuGet package: Sentry.Profiling
// Note: by default, the profiler is initialized asynchronously, this can be tuned by passing an desired initialization timeout to the constructor.
options.AddIntegration(new ProfilingIntegration());
});
```
Loading