Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new environment variable DD_ENV_TYPE that allows users to explicitly override the automatically detected cloud environment type in the serverless mini agent. This addresses a real-world issue where generic environment variables (like FUNCTION_NAME) were causing incorrect environment detection, particularly for Azure Functions being misidentified as Google Cloud Functions.
Changes:
- Added support for explicitly setting environment type via the
DD_ENV_TYPEenvironment variable with three supported values:cloudfunction,azurefunction, andazurespringapp - Changed
env_typefrom immutable to mutable to allow override capability - Added validation logic that gracefully falls back to auto-detection if an unrecognized value is provided
- Maintains full backward compatibility—existing auto-detection behavior is unchanged when the new env var is not set
|
👋 Hi @Velex158, thank you for this PR and the detailed writeup! I have a fix up in libdatadog that addresses the root cause of this and utilizes environment variables that are more cloud-specific to detect the cloud environment: DataDog/libdatadog#1857 This change also improves logging so that the root cause will be made clear in the case of any future environment-detection errors. Once that change is merged and we do a release of the Serverless Compatibility Layer, you will be able to freely use the |
What does this PR do?
This PR introduces support for explicitly overriding the detected cloud environment via the
DD_ENV_TYPEenvironment variable.If
DD_ENV_TYPEis set, the mini agent will prioritize this value over the automatically detected environment fromread_cloud_env(). Currently supported values are:cloudfunctionazurefunctionazurespringappIf the value is not recognized, the existing auto-detection logic remains unchanged.
Motivation
We encountered an issue where the environment detection logic incorrectly classified the runtime environment due to the presence of a generic environment variable (
FUNCTION_NAME).The function responsible for this is read_cloud_env()
In our specific case, Azure Functions were misidentified as Google Cloud Functions because
FUNCTION_NAMEwas set by internal tooling. This led to incorrect behavior of the serverless mini agent.As part of debugging (see support ticket below), we identified that:
FUNCTION_NAMEis too generic to reliably indicate the environmentTo resolve this, we:
AZURE_FUNCTION_NAMEDD_ENV_TYPE) to allow explicit controlSupport ticket:
https://help.datadoghq.com/hc/en-us/requests/2771896?brand_id=284865
Relevant excerpt from investigation:
Additional Notes
DD_ENV_TYPEis explicitly setDescribe how to test/QA your changes
Manual testing:
Run the mini agent without
DD_ENV_TYPESet
DD_ENV_TYPE=azurefunctionenv_typeis correctly overridden toAzureFunctionorigin:azurefunction,dd.origin:azurefunction
Set
DD_ENV_TYPE=cloudfunctionSet an invalid value (e.g.
DD_ENV_TYPE=unknown)Reproduce original issue scenario:
FUNCTION_NAMEin environmentDD_ENV_TYPE→ correct behaviorRegression safety: