Add Azure Functions account and resource group attributes - #3092
Conversation
Signed-off-by: E. Lewis <7704925+Lewis-E@users.noreply.github.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
This PR updates the Azure Functions resource detector to emit additional Azure environment metadata (subscription/account, resource group, service name, slot) and aligns parsing/building behavior with the Azure App Service pattern introduced in #3074.
Changes:
- Emit
cloud.account.id,azure.resource_group.name,cloud.resource_id,deployment.environment.name, andservice.namefor Azure Functions when corresponding env vars are present. - Reuse Azure App Service resource ID builder and promote a couple of App Service helpers to package scope.
- Extend unit tests and documentation to cover the new attributes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureFunctionsResourceProvider.java | Adds parsing of subscription/resource group/slot and emits new semantic attributes for Functions. |
| azure-resources/src/main/java/io/opentelemetry/contrib/azure/resource/AzureAppServiceResourceProvider.java | Exposes slot name and resource ID builder for reuse by Functions provider. |
| azure-resources/src/test/java/io/opentelemetry/contrib/azure/resource/AzureFunctionsResourceProviderTest.java | Adds test coverage for new attributes and “missing env var” scenarios. |
| azure-resources/README.md | Documents the newly detected attributes for Azure Functions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| .doesNotContainKey(CLOUD_RESOURCE_ID); | ||
| } | ||
|
|
||
| @Test |
- Extract shared package-private subscriptionId(env) helper and expose WEBSITE_OWNER_NAME/WEBSITE_RESOURCE_GROUP constants in AzureAppServiceResourceProvider; reuse them from AzureFunctionsResourceProvider to eliminate duplicated parsing logic. - Replace io.opentelemetry.api.internal.StringUtils (internal API) with standard Java null/empty checks. - Return null from subscriptionId when WEBSITE_OWNER_NAME lacks the '+' delimiter or has an empty subscription segment, so cloud.account.id and cloud.resource_id are not emitted from an invalid/unreliable value. - Add Azure Functions tests for malformed WEBSITE_OWNER_NAME (no '+', '+' at index 0, empty subscription segment) and update App Service tests to use a realistic owner name with the '+' delimiter.
| String resourceUri = | ||
| AzureAppServiceResourceProvider.resourceUri(name, websiteResourceGroup, subscriptionId); | ||
| if (resourceUri != null) { | ||
| builder.put(CLOUD_RESOURCE_ID, resourceUri); |
There was a problem hiding this comment.
Do you think this language applies, about MUST use a span attribute?
- Azure: The Fully Qualified Resource ID of the invoked function, not the function app, having the form
/subscriptions/<SUBSCRIPTION_GUID>/resourceGroups/<RG>/providers/Microsoft.Web/sites/<FUNCAPP>/functions/<FUNC>.
This means that a span attribute MUST be used, as an Azure function app can host multiple functions that would usually share a TracerProvider.
Description:
Update the Azure Functions resource detector to emit:
cloud.account.id- from the subscription portion ofWEBSITE_OWNER_NAMEbefore+- sem-conv, discussionazure.resource_group.name- fromWEBSITE_RESOURCE_GROUP- sem-conv, discussionservice.name- fromWEBSITE_SITE_NAME- sem-convGoal: Align the Java Azure Functions detector with Azure environment metadata mapping and the Java Azure App Service parsing/building pattern added in #3074.
AI Disclosure: Pi Coding Agent was used to draft this PR, but I wrote this PR description and can explain all changes.
Existing Issue(s): n/a
Testing:
Documentation:
Updated:
azure-resources/README.mdOutstanding items: n/a