Skip to content

fix(libdd-common): Add fallback logic for resolving Azure Functions instance name [SVLS-8931]#2077

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
kathie.huang/update-azure-function-instance-name-logic
Jun 15, 2026
Merged

fix(libdd-common): Add fallback logic for resolving Azure Functions instance name [SVLS-8931]#2077
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits into
mainfrom
kathie.huang/update-azure-function-instance-name-logic

Conversation

@kathiehuang

@kathiehuang kathiehuang commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Moves logic for resolving Azure Functions instance name from serverless-components to libdd-common.
  • Logic for resolving instance name: COMPUTERNAME -> WEBSITE_POD_NAME -> CONTAINER_NAME
    • This matches the instance tag of azure.functions.function_execution_count integration metric
    • Before, we only checked COMPUTERNAME. The investigation to determine which env vars should be used is in the Instance tab of Enhanced Metrics in the Serverless Compatibility Layer
  • This has the added benefit of populating the instance name span attribute aas.environment.instance_name in hosting plans where the attribute was unknown before
    • Before, we only looked at COMPUTERNAME for instance name, which was empty for Linux Flex Consumption and Consumption functions
  • This PR also makes some consts public so that they can be used by serverless-components; see [SVLS-9015] Use consts and instance resolution logic from libdd-common serverless-components#134 for usage

Motivation

https://datadoghq.atlassian.net/browse/SVLS-8931
https://datadoghq.atlassian.net/browse/SVLS-9015

Additional Notes

Once this PR is merged, we plan to make a new PR in serverless-components to update the libdatadog commit hash and remove the redundant consts and instance name logic. Draft PR: DataDog/serverless-components#134

How to test the change?

Unit tests: Run cargo test -p libdd-common azure_app_services

  1. Use git log to find this PR's most recent commit hash
  2. Clone serverless-components and update the commit hash in datadog-trace-agent/Cargo.toml everywhere that libdatadog is used
  3. Follow the instructions in the Serverless Compatibility Layer docs to deploy sample apps

Flex Consumption function with fix:
image

Flex Consumption function without fix:
Screenshot 2026-06-03 at 4 33 58 PM

Consumption function with fix:
image

Consumption function without fix:
image

I tested by deploying with serverless-compat-self-monitoring:

  • FC1 and Y1 linux functions get the aas.environment.instance_name span attribute populated
  • The span attributes for all other functions still look the same (same shape and casing)

@github-actions github-actions Bot added the common label Jun 3, 2026
@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Jun 3, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 73.41% (-0.14%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: aeffe22 | Docs | Datadog PR Page | Give us feedback!

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/kathie.huang/update-azure-function-instance-name-logic

Summary by Rule

Rule Base Branch PR Branch Change
unwrap_used 1 1 No change (0%)
Total 1 1 No change (0%)

Annotation Counts by File

File Base Branch PR Branch Change
libdd-common/src/azure_app_services.rs 1 1 No change (0%)

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 21 21 No change (0%)
datadog-live-debugger 4 6 ⚠️ +2 (+50.0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-sidecar 46 58 ⚠️ +12 (+26.1%)
libdd-common 13 13 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 5 5 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-remote-config 3 0 ✅ -3 (-100.0%)
libdd-telemetry 20 20 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 3 3 No change (0%)
libdd-trace-stats 1 1 No change (0%)
libdd-trace-utils 11 13 ⚠️ +2 (+18.2%)
Total 181 194 ⚠️ +13 (+7.2%)

About This Report

This report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality.

@kathiehuang kathiehuang changed the title [SVLS-8931] Add fallback logic for resolving Azure Functions instance name span attribute fix(libdd-common): Add fallback logic for resolving Azure Functions instance name span attribute [SVLS-8931] Jun 3, 2026
@kathiehuang kathiehuang changed the title fix(libdd-common): Add fallback logic for resolving Azure Functions instance name span attribute [SVLS-8931] fix(libdd-common): Add fallback logic for resolving Azure Functions instance name [SVLS-8931] Jun 3, 2026
@codecov-commenter

codecov-commenter commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.52%. Comparing base (37891f1) to head (1322cf3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2077      +/-   ##
==========================================
+ Coverage   73.49%   73.52%   +0.03%     
==========================================
  Files         475      475              
  Lines       78994    79143     +149     
==========================================
+ Hits        58054    58191     +137     
- Misses      20940    20952      +12     
Components Coverage Δ
libdd-crashtracker 65.35% <ø> (+0.04%) ⬆️
libdd-crashtracker-ffi 37.68% <ø> (ø)
libdd-agent-client 83.79% <ø> (ø)
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 86.07% <ø> (ø)
libdd-data-pipeline-ffi 73.02% <ø> (ø)
libdd-common 80.53% <100.00%> (+0.59%) ⬆️
libdd-common-ffi 74.41% <ø> (ø)
libdd-telemetry 73.34% <ø> (ø)
libdd-telemetry-ffi 31.36% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 76.22% <ø> (-0.10%) ⬇️
libdd-profiling 81.70% <ø> (+0.01%) ⬆️
libdd-profiling-ffi 64.79% <ø> (ø)
libdd-sampling 97.48% <ø> (ø)
datadog-sidecar 36.13% <ø> (ø)
datdog-sidecar-ffi 10.31% <ø> (ø)
spawn-worker 48.86% <ø> (ø)
libdd-tinybytes 93.80% <ø> (ø)
libdd-trace-normalization 81.71% <ø> (ø)
libdd-trace-obfuscation 87.30% <ø> (ø)
libdd-trace-protobuf 68.25% <ø> (ø)
libdd-trace-utils 89.32% <ø> (+0.01%) ⬆️
libdd-tracer-flare 86.57% <ø> (ø)
libdd-log 74.83% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dd-octo-sts

dd-octo-sts Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 83.48 MB 83.48 MB +0% (+6.53 KB) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.70 MB 7.70 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 94.59 MB 94.60 MB +0% (+6.57 KB) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.34 MB 10.34 MB +0% (+24 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 24.71 MB 24.72 MB +0% (+2.50 KB) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 86.89 KB 86.89 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 179.84 MB 179.85 MB +0% (+8.00 KB) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 923.21 MB 923.24 MB +0% (+27.25 KB) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.09 MB 8.09 MB +.01% (+1.00 KB) 🔍
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 86.89 KB 86.89 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 23.91 MB 23.91 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 47.73 MB 47.73 MB +0% (+4.78 KB) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 21.42 MB 21.43 MB +0% (+2.00 KB) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 88.26 KB 88.26 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 183.82 MB 183.83 MB +0% (+16.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 915.97 MB 915.99 MB +0% (+26.46 KB) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.25 MB 6.25 MB +0% (+512 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 88.26 KB 88.26 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 25.63 MB 25.63 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 45.35 MB 45.36 MB +0% (+4.30 KB) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 74.45 MB 74.46 MB +0% (+7.11 KB) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.58 MB 8.58 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 89.87 MB 89.87 MB +0% (+7.12 KB) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.43 MB 10.43 MB 0% (0 B) 👌

@kathiehuang

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR moves Azure Functions instance-name resolution into libdd-common by adding hosting-plan-aware fallback logic so aas.environment.instance_name is populated correctly across Flex Consumption/Consumption and Premium/Dedicated plans. It also exposes a few environment variable name constants for reuse by downstream components (e.g., serverless-components).

Changes:

  • Add resolve_instance_name to select the correct instance identifier source (CONTAINER_NAME / WEBSITE_POD_NAME / COMPUTERNAME) based on WEBSITE_SKU, with fallbacks.
  • Expand the Linux /proc/self/environ allowlist to include the new instance-name env vars.
  • Make selected constants public and add/adjust unit tests to cover the new behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +423 to +425
fn non_empty(s: Option<&str>) -> Option<&str> {
s.filter(|v| !v.trim().is_empty())
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kathiehuang kathiehuang force-pushed the kathie.huang/update-azure-function-instance-name-logic branch from 69e67aa to fcdcb31 Compare June 5, 2026 14:15
@kathiehuang kathiehuang requested a review from Copilot June 5, 2026 14:51
@kathiehuang

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fcdcb31d3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

.or_else(|| non_empty(computer_name))
.or_else(|| non_empty(container_name))
.or_else(|| non_empty(pod_name))
.map(|s| s.to_string())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize instance names to match metric tags

In resolve_instance_name, mixed-case Azure values are returned as-is; for example the new tests cover CONTAINER_NAME="0--abc-DEF" and "ABCD...", but the serverless enhanced instance metric this logic is being moved from lowercases the resolved instance tag before submission. In Flex/Consumption or Premium plans where Azure supplies uppercase characters, spans will get aas.environment.instance_name with different casing than the azure.functions.enhanced.instance tag, breaking the intended correlation even though the same source env var was selected.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intentional - the existing aas.environment.instance_name span attribute preserves the casing, but on the integration metric, the instance tag is consistently lowercased.

Example:

Mixed case in existing instance name span attribute:
image

Lowercase in integration metric azure.functions.function_execution_count (pulled from Azure Monitor):
image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread libdd-common/src/azure_app_services.rs Outdated
}

#[test]
fn test_public_consts_are_accessible() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the test since it's not useful 1322cf3

@kathiehuang kathiehuang force-pushed the kathie.huang/update-azure-function-instance-name-logic branch from 1322cf3 to ee2b343 Compare June 8, 2026 14:21
@kathiehuang kathiehuang force-pushed the kathie.huang/update-azure-function-instance-name-logic branch from ee2b343 to ff8ee41 Compare June 8, 2026 17:00
@kathiehuang kathiehuang marked this pull request as ready for review June 8, 2026 17:45
@kathiehuang kathiehuang requested a review from a team as a code owner June 8, 2026 17:45
@kathiehuang kathiehuang requested a review from duncanpharvey June 8, 2026 17:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff8ee413f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread libdd-common/src/azure_app_services.rs Outdated
Comment on lines +428 to +430
Some("FlexConsumption") | Some("Dynamic") => {
non_empty(container_name).or_else(|| non_empty(pod_name))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prefer COMPUTERNAME for Windows Dynamic apps

When a Windows Consumption function has WEBSITE_SKU=Dynamic and also exposes a CONTAINER_NAME app setting, this branch chooses CONTAINER_NAME before COMPUTERNAME. The new Windows test only covers the case where container vars are absent, but app settings are surfaced as environment variables, so a user-defined CONTAINER_NAME would overwrite aas.environment.instance_name with an unrelated value instead of the Windows instance name the PR says should come from COMPUTERNAME; the resolver needs an OS/plan signal or a Windows-specific preference.

Useful? React with 👍 / 👎.

@kathiehuang kathiehuang Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmmm. Maybe I can remove WEBSITE_SKU from the function signature entirely and just make the fallback logic the same regardless of the hosting plan - COMPUTERNAME > WEBSITE_POD_NAME > CONTAINER_NAME. Based off this investigation, these three environment variables never conflict - they're either the same as each other or empty. This ordering makes the most likely env var to be set by a user, CONTAINER_NAME, the last in the fallback chain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

869d570

Deployed with serverless-compat-self-monitoring and ensured no regressions

Comment on lines +21 to +26
pub const WEBSITE_SKU: &str = "WEBSITE_SKU";
pub const REGION_NAME: &str = "REGION_NAME";
const CONTAINER_NAME: &str = "CONTAINER_NAME";
const WEBSITE_POD_NAME: &str = "WEBSITE_POD_NAME";

const UNKNOWN_VALUE: &str = "unknown";
pub const UNKNOWN_VALUE: &str = "unknown";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do these constants need to be public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had received some suggestions on my enhanced metrics PR to use the constants in libdatadog (example 1, example 2, and I can't use them in serverless-components unless they're public

image

Comment thread libdd-common/src/azure_app_services.rs Outdated
Comment on lines +258 to +260
let container_name = query.get_var(CONTAINER_NAME);
let pod_name = query.get_var(WEBSITE_POD_NAME);
let computer_name = query.get_var(INSTANCE_NAME);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very minor nit but I think it would make it easier to follow the instance name resolution order if the variables were defined in the same order (computer_name -> pod_name -> container_name).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! Made the order consistent in aeffe22

Comment thread libdd-common/src/azure_app_services.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe the INSTANCE_NAME constant should be renamed to COMPUTERNAME given that instance name can come from one of several environment variables now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! Renamed in aeffe22

@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit a820699 into main Jun 15, 2026
91 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the kathie.huang/update-azure-function-instance-name-logic branch June 15, 2026 20:02
iunanua added a commit that referenced this pull request Jun 19, 2026
# Release proposal for libdd-remote-config and its dependencies

This PR contains version bumps based on public API changes and commits
since last release.

## libdd-common
**Next version:** `5.0.0`
**Semver bump:** `major`
**Tag:** `libdd-common-v5.0.0`

### Commits

- chore(profiling): Use SECURITY_ANONYMOUS when connecting to named pipe
server (#2134)
- fix: Fix http PathAndQuery Uri Parsing (#2122)
- chore(common)!: replace native-certs with platform-verifier (#2078)
- feat(data-pipeline)!: CSS Trace Filters (#1985)
- fix(libdd-common): Add fallback logic for resolving Azure Functions
instance name [SVLS-8931] (#2077)
- test: fix timeouts on heavily contended scenarios (#2093)

## libdd-remote-config
**Next version:** `1.0.0`
**Semver bump:** `major`
**Tag:** `libdd-remote-config-v1.0.0`

**Warning:** this is an initial release. Please verify that the version
and commits included are correct.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: iunanua <18325288+iunanua@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants