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.
Setup
Install dependencies. Run the following commands:
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.
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
):
require('@datadog/serverless-compat').start();
// This line must come before importing any instrumented module.
const tracer = require('dd-trace').init()
Configure the Datadog Node.js tracer
Configuring the Node.js Tracing Library
Install dependencies. Run the following commands:
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.
Start the Datadog Serverless Compatibility Layer and initialize the Datadog Python tracer. Add the following lines to your main application entry point file:
from datadog_serverless_compat import start
import ddtrace.auto
start()
Configure the Datadog Python tracer
Configuring the Python Tracing Library
Install dependencies. Download the Datadog JARs and deploy them with your function:
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 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.
Start the Datadog Serverless Compatibility Layer and initialize the Datadog Java tracer. Add the following -javaagent
arguments to the JVM options.:
-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 for more details on the appropriate environment variable for your hosting plan.
Configure the Datadog Java tracer
Configuring the Java Tracing Library
Install dependencies. Run the following commands:
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.
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:
Datadog.Serverless.CompatibilityLayer.Start();
If your Azure Function app uses the In-Process model, add a NuGet package reference to Microsoft.Azure.Functions.Extensions
:
dotnet package add Microsoft.Azure.Functions.Extensions
And add the following .cs
file to your application:
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();
}
}
}
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
Configure the Datadog .NET tracer
Deploy your function.
Configure Datadog intake. Add the following environment variables to your function’s application settings:
Configure Unified Service Tagging. You can collect metrics from your Azure Functions by installing the Datadog Azure integration. 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.
What’s next?
Troubleshooting
Enable debug logs
You can collect debug logs 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
.Values: true
, false
DD_LOG_LEVEL
- Sets logging level for the Datadog Serverless Compatibility Layer. Defaults to
info
.Values: trace
, debug
, info
, warn
, error
, critical
, off