title |
---|
Install Serverless Monitoring for Azure Functions |
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.
{{< programming-lang-wrapper langs="nodejs,python" >}} {{< programming-lang lang="nodejs" >}}
-
Install dependencies. Run the following commands:
npm install @datadog/serverless-compat npm install dd-trace
To use automatic instrumentation, 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
anddd-trace
to ensure you have access to enhancements and bug fixes. -
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
):require('@datadog/serverless-compat').start(); // This line must come before importing any instrumented module. const tracer = require('dd-trace').init()
-
(Optional) Enable runtime metrics. See Node.js Runtime Metrics.
-
(Optional) Enable custom metrics. See Metric Submission: DogStatsD.
{{< /programming-lang >}} {{< programming-lang lang="python" >}}
-
Install dependencies. Run the following commands:
pip install datadog-serverless-compat pip install ddtrace
To use automatic instrumentation, you must use
dd-trace
v2.19+.Datadog recommends using the latest versions of both
datadog-serverless-compat
andddtrace
to ensure you have access to enhancements and bug fixes. -
Initialize the Datadog Python tracer and serverless compatibility layer. Add the following lines to your main application entry point file:
from datadog_serverless_compat import start from ddtrace import tracer, patch_all start() patch_all()
-
(Optional) Enable runtime metrics. See Python Runtime Metrics.
-
(Optional) Enable custom metrics. See Metric Submission: DogStatsD. 1: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation 2: /tracing/metrics/runtime_metrics/python/ 3: /metrics/custom_metrics/dogstatsd_metrics_submission/?code-lang=python {{< /programming-lang >}} {{< /programming-lang-wrapper >}}
-
Deploy your function.
-
Configure Datadog intake. Add the following environment variables to your function's application settings:
DD_API_KEY=<YOUR_API_KEY> DD_SITE={{< region-param key=dd_site code="true" >}}
- Set
DD_API_KEY
to your Datadog API key. - Set
DD_SITE
to {{< region-param key=dd_site code="true" >}}. (Ensure that your correct Datadog site is selected in the drop-down on the right side of this page.)
- Set
-
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
, andversion
tags on your resource in Azure. Then, configure the following environment variables. You can add custom tags asDD_TAGS
.DD_ENV="<ENVIRONMENT>" DD_SERVICE="<SERVICE_NAME>" DD_VERSION="<VERSION>" DD_TAGS="<KEY_1:VALUE_1>,<KEY_2:VALUE_2>"
- You can view your Azure Functions traces in Trace Explorer. Search for the service name you set in the
DD_SERVICE
environment variable to see your traces. - You can use the Serverless > Azure Functions page to see your traces enriched with telemetry collected by the Datadog Azure integration.
Trace metrics are enabled by default. To configure trace metrics, use the following environment variable:
DD_TRACE_STATS_COMPUTATION_ENABLED
: Enables (true
) or disables (false
) trace metrics. Defaults to true
.
Values: true
, false
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
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.