---
title: Install Serverless Monitoring for Azure Functions
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > Serverless > Install Serverless Monitoring for Azure Functions
---

# Install Serverless Monitoring for Azure Functions

## Overview{% #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](https://docs.datadoghq.com/integrations/azure/).

Here is the list of supported runtimes, operating systems (OS) and hosting plans for Azure Functions monitoring:

- **Runtimes**: .NET, Node.js, Python, Java
- **Operating Systems (OS)**: Windows, Linux
- **Hosting Plans**: Dedicated (App Service) Plan, Premium Plan, Consumption Plan, Flex Consumption Plan

The recommended installation method depends on your Azure Function's configuration:

- For .NET Windows Azure Functions running on Dedicated/App Service or Premium plans: use the [Datadog .NET APM Extension](https://docs.datadoghq.com/serverless/azure_app_service/windows_code/?tab=net).
- For all other configurations (including different runtimes, operating systems, or hosting plans): Follow the instructions below to install the Serverless Compatibility Layer.

## Setup{% #setup %}

If you haven't already, install the [Datadog-Azure integration](https://docs.datadoghq.com/integrations/azure/) to collect metrics and logs. Then instrument your application with the following steps:

{% tab title="Node.js" %}

1. **Install dependencies**. Run the following commands:

   ```shell
   npm install @datadog/serverless-compat
   npm install dd-trace
   ```

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.

1. **Start the Datadog Serverless Compatibility Layer and initialize the Datadog Node.js tracer**.

Use the `--require` option to load and initialize the Serverless Compatibility Layer and the Datadog Node.js tracer in one step. Node options in Azure Functions can be configured with the environment variable `languageWorkers__node__arguments`.

   ```
   languageWorkers__node__arguments='--require @datadog/serverless-compat/init --require dd-trace/init'
   ```

1. **Configure the Datadog Node.js tracer**

[Configuring the Node.js Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/nodejs)

{% /tab %}

{% tab title="Python" %}

1. **Install dependencies**. Run the following commands:

   ```shell
   pip install datadog-serverless-compat
   pip install ddtrace
   ```

Datadog recommends using the latest versions of both `datadog-serverless-compat` and `ddtrace` to ensure you have access to enhancements and bug fixes.

1. **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
   import ddtrace.auto
   
   start()
   ```

1. **Configure the Datadog Python tracer**

[Configuring the Python Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/python)

{% /tab %}

{% tab title="Java" %}

1. **Install dependencies**. Download the Datadog JARs and deploy them with your function:

   ```bash
   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](https://repo1.maven.org/maven2/com/datadoghq/dd-serverless-compat-java-agent/) 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.

1. **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](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java?tabs=bash%2Cconsumption#customize-jvm) for more details on the appropriate environment variable for your hosting plan.

1. **Configure the Datadog Java tracer**

[Configuring the Java Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/java)

{% /tab %}

{% tab title=".NET" %}

1. **Install dependencies**. Run the following commands:

   ```shell
   dotnet package add Datadog.AzureFunctions
   ```

Datadog recommends regularly upgrading to the latest version of `Datadog.AzureFunctions` to ensure you have access to enhancements and bug fixes.

1. **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 [legacy in-process model](https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-in-process-differences), 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();
         }
      }
   }
   ```

1. **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
   ```

1. **Configure the Datadog .NET tracer**

   - [Configuring the .NET Core Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/dotnet-core)
   - [Configuring the .NET Framework Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/dotnet-framework)

{% /tab %}

**Deploy your function**.

**Configure Datadog intake**. Add the following environment variables to your function's application settings:

| Name                      | Value                                                                                                                                                                       |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DD_API_KEY`              | Your [Datadog API key](https://docs.datadoghq.com/account_management/api-app-keys/#add-an-api-key-or-client-token).                                                         |
| `DD_SITE`                 | Your [Datadog site](https://docs.datadoghq.com/getting_started/site). For example, .                                                                                        |
| `DD_AZURE_RESOURCE_GROUP` | Your Azure resource group. Only required for Azure Functions on the [Flex Consumption plan](https://learn.microsoft.com/en-us/azure/azure-functions/flex-consumption-plan). |

**Do not set** the following environment variables in your serverless environment. They should only be set in non-serverless environments.

- `DD_AGENT_HOST`
- `DD_TRACE_AGENT_URL`

**Configure Unified Service Tagging**. You can collect metrics from your Azure Functions by installing the [Datadog Azure integration](https://docs.datadoghq.com/integrations/azure/). 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](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/). For example, `prod`. |
| `DD_SERVICE` | How you want to tag your service for [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/).                  |
| `DD_VERSION` | How you want to tag your version for [Unified Service Tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/).                  |

## What's next?{% #whats-next %}

- You can view your Azure Functions traces in [Trace Explorer](https://app.datadoghq.com/apm/traces). Search for the service name you set in the `DD_SERVICE` environment variable to see your traces.
- You can use the [Serverless > Azure Functions](https://app.datadoghq.com/functions?cloud=azure&entity_view=function) page to see your traces enriched with telemetry collected by the [Datadog Azure integration](https://docs.datadoghq.com/integrations/azure/).

## Profiling{% #profiling %}

{% alert level="info" %}
Datadog's Continuous Profiler is available in preview for Python and Node.js on Azure Functions.
{% /alert %}

To enable the [Continuous Profiler](https://docs.datadoghq.com/profiler/), set the environment variable `DD_PROFILING_ENABLED=true`.

## Troubleshooting{% #troubleshooting %}

### Enable debug logs{% #enable-debug-logs %}

You can collect [debug logs](https://docs.datadoghq.com/tracing/troubleshooting/tracer_debug_logs/#enable-debug-mode) for troubleshooting. To configure debug logs, use the following environment variables:

{% dl %}

{% dt %}
`DD_TRACE_DEBUG`
{% /dt %}

{% dd %}
Enables (`true`) or disables (`false`) debug logging for the Datadog Tracing Library. Defaults to `false`.
**Values**: `true`, `false`
{% /dd %}

{% dt %}
`DD_LOG_LEVEL`
{% /dt %}

{% dd %}
Sets logging level for the Datadog Serverless Compatibility Layer. Defaults to `info`.
**Values**: `trace`, `debug`, `info`, `warn`, `error`, `critical`, `off`
{% /dd %}

{% /dl %}
