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
2 changes: 2 additions & 0 deletions src/docs/product/profiling/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Profiling depends on Sentry's performance monitoring product being enabled befor
- [iOS](/platforms/apple/guides/ios/profiling/)
- [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
- [.NET](/platforms/dotnet/profiling/) [experimental, iOS only]
- 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
77 changes: 77 additions & 0 deletions src/platforms/dotnet/profiling/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
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>

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

</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

```shell {tabTitle:.NET CLI}
dotnet add package Sentry.Profiling -v {{@inject packages.version('sentry.dotnet', '4.0.0-beta.8') }}
```

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}
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.
// 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;
});
```

```csharp {tabTitle:Windows/Linux/macOS}
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;

// 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(
// During startup, wait up to 500ms to profile the app startup code. This could make launching the app a bit slower so comment it out if your prefer profiling to start asynchronously
TimeSpan.FromMilliseconds(500)
));
});
```

###

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, e.g. `new ProfilingIntegration(TimeSpan.FromMilliseconds(500))` to wait up to 500 ms for the profiler to start up.
Note: this doesn't apply to iOS and Mac Catalyst which use native profiling and are initialized synchronously.
- 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
- Native AOT - this is only supported for iOS and Mac Catalyst (alongside the standard Mono AOT)
- 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 Mac Catalyst.
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,23 @@
---
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
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___";

// We recommend adjusting this value in production:
options.TracesSampleRate = 1.0;
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
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
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___";

// 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