| title | Install Serverless Monitoring for Azure Functions | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| further_reading |
|
This page explains how to collect traces, trace metrics, runtime metrics, enhanced metrics, and custom metrics from your Azure Functions. Enhanced metrics are distinguished with the azure.functions.enhanced.* namespace. To collect additional metrics, install the Datadog Azure integration.
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.
- For Azure Function Apps running on Container Apps: use Datadog Serverless-Init.
- For all other configurations (including different runtimes, operating systems, or hosting plans): Follow the instructions below to install the Serverless Compatibility Layer.
If you haven't already, install the Datadog-Azure integration to collect metrics and logs. Then instrument your application with the following steps:
{{< programming-lang-wrapper langs="nodejs,python,java,dotnet" >}} {{< programming-lang lang="nodejs" >}}
-
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-compatanddd-traceto ensure you have access to enhancements and bug fixes. -
Start the Datadog Serverless Compatibility Layer and initialize the Datadog Node.js SDK.
Use the
--requireoption to load and initialize the Serverless Compatibility Layer and the Datadog Node.js SDK in one step. Node options in Azure Functions can be configured with the environment variablelanguageWorkers__node__arguments.languageWorkers__node__arguments='--require @datadog/serverless-compat/init --require dd-trace/init' -
Configure the Datadog Node.js SDK
{{< /programming-lang >}} {{< programming-lang lang="python" >}}
-
Install dependencies. Run the following commands:
pip install datadog-serverless-compat pip install ddtrace
Datadog recommends using the latest versions of both
datadog-serverless-compatandddtraceto ensure you have access to enhancements and bug fixes. -
Start the Datadog Serverless Compatibility Layer and initialize the Datadog Python SDK. Add the following lines to your main application entry point file:
from datadog_serverless_compat import start start() import ddtrace.auto # noqa: E402, F401
-
Configure the Datadog Python SDK
{{< /programming-lang >}} {{< programming-lang lang="java" >}}
-
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-agentanddd-java-agentto ensure you have access to enhancements and bug fixes. -
Start the Datadog Serverless Compatibility Layer and initialize the Datadog Java SDK. Add the following
-javaagentarguments 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 SDK
{{< /programming-lang >}} {{< programming-lang lang="dotnet" >}}
-
Install dependencies. Run the following commands:
dotnet package add Datadog.AzureFunctions
Datadog recommends regularly upgrading to the latest version of
Datadog.AzureFunctionsto 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 legacy in-process model, add a NuGet package reference to
Microsoft.Azure.Functions.Extensions:dotnet package add Microsoft.Azure.Functions.Extensions
And add the following
.csfile 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\datadogIf 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 SDK
{{< /programming-lang >}} {{< /programming-lang-wrapper >}}
-
Deploy your function.
-
Configure Datadog intake. Add the following environment variables to your function's application settings:
Name Value DD_API_KEYYour Datadog API key. DD_SITEYour Datadog site. For example, {{< region-param key=dd_site code="true" >}}. DD_AZURE_RESOURCE_GROUPYour Azure resource group. Only required for Azure Functions on the Flex Consumption plan. {{% svl-tracing-env %}}
-
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, andversiontags on your resource in Azure. Then, configure the following environment variables.Name Value DD_ENVHow you want to tag your env for Unified Service Tagging. For example, prod.DD_SERVICEHow you want to tag your service for Unified Service Tagging. DD_VERSIONHow you want to tag your version for Unified Service Tagging.
- You can view your Azure Functions traces in {{< ui >}}Trace Explorer{{< /ui >}}. Search for the service name you set in the
DD_SERVICEenvironment variable to see your traces. - You can use the {{< ui >}}Serverless{{< /ui >}} > {{< ui >}}Azure Functions{{< /ui >}} page to see your traces enriched with telemetry collected by the Datadog Azure integration.
To enable the Continuous Profiler, set the environment variable DD_PROFILING_ENABLED=true.
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 SDK. 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
{{< partial name="whats-next/whats-next.html" >}}