Skip to content

Conversation

@rajkumar-rangaraj
Copy link
Member

Fixes #4153

Changes

This PR implements support for the OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION environment variable as specified in the OpenTelemetry specification.

Key Implementation Details

  • Internal API only: All new types and properties are marked internal to avoid expanding the public API surface
  • Spec-compliant parsing: Uses direct string comparison (case-insensitive) to validate against spec-defined snake_case values:
    • explicit_bucket_histogram (default)
    • base2_exponential_bucket_histogram
  • View precedence: Explicit views configured via AddView take precedence over the default aggregation setting
  • Applied in both code paths: Default aggregation is applied whether or not views are configured, ensuring consistent behavior

Implementation Components

  1. MetricReaderHistogramAggregation (internal enum): Represents the two valid histogram aggregation types
  2. MetricReaderOptions.DefaultHistogramAggregation (internal property): Stores the configured default
  3. OtlpServiceCollectionExtensions: Parses the environment variable/configuration and sets the property
  4. MetricReaderExt.CreateDefaultHistogramConfiguration: Helper method that applies the default to histogram instruments
  5. Test coverage: 11 new tests covering environment variables, IConfiguration, view overrides, and edge cases

Testing

All existing tests pass (524/528), with 4 unrelated failures in other areas. New tests added:

  • Configuration-based parsing
  • Environment variable parsing
  • Application to histogram instruments
  • View override behavior
  • Invalid value handling

Documentation

  • Updated README.md with environment variable documentation
  • Updated CHANGELOG.md with feature description

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)

@rajkumar-rangaraj rajkumar-rangaraj requested a review from a team as a code owner December 16, 2025 18:47
@github-actions github-actions bot added pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Dec 16, 2025
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.77%. Comparing base (fe9e62d) to head (860765c).
⚠️ Report is 11 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/OpenTelemetry/Metrics/Reader/MetricReaderExt.cs 92.85% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6778      +/-   ##
==========================================
+ Coverage   86.69%   86.77%   +0.08%     
==========================================
  Files         262      262              
  Lines       12320    12350      +30     
==========================================
+ Hits        10681    10717      +36     
+ Misses       1639     1633       -6     
Flag Coverage Δ
unittests-Project-Experimental 86.42% <96.77%> (-0.22%) ⬇️
unittests-Project-Stable 86.68% <96.77%> (-0.01%) ⬇️
unittests-Solution 86.75% <96.77%> (+0.12%) ⬆️
unittests-UnstableCoreLibraries-Experimental 86.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
.../Implementation/OtlpServiceCollectionExtensions.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Metrics/Reader/MetricReader.cs 89.47% <100.00%> (+0.07%) ⬆️
...penTelemetry/Metrics/Reader/MetricReaderOptions.cs 100.00% <100.00%> (ø)
...rc/OpenTelemetry/Metrics/Reader/MetricReaderExt.cs 92.00% <92.85%> (+0.03%) ⬆️

... and 7 files with indirect coverage changes

@rajkumar-rangaraj rajkumar-rangaraj added this pull request to the merge queue Dec 19, 2025
Merged via the queue into open-telemetry:main with commit 39cf140 Dec 19, 2025
85 checks passed
@rajkumar-rangaraj rajkumar-rangaraj deleted the rajrang/fix4153 branch December 19, 2025 18:38
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 Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION

2 participants