Skip to content

Add Azure Functions account and resource group attributes - #3092

Open
Lewis-E wants to merge 3 commits into
open-telemetry:mainfrom
Lewis-E:fix-azure-functions-resource-attributes
Open

Add Azure Functions account and resource group attributes#3092
Lewis-E wants to merge 3 commits into
open-telemetry:mainfrom
Lewis-E:fix-azure-functions-resource-attributes

Conversation

@Lewis-E

@Lewis-E Lewis-E commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description:

Update the Azure Functions resource detector to emit:

  • cloud.account.id - from the subscription portion of WEBSITE_OWNER_NAME before + - sem-conv, discussion
  • azure.resource_group.name - from WEBSITE_RESOURCE_GROUP - sem-conv, discussion
  • service.name - from WEBSITE_SITE_NAME - sem-conv

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

  • Unit Tests
  • Deployed a test app & confirmed the correct attributes were detected.
Screenshot 2026-09-03 at 7 28 38 AM

Documentation:

Updated:

  • azure-resources/README.md

Outstanding items: n/a

Signed-off-by: E. Lewis <7704925+Lewis-E@users.noreply.github.com>
@github-actions
github-actions Bot requested review from trask and zeitlinger September 2, 2026 17:08
@Lewis-E
Lewis-E marked this pull request as ready for review September 3, 2026 16:02
Copilot AI lite review requested due to automatic review settings September 3, 2026 16:02
@Lewis-E
Lewis-E requested a review from a team as a code owner September 3, 2026 16:02

Copilot AI left a comment

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.

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, and service.name for 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

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.

test updated

- 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants