-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Update Azure Functions guide to use OpenTelemetry #15568
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
base: master
Are you sure you want to change the base?
Changes from all commits
dabbc14
0c483be
a643560
9501fb4
5260cbe
d8c453e
bcc7182
a4c305b
de444e3
a1c555e
09817f7
2dfc79b
6366d67
ba078d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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') }} | ||
| dotnet add package OpenTelemetry | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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') }} | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ___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; | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var host = new HostBuilder() | ||
| .ConfigureFunctionsWorkerDefaults((host, builder) => | ||
| .ConfigureFunctionsWorkerDefaults() | ||
| // ___PRODUCT_OPTION_START___ performance | ||
| .ConfigureServices(services => | ||
| { | ||
| services.AddOpenTelemetry().WithTracing(builder => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Do we need to add a Or at least mention it in a comment? services.AddOpenTelemetry().WithTracing(builder => // from OpenTelemetry.Extensions.Hosting
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }) | ||
| // ___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; | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| }) | ||
| .Build(); | ||
|
|
||
|
|
||
| await host.RunAsync(); | ||
| ``` | ||
|
|
||
|
|
@@ -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#**) | ||
There was a problem hiding this comment.
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.