Skip to content

Prioritize deployment environment set in OTEL_RESOURCE_ATTRIBUTES#3405

Open
scottrudy wants to merge 6 commits into
Azure:mainfrom
scottrudy:scottrudy/stop-otel-env-override
Open

Prioritize deployment environment set in OTEL_RESOURCE_ATTRIBUTES#3405
scottrudy wants to merge 6 commits into
Azure:mainfrom
scottrudy:scottrudy/stop-otel-env-override

Conversation

@scottrudy

Copy link
Copy Markdown

Further enhances the isolated worker's FunctionsResourceDetector and the changes made in #3362.

FunctionsResourceDetector

The attribute deployment.environment.name now follows priority order (Azure only):

  • OTEL_RESOURCE_ATTRIBUTES[deployment.environment.name] or OTEL_RESOURCE_ATTRIBUTES[deployment.environment] →
    WEBSITE_SLOT_NAME.
  • When a higher-priority source is present the detector skips adding deployment.environment.name, letting the OTel SDK pick it up instead.

Issue describing the changes in this PR

resolves #3404

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

Copilot AI review requested due to automatic review settings May 6, 2026 20:24

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.

Pull request overview

Updates the isolated worker OpenTelemetry FunctionsResourceDetector so that deployment.environment.name is not overwritten when a higher-priority value is already provided via OTEL_RESOURCE_ATTRIBUTES, aligning behavior with the intended priority order in Azure environments.

Changes:

  • Skip adding deployment.environment.name from WEBSITE_SLOT_NAME when OTEL_RESOURCE_ATTRIBUTES contains deployment.environment.name or deployment.environment.
  • Add a semantic convention constant for deployment.environment to support the new priority check.
  • Add/adjust tests and update OpenTelemetry package release notes for the behavior change.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
test/DotNetWorker.OpenTelemetry.Tests/EndToEndTests.cs Adds test coverage for skipping deployment.environment.name when configured via OTEL_RESOURCE_ATTRIBUTES (currently contains issues).
src/DotNetWorker.OpenTelemetry/ResourceSemanticConventions.cs Adds deployment.environment constant to support priority checking.
src/DotNetWorker.OpenTelemetry/release_notes.md Documents the updated detector behavior and references #3404.
src/DotNetWorker.OpenTelemetry/FunctionsResourceDetector.cs Implements the priority/skip logic for deployment environment attributes (Azure-only).

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

Comment thread test/DotNetWorker.OpenTelemetry.Tests/EndToEndTests.cs Outdated
Comment thread test/DotNetWorker.OpenTelemetry.Tests/EndToEndTests.cs Outdated
Comment thread test/DotNetWorker.OpenTelemetry.Tests/EndToEndTests.cs Outdated
Comment thread src/DotNetWorker.OpenTelemetry/FunctionsResourceDetector.cs Outdated
@jviau jviau requested a review from RohitRanjanMS May 11, 2026 15:43
{
attributes.Add(new(ResourceSemanticConventions.DeploymentEnvironmentName, slot));
attributes.Add(new(ResourceSemanticConventions.DeploymentEnvironmentName, slot));

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.

Remove trailing spaces.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed

public static IEnumerable<object[]> EnvironmentNameSkippedData =>
[
// OTEL_RESOURCE_ATTRIBUTES[deployment.environment.name] set in Azure
[new Dictionary<string, string> { { "WEBSITE_SITE_NAME", "appName" }, { "WEBSITE_SLOT_NAME", "staging" }, { "OTEL_RESOURCE_ATTRIBUTES", "deployment.environment.name=custom-name,other.key=value" } }],

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.

Add tests for deployment.environment.name and deployment.environment with empty values. If a user accidentally sets an empty value, the slot name gets silently skipped.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call out. Explicit tests have been added.

@RohitRanjanMS

Copy link
Copy Markdown
Member

@scottrudy, thanks for putting in the time to create this PR. Really appreciate you doing it.

@scottrudy scottrudy requested a review from RohitRanjanMS May 23, 2026 17:28
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.

Azure Function Defaults override deployment.environment.name in OTEL_RESOURCE_ATTRIBUTES

4 participants