Skip to content
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

DOCS-9940: Serverless Monitoring for Azure Functions #27294

Merged
merged 9 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 8 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
11 changes: 8 additions & 3 deletions config/_default/menus/main.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3024,21 +3024,26 @@ menu:
parent: serverless
identifier: serverless_container_apps
weight: 5
- name: Azure Functions
url: serverless/azure_functions
parent: serverless
identifier: serverless_azure_functions
weight: 6
- name: Google Cloud Run
url: serverless/google_cloud_run
parent: serverless
identifier: serverless_gcr
weight: 6
weight: 7
- name: Glossary
url: serverless/glossary
parent: serverless
identifier: serverless_glossary
weight: 7
weight: 8
- name: Guides
url: serverless/guide/
identifier: serverless_guides
parent: serverless
weight: 8
weight: 9
- name: Network Monitoring
url: network_monitoring/
pre: network
Expand Down
130 changes: 130 additions & 0 deletions content/en/serverless/azure_functions/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
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].

## Setup

{{< programming-lang-wrapper langs="nodejs,python" >}}
{{< 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.

Check notice on line 20 in content/en/serverless/azure_functions/_index.md

View workflow job for this annotation

GitHub Actions / vale

Datadog.sentencelength

Suggestion: Try to keep your sentence length to 25 words or fewer.

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`):

```js
require('@datadog/serverless-compat').start();

// This line must come before importing any instrumented module.
const tracer = require('dd-trace').init()
```

3. (Optional) **Enable runtime metrics**. See [Node.js Runtime Metrics][2].

4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3].

[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
{{< /programming-lang >}}
{{< programming-lang lang="python" >}}
1. **Install dependencies**. Run the following commands:
```shell
pip install datadog-serverless-compat
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:

```python
from datadog_serverless_compat import start
janine-c marked this conversation as resolved.
Show resolved Hide resolved
from ddtrace import tracer, patch_all

start()
patch_all()
```

3. (Optional) **Enable runtime metrics**. See [Python Runtime Metrics][2].

4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3].
[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if you saw this during your testing or if it's something odd going on on my end, but my local build insists on having this blank line to render the links properly:

Suggested change
4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3].
[1]: /tracing/trace_collection/automatic_instrumentation/?tab=singlestepinstrumentation
4. (Optional) **Enable custom metrics**. See [Metric Submission: DogStatsD][3].
[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 >}}

3. **Deploy your function**.
Copy link
Contributor

Choose a reason for hiding this comment

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

The numbering goes back to 3 here - just bump the numbers from here on in up by 2 and you're good to go 🙂


4. **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][1].
- Set `DD_SITE` to {{< region-param key=dd_site code="true" >}}. (Ensure that your correct [Datadog site][2] is selected in the drop-down on the right side of this page.)

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

```
DD_ENV="<ENVIRONMENT>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just want to double check that these environment variables use quotation marks, but the ones in the previous step don't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it's actually an interface that they'd use to add each of these... you bring up a good point, I'm going to reformat this

DD_SERVICE="<SERVICE_NAME>"
DD_VERSION="<VERSION>"
DD_TAGS="<KEY_1:VALUE_1>,<KEY_2:VALUE_2>"
```

## 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:

`DD_TRACE_STATS_COMPUTATION_ENABLED`
: Enables (`true`) or disables (`false`) trace metrics. Defaults to `true`.

**Values**: `true`, `false`

## Troubleshooting

### Enable debug logs

You can collect [debug logs][7] 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`
duncanpharvey marked this conversation as resolved.
Show resolved Hide resolved

`DD_LOG_LEVEL`
: Sets logging level for the Datadog Serverless Compatibility Layer. Defaults to `info`.

**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
Loading