Skip to content
Open
Changes from all 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
92 changes: 48 additions & 44 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,76 @@ 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.extensions.logging') }}
// ___PRODUCT_OPTION_START___ performance
dotnet add package Sentry.OpenTelemetry -v {{@inject packages.version('sentry.dotnet.opentelemetry') }}
Comment on lines +22 to +24
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renders fine in the preview. I don't see any reason to change this.

dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.Http

// ___PRODUCT_OPTION_END___
```

```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.extensions.logging') }}
// ___PRODUCT_OPTION_START___ performance
Install-Package Sentry.OpenTelemetry -Version {{@inject packages.version('sentry.dotnet.opentelemetry') }}
// ___PRODUCT_OPTION_END___
```

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>
<OnboardingOption optionId="performance">
Performance tracing can be enabled by adding Sentry to the OpenTelemetry `TracerProviderBuilder` and then configuring Sentry itself to use OpenTelemetry.
</OnboardingOption>

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

</Alert>
For example:

```csharp
using Sentry.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
// ___PRODUCT_OPTION_START___ performance
using OpenTelemetry.Trace;
// ___PRODUCT_OPTION_END___
using Sentry.OpenTelemetry;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((host, builder) =>
.ConfigureFunctionsWorkerDefaults()
// ___PRODUCT_OPTION_START___ performance
.ConfigureServices(services =>
{
services.AddOpenTelemetry().WithTracing(builder =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do we need to add a PackageReference to OpenTelemetry.Extensions.Hosting to the Install section?

Or at least mention it in a comment?

services.AddOpenTelemetry().WithTracing(builder => // from OpenTelemetry.Extensions.Hosting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the OpenTelemetry packages... not the AzureFunctions ones as I think it's implicit folks have those already for an AF application.

{
builder
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
.AddHttpClientInstrumentation(); // From OpenTelemetry.Instrumentation.Http, instruments outgoing HTTP requests
});
})
// ___PRODUCT_OPTION_END___
.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
// ___PRODUCT_OPTION_END___
options.Debug = true;
});
})
.Build();


await host.RunAsync();
```

Expand All @@ -93,4 +97,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