diff --git a/content/en/serverless/azure_functions/_index.md b/content/en/serverless/azure_functions/_index.md index 9a84bd3fa529d..60f1d94c62194 100644 --- a/content/en/serverless/azure_functions/_index.md +++ b/content/en/serverless/azure_functions/_index.md @@ -3,11 +3,11 @@ title: Install Serverless Monitoring for Azure Functions --- ## Overview -This page explains how to collect traces, trace metrics, runtime metrics, and custom metrics from your Azure Functions. To collect additional metrics, install the [Datadog Azure integration][6]. +This page explains how to collect traces, trace metrics, runtime metrics, and custom metrics from your Azure Functions. To collect additional metrics, install the [Datadog Azure integration][5]. ## Setup -{{< programming-lang-wrapper langs="nodejs,python,java" >}} +{{< programming-lang-wrapper langs="nodejs,python,java,dotnet" >}} {{< programming-lang lang="nodejs" >}} 1. **Install dependencies**. Run the following commands: ```shell @@ -15,11 +15,9 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu npm install dd-trace ``` - To use [automatic instrumentation][1], you must use `dd-trace` v5.25+. - Datadog recommends pinning the package versions and regularly upgrading to the latest versions of both `@datadog/serverless-compat` and `dd-trace` to ensure you have access to enhancements and bug fixes. -2. **Start the Datadog serverless compatibility layer and initialize the Node.js tracer**. Add the following lines to your main application entry point file (for example, `app.js`): +2. **Start the Datadog Serverless Compatibility Layer and initialize the Datadog Node.js tracer**. Add the following lines to your main application entry point file (for example, `app.js`): ```js require('@datadog/serverless-compat').start(); @@ -28,13 +26,11 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu const tracer = require('dd-trace').init() ``` -3. (Optional) **Enable runtime metrics**. See [Node.js Runtime Metrics][2]. +3. **Configure the Datadog Node.js tracer** -4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3]. + [Configuring the Node.js Tracing Library][1] -[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation -[2]: /tracing/metrics/runtime_metrics/nodejs/?tab=environmentvariables -[3]: /metrics/custom_metrics/dogstatsd_metrics_submission/?code-lang=nodejs +[1]:/tracing/trace_collection/library_config/nodejs {{< /programming-lang >}} {{< programming-lang lang="python" >}} 1. **Install dependencies**. Run the following commands: @@ -43,11 +39,9 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu pip install ddtrace ``` - To use [automatic instrumentation][1], you must use `dd-trace` v2.19+. - Datadog recommends using the latest versions of both `datadog-serverless-compat` and `ddtrace` to ensure you have access to enhancements and bug fixes. -2. **Initialize the Datadog Python tracer and serverless compatibility layer**. Add the following lines to your main application entry point file: +2. **Start the Datadog Serverless Compatibility Layer and initialize the Datadog Python tracer**. Add the following lines to your main application entry point file: ```python from datadog_serverless_compat import start @@ -56,13 +50,11 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu start() ``` -3. (Optional) **Enable runtime metrics**. See [Python Runtime Metrics][2]. +3. **Configure the Datadog Python tracer** -4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3]. + [Configuring the Python Tracing Library][1] -[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation -[2]: /tracing/metrics/runtime_metrics/python/ -[3]: /metrics/custom_metrics/dogstatsd_metrics_submission/?code-lang=python +[1]:/tracing/trace_collection/library_config/python {{< /programming-lang >}} {{< programming-lang lang="java" >}} 1. **Install dependencies**. Download the Datadog JARs and deploy them with your function: @@ -70,29 +62,103 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer' wget -O dd-serverless-compat-java-agent.jar 'https://dtdg.co/latest-serverless-compat-java-agent' ``` - See Datadog's [Maven Repository][4] for any specific version of the Datadog Serverless Compatibility Layer. - - To use [automatic instrumentation][1], you must use `dd-java-agent` v1.48.0+. + See Datadog's [Maven Repository][1] for any specific version of the Datadog Serverless Compatibility Layer. Datadog recommends regularly upgrading to the latest versions of both `dd-serverless-compat-java-agent` and `dd-java-agent` to ensure you have access to enhancements and bug fixes. -2. **Start the Datadog serverless compatibility layer and initialize the Java tracer**. Add the following `-javaagent` arguments to the JVM options.: +2. **Start the Datadog Serverless Compatibility Layer and initialize the Datadog Java tracer**. Add the following `-javaagent` arguments to the JVM options.: ```bash -javaagent:/path/to/dd-serverless-compat-java-agent.jar -javaagent:/path/to/dd-java-agent.jar ``` - **Note**: the environment variable to set JVM options depends on the hosting plan (example, Consumption, Elastic Premium, Dedicated). See [Azure Functions Java developer guide][5] for more details on the appropriate environment variable for your hosting plan. + **Note**: the environment variable to set JVM options depends on the hosting plan (example, Consumption, Elastic Premium, Dedicated). See [Azure Functions Java developer guide][2] for more details on the appropriate environment variable for your hosting plan. -3. (Optional) **Enable runtime metrics**. See [Java Runtime Metrics][2]. +3. **Configure the Datadog Java tracer** -4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3]. + [Configuring the Java Tracing Library][3] -[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation -[2]: /tracing/metrics/runtime_metrics/?tab=java#environment-variables -[3]: /metrics/custom_metrics/dogstatsd_metrics_submission/?code-lang=java -[4]: https://repo1.maven.org/maven2/com/datadoghq/dd-serverless-compat-java-agent/ -[5]: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#customize-jvm +[1]: https://repo1.maven.org/maven2/com/datadoghq/dd-serverless-compat-java-agent/ +[2]: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#customize-jvm +[3]: /tracing/trace_collection/library_config/java +{{< /programming-lang >}} +{{< programming-lang lang="dotnet" >}} +1. **Install dependencies**. Run the following commands: + ```shell + dotnet package add Datadog.Azure.Functions + ``` + + Datadog recommends regularly upgrading to the latest version of `Datadog.AzureFunctions` to ensure you have access to enhancements and bug fixes. + +2. **Start the Datadog Serverless Compatibility Layer**. + + If your Azure Function app uses the Isolated Worker model, add the following lines to your main application entry point file: + ```csharp + Datadog.Serverless.CompatibilityLayer.Start(); + ``` + + If your Azure Function app uses the In-Process model, add a NuGet package reference to `Microsoft.Azure.Functions.Extensions`: + ```shell + dotnet package add Microsoft.Azure.Functions.Extensions + ``` + + And add the following `.cs` file to your application: + ```csharp + using Datadog.Serverless; + using Microsoft.Azure.Functions.Extensions.DependencyInjection; + + [assembly: FunctionsStartup(typeof(MyFunctionApp.Startup))] + + namespace MyFunctionApp + { + public class Startup : FunctionsStartup + { + public override void Configure(IFunctionsHostBuilder builder) + { + Datadog.Serverless.CompatibilityLayer.Start(); + } + } + } + ``` + +3. **Configure Automatic Instrumentation** + + If your Azure Function app runs on Windows, add the following environment variables to your Function app: + ``` + CORECLR_ENABLE_PROFILING=1 + + CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} + + CORECLR_PROFILER_PATH_64= + C:\home\site\wwwroot\datadog\win-x64\Datadog.Trace.ClrProfiler.Native.dll + + CORECLR_PROFILER_PATH_32= + C:\home\site\wwwroot\datadog\win-x86\Datadog.Trace.ClrProfiler.Native.dll + + DD_DOTNET_TRACER_HOME=C:\home\site\wwwroot\datadog + + ``` + + If your Azure Function app runs on Linux, add the following environment variables to your Function app: + ``` + CORECLR_ENABLE_PROFILING=1 + + CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} + + CORECLR_PROFILER_PATH= + /home/site/wwwroot/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so + + DD_DOTNET_TRACER_HOME=/home/site/wwwroot/datadog + + ``` + +4. **Configure the Datadog .NET tracer** + + - [Configuring the .NET Core Tracing Library][1] + - [Configuring the .NET Framework Tracing Library][2] + +[1]:/tracing/trace_collection/library_config/dotnet-core +[2]:/tracing/trace_collection/library_config/dotnet-framework {{< /programming-lang >}} {{< /programming-lang-wrapper >}} @@ -105,50 +171,24 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu | `DD_API_KEY` | Your [Datadog API key][1]. | | `DD_SITE` | Your [Datadog site][2]. For example, {{< region-param key=dd_site code="true" >}}. | -7. **Configure Unified Service Tagging**. You can collect metrics from your Azure Functions by installing the [Datadog Azure integration][6]. To correlate these metrics with your traces, first set the `env`, `service`, and `version` tags on your resource in Azure. Then, configure the following environment variables. You can add custom tags as `DD_TAGS`. +7. **Configure Unified Service Tagging**. You can collect metrics from your Azure Functions by installing the [Datadog Azure integration][5]. To correlate these metrics with your traces, first set the `env`, `service`, and `version` tags on your resource in Azure. Then, configure the following environment variables. | Name | Value | | ---- | ----- | - | `DD_ENV` | How you want to tag your env for [Unified Service Tagging][9]. For example, `prod`. | - | `DD_SERVICE` | How you want to tag your service for [Unified Service Tagging][9]. | - | `DD_VERSION` | How you want to tag your version for [Unified Service Tagging][9]. | - | `DD_TAGS` | Your comma-separated custom tags. For example, `key1:value1,key2:value2`. | + | `DD_ENV` | How you want to tag your env for [Unified Service Tagging][7]. For example, `prod`. | + | `DD_SERVICE` | How you want to tag your service for [Unified Service Tagging][7]. | + | `DD_VERSION` | How you want to tag your version for [Unified Service Tagging][7]. | ## What's next? -- You can view your Azure Functions traces in [Trace Explorer][4]. Search for the service name you set in the `DD_SERVICE` environment variable to see your traces. -- You can use the [Serverless > Azure Functions][5] page to see your traces enriched with telemetry collected by the [Datadog Azure integration][6]. - -### Enable/disable trace metrics - -[Trace metrics][3] are enabled by default. To configure trace metrics, use the following environment variable: - -{{< programming-lang-wrapper langs="nodejs,python,java" >}} -{{< programming-lang lang="nodejs" >}} -`DD_TRACE_STATS_COMPUTATION_ENABLED` -: Enables (`true`) or disables (`false`) trace metrics. Defaults to `true`. - - **Values**: `true`, `false` -{{< /programming-lang >}} -{{< programming-lang lang="python" >}} -`DD_TRACE_STATS_COMPUTATION_ENABLED` -: Enables (`true`) or disables (`false`) trace metrics. Defaults to `true`. - - **Values**: `true`, `false` -{{< /programming-lang >}} -{{< programming-lang lang="java" >}} -`DD_TRACE_TRACER_METRICS_ENABLED` -: Enables (`true`) or disables (`false`) trace metrics. Defaults to `true`. - - **Values**: `true`, `false` -{{< /programming-lang >}} -{{< /programming-lang-wrapper >}} +- You can view your Azure Functions traces in [Trace Explorer][3]. Search for the service name you set in the `DD_SERVICE` environment variable to see your traces. +- You can use the [Serverless > Azure Functions][4] page to see your traces enriched with telemetry collected by the [Datadog Azure integration][5]. ## Troubleshooting ### Enable debug logs -You can collect [debug logs][7] for troubleshooting. To configure debug logs, use the following environment variables: +You can collect [debug logs][6] for troubleshooting. To configure debug logs, use the following environment variables: `DD_TRACE_DEBUG` : Enables (`true`) or disables (`false`) debug logging for the Datadog Tracing Library. Defaults to `false`. @@ -160,17 +200,10 @@ You can collect [debug logs][7] for troubleshooting. To configure debug logs, us **Values**: `trace`, `debug`, `info`, `warn`, `error`, `critical`, `off` -### Linux Consumption plans and GitHub Actions - -To use a GitHub Action to deploy to a Linux Consumption function, you must configure your workflow to use an Azure Service Principal for RBAC. See [Using Azure Service Principal for RBAC as Deployment Credential][8]. - - [1]: /account_management/api-app-keys/#add-an-api-key-or-client-token [2]: /getting_started/site -[3]: /tracing/metrics/metrics_namespace/ -[4]: https://app.datadoghq.com/apm/traces -[5]: https://app.datadoghq.com/functions?cloud=azure&entity_view=function -[6]: /integrations/azure/ -[7]: /tracing/troubleshooting/tracer_debug_logs/#enable-debug-mode -[8]: https://github.com/Azure/functions-action?tab=readme-ov-file#using-azure-service-principal-for-rbac-as-deployment-credential -[9]: /getting_started/tagging/unified_service_tagging/ \ No newline at end of file +[3]: https://app.datadoghq.com/apm/traces +[4]: https://app.datadoghq.com/functions?cloud=azure&entity_view=function +[5]: /integrations/azure/ +[6]: /tracing/troubleshooting/tracer_debug_logs/#enable-debug-mode +[7]: /getting_started/tagging/unified_service_tagging/