[SVLS-6337] Set resource group correctly for Azure functions on flex consumption plans#1241
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1241 +/- ##
==========================================
- Coverage 71.64% 71.63% -0.01%
==========================================
Files 355 355
Lines 56385 56443 +58
==========================================
+ Hits 40398 40435 +37
- Misses 15987 16008 +21
🚀 New features to boost your workflow:
|
d71aa73 to
8d45f9b
Compare
BenchmarksComparisonBenchmark execution time: 2025-10-01 16:33:58 Comparing candidate commit d88f866 in PR branch Found 0 performance improvements and 2 performance regressions! Performance is the same for 51 metrics, 2 unstable metrics. scenario:credit_card/is_card_number/378282246310005
CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
Group 14
Group 15
BaselineOmitted due to size. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. |
duncanpharvey
left a comment
There was a problem hiding this comment.
Looks good! Just one minor comment
| let extracted = | ||
| AzureMetadata::extract_resource_group(query.get_var(WEBSITE_OWNER_NAME)); | ||
| match extracted.as_deref() { | ||
| Some("flex") => None, |
There was a problem hiding this comment.
Very much an edge case but what if a customer happens to name their resource group flex? Would the span attribute end up resolving to unknown?
There was a problem hiding this comment.
It seems to me that the WEBSITE_RESOURCE_GROUP environment variable is normally available in Azure Functions (except if they're on the flex consumption plan), so if we're not in a flex consumption function, then checking WEBSITE_RESOURCE_GROUP should be able to return the correct resource group, and we won't get to the part where it checks WEBSITE_OWNER_NAME.
Is WEBSITE_RESOURCE_GROUP sometimes not set in Azure functions? If so, when checking WEBSITE_OWNER_NAME and extracting the resource group from there, if it's "flex", I could also check if the WEBSITE_SKU env var is also not FlexConsumption (and return "flex")?
There was a problem hiding this comment.
Yeah I think checking if the WEBSITE_SKU is FlexConsumption (or whatever the specific value is) is a better approach compared to checking if the extracted value from the WEBSITE_OWNER_NAME is flex. Then it doesn't matter what the extracted value parsed from WEBSITE_OWNER_NAME is.
There was a problem hiding this comment.
Gotcha, that makes sense! I changed it check WEBSITE_SKU == FlexConsumption rather than checking if the extracted value is flex!
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. |
…p for flex consumption functions
… flex consumption rg detection logic changes
a777daf to
d1b35ef
Compare
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
kathie.huang@datadoghq.com cancelled this merge request build |
|
/remove |
|
View all feedbacks in Devflow UI.
|
|
/merge |
|
View all feedbacks in Devflow UI.
This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
The expected merge time in
|
What does this PR do?
We plan on changing the public docs to ask customers who are using Datadog to monitor their Azure functions on the flex consumption plan to add a
DD_AZURE_RESOURCE_GROUPenvironment variable in their Azure app settings. This PR handles the logic to check for that env var to accurately update the resource group span attribute for flex consumption functions.DD_AZURE_RESOURCE_GROUPenvironment variable (which we ask flex consumption function users to add in Azure app settings)WEBSITE_RESOURCE_GROUPenvironment variable (which Azure automatically has for any function not on flex consumption plans)WEBSITE_SKUto see if the function is on a flex consumption plan. If so, it should have setDD_AZURE_RESOURCE_GROUP, so set the resource group tounknown.WEBSITE_OWNER_NAMEenvironment variable (which includes the resource group in a structure that is consistent across all plans except flex consumption). It sets the Azure metadata resource group span attribute accordingly.DD_AZURE_RESOURCE_GROUPfor a flex consumption function, we will shut down the tracer (link to PR). We also plan to update the serverless-compat layers for defense in depth.Also fixed spelling error for
WEBSITE_OWNER_NAMEvariableMotivation
aas.resource.groupspan attribute for functions on flex consumption plans is set incorrectly in Datadog - they're all set to "flex"aas.resource.idis built usingaas.resource.group, and the resource id is used in billing, which needs to be accurateJira Ticket - more context on our investigation can be found here, e.g. there is a precedent for asking for this env var with Azure Container Apps using serverless-init
Additional Notes
Once this PR is merged, we plan to make a new PR in
serverless-components/datadog-trace-agentto update the libdatadog commit hash.How to test the change?
git logto find this PR's most recent commit hash (currentlyd1b35ef21fff3c4588073504905081c8923bbc4b)everywhere that
libdatadogis useduse_serverless_compat_local_pathto true and making sure the built binary is in yourpythonfolderDD_AZURE_RESOURCE_GROUPenv var, you should seeunknownas the resource group. (There is a PR in serverless-components/datadog-trace-agent that will shut down the trace agent, causing no traces to be sent to Datadog, ifDD_AZURE_RESOURCE_GROUPis missing)DD_AZURE_RESOURCE_GROUPas an environment variable with your resource group. Repeat step 5, you should see the correct resource group in theresource.groupspan attribute!No

DD_AZURE_RESOURCE_GROUPenvironment variable -> unknown resource group:DD_AZURE_RESOURCE_GROUPenvironment variable set -> resource group correctly set