Skip to content

[DO NOT MERGE][SVLS-7119] add instructions to install Serverless monitoring for .NET Azure Functions #30608

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
182 changes: 107 additions & 75 deletions content/en/serverless/azure_functions/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ 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
npm install @datadog/serverless-compat
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();
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -56,43 +50,114 @@ 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:
```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][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. **Configure the Datadog Java tracer**

[Configuring the Java Tracing Library][3]

[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

3. (Optional) **Enable runtime metrics**. See [Java Runtime Metrics][2].
CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}

4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3].
CORECLR_PROFILER_PATH=
/home/site/wwwroot/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so

DD_DOTNET_TRACER_HOME=/home/site/wwwroot/datadog

```

[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
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 >}}

Expand All @@ -105,50 +170,24 @@ This page explains how to collect traces, trace metrics, runtime metrics, and cu
| `DD_API_KEY` | Your [Datadog API key][1]. |
Copy link
Member

@lucaspimentel lucaspimentel Jul 21, 2025

Choose a reason for hiding this comment

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

Probably fine for a first pass, but we should consider consolidating all the env vars later. Right now the steps are

  1. add env vars
  2. deploy your func
  3. add more env vars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you have any formatting recommendations for this! We have the .NET specific environment variables in the programming-lang lang block and the generic environment variables outside of it so I'm not sure the best way to reconcile those two things.

| `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`.
Expand All @@ -160,17 +199,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/
[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/
Loading