Skip to content

Commit e4de7d8

Browse files
Update Azure Functions guide to use OpenTelemetry (#15568)
## DESCRIBE YOUR PR Resolves getsentry/sentry-dotnet#4726 See also: - getsentry/sentry-dotnet#4763 - getsentry/sentry-dotnet#4786 ## IS YOUR CHANGE URGENT? - [ ] Other deadline: Can be released any time before the version 6 release ## SLA cc: @Flash0ver ## PRE-MERGE CHECKLIST - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent a370bb5 commit e4de7d8

File tree

1 file changed

+48
-44
lines changed
  • docs/platforms/dotnet/guides/azure-functions-worker

1 file changed

+48
-44
lines changed

docs/platforms/dotnet/guides/azure-functions-worker/index.mdx

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ sdk: sentry.dotnet.azure.functions.worker
44
description: "Learn about Sentry's .NET integration with Azure Functions."
55
---
66

7-
Sentry provides an integration with Azure Functions through the [Sentry.Azure.Functions.Worker NuGet package](https://www.nuget.org/packages/Sentry.Azure.Functions.Worker).
8-
All triggers are supported.
7+
Sentry provides an integration with Azure Functions through the [Sentry.Extensions.Logging](https://www.nuget.org/packages/Sentry.Extensions.Logging) and [Sentry.OpenTelemetry](https://www.nuget.org/packages/Sentry.OpenTelemetry) NuGet packages.
98

109
## Features
1110

@@ -17,71 +16,76 @@ Select which Sentry features you'd like to install in addition to Error Monitori
1716

1817
<OnboardingOptionButtons options={['error-monitoring', 'performance']}/>
1918

20-
Add the Sentry dependency to your Azure Functions application:
19+
Add the Sentry dependencies to your Azure Functions application:
2120

2221
```shell {tabTitle:.NET Core CLI}
23-
dotnet add package Sentry.Azure.Functions.Worker -v {{@inject packages.version('sentry.dotnet.azure.functions.worker') }}
22+
dotnet add package Sentry.Extensions.Logging -v {{@inject packages.version('sentry.dotnet.extensions.logging') }}
23+
// ___PRODUCT_OPTION_START___ performance
24+
dotnet add package Sentry.OpenTelemetry -v {{@inject packages.version('sentry.dotnet.opentelemetry') }}
25+
dotnet add package OpenTelemetry
26+
dotnet add package OpenTelemetry.Extensions.Hosting
27+
dotnet add package OpenTelemetry.Instrumentation.Http
28+
29+
// ___PRODUCT_OPTION_END___
2430
```
2531

2632
```powershell {tabTitle:Package Manager}
27-
Install-Package Sentry.Azure.Functions.Worker -Version {{@inject packages.version('sentry.dotnet.azure.functions.worker') }}
33+
Install-Package Sentry.Extensions.Logging -Version {{@inject packages.version('sentry.dotnet.extensions.logging') }}
34+
// ___PRODUCT_OPTION_START___ performance
35+
Install-Package Sentry.OpenTelemetry -Version {{@inject packages.version('sentry.dotnet.opentelemetry') }}
36+
// ___PRODUCT_OPTION_END___
2837
```
2938

30-
This package extends [Sentry.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/). This means that besides the Azure Functions related features, through this package you'll also get access to the `ILogger<T>` integration and also the features available in the main [Sentry](/platforms/dotnet/) SDK.
39+
The [Sentry.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/) package also provides access to the `ILogger<T>` integration and the other core features available in the [Sentry](/platforms/dotnet/) SDK.
3140

3241
## Configure
3342

34-
Sentry integration with Azure Functions is done by calling `.UseSentry()` and specifying the options, for example:
43+
The core features of Sentry are enabled by calling `AddSentry` when configuring logging.
3544

36-
```csharp
37-
using Sentry.Azure.Functions.Worker;
38-
39-
var builder = FunctionsApplication.CreateBuilder(args);
40-
41-
builder.UseSentry(options =>
42-
{
43-
options.Dsn = "___PUBLIC_DSN___";
44-
// When configuring for the first time, to see what the SDK is doing:
45-
options.Debug = true;
46-
// Adds request URL and headers, IP and name for users, etc.
47-
options.SendDefaultPii = true;
48-
// ___PRODUCT_OPTION_START___ performance
49-
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
50-
// We recommend adjusting this value in production.
51-
options.TracesSampleRate = 1.0;
52-
// ___PRODUCT_OPTION_END___ performance
53-
});
54-
55-
builder.Build().Run();
56-
```
57-
58-
<Alert>
45+
<OnboardingOption optionId="performance">
46+
Performance tracing can be enabled by adding Sentry to the OpenTelemetry `TracerProviderBuilder` and then configuring Sentry itself to use OpenTelemetry.
47+
</OnboardingOption>
5948

60-
If using the ASP.NET Core integration add `UseSentry` to the `ConfigureFunctionsWebApplication` call instead.
61-
62-
</Alert>
49+
For example:
6350

6451
```csharp
65-
using Sentry.Azure.Functions.Worker;
52+
using Microsoft.Extensions.Hosting;
53+
using Microsoft.Extensions.Logging;
54+
using OpenTelemetry;
55+
// ___PRODUCT_OPTION_START___ performance
56+
using OpenTelemetry.Trace;
57+
// ___PRODUCT_OPTION_END___
58+
using Sentry.OpenTelemetry;
6659

6760
var host = new HostBuilder()
68-
.ConfigureFunctionsWorkerDefaults((host, builder) =>
61+
.ConfigureFunctionsWorkerDefaults()
62+
// ___PRODUCT_OPTION_START___ performance
63+
.ConfigureServices(services =>
64+
{
65+
services.AddOpenTelemetry().WithTracing(builder =>
66+
{
67+
builder
68+
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
69+
.AddHttpClientInstrumentation(); // From OpenTelemetry.Instrumentation.Http, instruments outgoing HTTP requests
70+
});
71+
})
72+
// ___PRODUCT_OPTION_END___
73+
.ConfigureLogging(logging =>
6974
{
70-
builder.UseSentry(host, options =>
75+
logging.AddSentry(options =>
7176
{
7277
options.Dsn = "___PUBLIC_DSN___";
73-
// When configuring for the first time, to see what the SDK is doing:
74-
options.Debug = true;
75-
// Adds request URL and headers, IP and name for users, etc.
76-
options.SendDefaultPii = true;
7778
// ___PRODUCT_OPTION_START___ performance
78-
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
79-
// We recommend adjusting this value in production.
8079
options.TracesSampleRate = 1.0;
81-
// ___PRODUCT_OPTION_END___ performance
80+
options.UseOpenTelemetry(); // <-- Configure Sentry to use open telemetry
81+
options.DisableSentryHttpMessageHandler = true; // So Sentry doesn't also create spans for outbound HTTP requests
82+
// ___PRODUCT_OPTION_END___
83+
options.Debug = true;
8284
});
8385
})
8486
.Build();
87+
88+
8589
await host.RunAsync();
8690
```
8791

@@ -93,4 +97,4 @@ This snippet includes an intentional error, so you can test that everything is w
9397

9498
## Samples
9599

96-
- [Integration with Azure Functions](https://github.com/getsentry/sentry-dotnet/tree/main/src/Sentry.Azure.Functions.Worker) sample demonstrates Sentry with Azure Functions Isolated Worker SDK. (**C#**)
100+
- [Azure Functions Sample](https://github.com/getsentry/sentry-dotnet/blob/main/samples/Sentry.Samples.OpenTelemetry.AzureFunctions/) demonstrates Sentry with Azure Functions Isolated Worker SDK. (**C#**)

0 commit comments

Comments
 (0)