Skip to content

[Shared] Refactor EnvironmentVariableScope#7175

Merged
martincostello merged 1 commit into
open-telemetry:mainfrom
martincostello:refactor-EnvironmentVariableScope
Apr 27, 2026
Merged

[Shared] Refactor EnvironmentVariableScope#7175
martincostello merged 1 commit into
open-telemetry:mainfrom
martincostello:refactor-EnvironmentVariableScope

Conversation

@martincostello
Copy link
Copy Markdown
Member

Changes

Copy from open-telemetry/opentelemetry-dotnet-contrib to support multiple variables without needing to allocator multiple scopes as I've found that need while working on #7168 and #7174.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Copy from open-telemetry/opentelemetry-dotnet-contrib to support multiple variables without needing to allocator multiple scopes.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry.Extensions.Hosting Issues related to OpenTelemetry.Extensions.Hosting NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Apr 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.06%. Comparing base (9b45df9) to head (ed8d682).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7175      +/-   ##
==========================================
- Coverage   89.08%   89.06%   -0.03%     
==========================================
  Files         271      271              
  Lines       13073    13073              
==========================================
- Hits        11646    11643       -3     
- Misses       1427     1430       +3     
Flag Coverage Δ
unittests-Project-Experimental 88.98% <ø> (-0.06%) ⬇️
unittests-Project-Stable 89.04% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 2 files with indirect coverage changes

@martincostello martincostello marked this pull request as ready for review April 26, 2026 12:01
@martincostello martincostello requested a review from a team as a code owner April 26, 2026 12:01
Copilot AI review requested due to automatic review settings April 26, 2026 12:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the test-only EnvironmentVariableScope helper to support setting/restoring multiple environment variables in a single scope, and updates impacted tests to use the new factory-based API.

Changes:

  • Replaced single-variable EnvironmentVariableScope ctor usage with EnvironmentVariableScope.Create(...) across several tests.
  • Refactored EnvironmentVariableScope to track and restore multiple variables.
  • Minor expression-bodied member cleanup in TracerProviderBuilderBaseTests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/OpenTelemetry.Tests/EnvironmentVariableScope.cs Refactors helper to support multiple env vars and adds Create factory overloads.
test/OpenTelemetry.Tests/Trace/TracerProviderBuilderBaseTests.cs Switches env var scoping to Create and simplifies helper methods.
test/OpenTelemetry.Tests/Metrics/MeterProviderBuilderBaseTests.cs Switches env var scoping to Create.
test/OpenTelemetry.Tests/Logs/LoggerProviderBuilderBaseTests.cs Switches env var scoping to Create.
test/OpenTelemetry.Extensions.Hosting.Tests/OpenTelemetryMetricsBuilderExtensionsTests.cs Switches env var scoping to Create for OTEL_SDK_DISABLED test.
test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpMetricsExporterTests.cs Switches env var scoping to Create for env-var-based configuration test.

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

Comment thread test/OpenTelemetry.Tests/EnvironmentVariableScope.cs
Comment thread test/OpenTelemetry.Tests/EnvironmentVariableScope.cs
@martincostello martincostello added this pull request to the merge queue Apr 27, 2026
Merged via the queue into open-telemetry:main with commit 0bfe8c7 Apr 27, 2026
61 checks passed
@martincostello martincostello deleted the refactor-EnvironmentVariableScope branch April 27, 2026 05:17
martincostello added a commit to martincostello/opentelemetry-dotnet that referenced this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry.Extensions.Hosting Issues related to OpenTelemetry.Extensions.Hosting NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants