Skip to content
Open
Changes from 4 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
70 changes: 25 additions & 45 deletions docs/platforms/dotnet/guides/azure-functions-worker/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ sdk: sentry.dotnet.azure.functions.worker
description: "Learn about Sentry's .NET integration with Azure Functions."
---

Sentry provides an integration with Azure Functions through the [Sentry.Azure.Functions.Worker NuGet package](https://www.nuget.org/packages/Sentry.Azure.Functions.Worker).
All triggers are supported.
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.

## Features

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

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

Add the Sentry dependency to your Azure Functions application:
Add the Sentry dependencies to your Azure Functions application:

```shell {tabTitle:.NET Core CLI}
dotnet add package Sentry.Azure.Functions.Worker -v {{@inject packages.version('sentry.dotnet.azure.functions.worker') }}
dotnet add package Sentry.Extensions.Logging -v {{@inject packages.version('sentry.dotnet') }}
dotnet add package Sentry.OpenTelemetry -v {{@inject packages.version('sentry.dotnet') }}
```

```powershell {tabTitle:Package Manager}
Install-Package Sentry.Azure.Functions.Worker -Version {{@inject packages.version('sentry.dotnet.azure.functions.worker') }}
Install-Package Sentry.Extensions.Logging -Version {{@inject packages.version('sentry.dotnet') }}
Install-Package Sentry.OpenTelemetry -Version {{@inject packages.version('sentry.dotnet') }}
```

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

## Configure

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

```csharp
using Sentry.Azure.Functions.Worker;

var builder = FunctionsApplication.CreateBuilder(args);

builder.UseSentry(options =>
{
options.Dsn = "___PUBLIC_DSN___";
// When configuring for the first time, to see what the SDK is doing:
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();
```

<Alert>
Performance tracing can be enabled by adding Sentry to the OpenTelemetry `TraceProviderBuilder` and then configuring Sentry itself to use OpenTelemetry.

If using the ASP.NET Core integration add `UseSentry` to the `ConfigureFunctionsWebApplication` call instead.

</Alert>
For example:

```csharp
using Sentry.Azure.Functions.Worker;
using Sentry.OpenTelemetry;

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
.AddHttpClientInstrumentation() // From OpenTelemetry.Instrumentation.Http... adds automatic tracing for outgoing HTTP requests
.Build();

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((host, builder) =>
.ConfigureFunctionsWorkerDefaults()
.ConfigureLogging(logging =>
{
builder.UseSentry(host, options =>
logging.AddSentry(options =>
{
options.Dsn = "___PUBLIC_DSN___";
// When configuring for the first time, to see what the SDK is doing:
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
options.UseOpenTelemetry(); // <-- Configure Sentry to use open telemetry
options.DisableSentryHttpMessageHandler = true; // So Sentry doesn't also create spans for outbound HTTP requests
options.Debug = true;
});
})
.Build();


await host.RunAsync();
```

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

## Samples

- [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#**)
- [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#**)
Loading