Skip to content

Conversation

mathieurobin1
Copy link
Contributor

@mathieurobin1 mathieurobin1 commented Jul 17, 2025

Fixes #3515

Changes

Implements the configuration of PeriodicExportingMetricReader via environment variables with default values.

It introduces support for:

  • OTEL_METRIC_EXPORT_INTERVAL (Duration)
  • OTEL_METRIC_EXPORT_TIMEOUT (Timeout)

Known Limitation / Discussion Point:

During implementation, I identified that the existing utility function common::GetDurationEnvironmentVariable is not fully compliant with the specification for Timeout types.

  • Specification: A Timeout value of 0 SHOULD be interpreted as "infinite".
  • Current Implementation: The underlying parser (GetTimeoutFromString) explicitly rejects a value of 0 as invalid.

To keep the scope of this PR focused on the PeriodicExportingMetricReaderOptions, I have used the existing utility for both environment variables. This means that OTEL_METRIC_EXPORT_TIMEOUT=0 is currently not handled as an infinite timeout but will instead fall back to the default value.

I believe fixing the common utility function should be addressed in a separate issue/PR to ensure it doesn't introduce unintended side effects elsewhere.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@mathieurobin1 mathieurobin1 requested a review from a team as a code owner July 17, 2025 18:41
Copy link

linux-foundation-easycla bot commented Jul 17, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: mathieurobin1 / name: Mathieu Robin (2b44323, a1311d1)
  • ✅ login: marcalff / name: Marc Alff (10c5437)

Copy link

netlify bot commented Jul 17, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 2b44323
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/687aae453e11530008f10b3e

@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch 2 times, most recently from b0aea62 to 4c3e120 Compare July 17, 2025 18:54
@marcalff marcalff changed the title [CONFIGURATION] Implement env var configuration for PeriodicExportingMetricReader [SDK] Implement env var configuration for PeriodicExportingMetricReader Jul 17, 2025
@marcalff
Copy link
Member

I changed the title to [SDK], because I use the [CONFIGURATION] tag is for everything related to declarative configuration (aka, config.yaml)

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, see minor comments.

@marcalff
Copy link
Member

Known Limitation / Discussion Point:

During implementation, I identified that the existing utility function common::GetDurationEnvironmentVariable is not fully compliant with the specification for Timeout types.

* **Specification:** A `Timeout` value of `0` SHOULD be interpreted as "infinite".

* **Current Implementation:** The underlying parser (`GetTimeoutFromString`) explicitly rejects a value of `0` as invalid.

To keep the scope of this PR focused on the PeriodicExportingMetricReaderOptions, I have used the existing utility for both environment variables. This means that OTEL_METRIC_EXPORT_TIMEOUT=0 is currently not handled as an infinite timeout but will instead fall back to the default value.

I believe fixing the common utility function should be addressed in a separate issue/PR to ensure it doesn't introduce unintended side effects elsewhere.

Looks like you found an existing bug.

Please use common::GetDurationEnvironmentVariable so that all duration variables have the same behavior, instead of having multiple and slightly different helpers.

The issue with 0 / infinite can be fixed separately.

@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch from 71bfae5 to a1311d1 Compare July 17, 2025 22:51
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.00%. Comparing base (5423b91) to head (2b44323).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3549      +/-   ##
==========================================
+ Coverage   89.99%   90.00%   +0.02%     
==========================================
  Files         219      220       +1     
  Lines        7048     7056       +8     
==========================================
+ Hits         6342     6350       +8     
  Misses        706      706              
Files with missing lines Coverage Δ
...export/periodic_exporting_metric_reader_options.cc 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcalff
Copy link
Member

The include-what-you-use failures can be seen in CI, go to "Summary" for the CI job, and download artifacts that contains the full logs.

Search for Warning: include-what-you-use reported diagnostics.

Logs provided below


/home/runner/work/opentelemetry-cpp/opentelemetry-cpp/sdk/test/metrics/periodic_exporting_metric_reader_test.cc should add these lines:
#include <stdlib.h>
#include <ratio>

Also, there is a build break for tests on Windows. See existing tests for how to use setenv.

@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch from c919c83 to 755345a Compare July 18, 2025 10:39
@mathieurobin1
Copy link
Contributor Author

Thanks for your feedback, forgot to include env_variables.h for Windows build.
Should be good now :)

@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch from 755345a to 34b1f06 Compare July 18, 2025 16:04
Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks.

@marcalff
Copy link
Member

Build failure in windows CI:

metrics_ostream.obj : error LNK2019: unresolved external symbol "public: __cdecl opentelemetry::v1::sdk::metrics::PeriodicExportingMetricReaderOptions::PeriodicExportingMetricReaderOptions(void)" (??0PeriodicExportingMetricReaderOptions@metrics@sdk@v1@opentelemetry@@QEAA@XZ) referenced in function "void __cdecl `anonymous namespace'::InitMetrics(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?InitMetrics@?A0x81c1a3c3@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) [D:\a\opentelemetry-cpp\opentelemetry-cpp\build\install_test\examples-test\examples\metrics_simple\metrics_ostream_example.vcxproj]

To fix it:

  • add OPENTELEMETRY_EXPORT, see file otlp_http_metric_exporter_options.h for an example
  • adjust ext/src/dll/input.src if necessary

Since a new patch is needed to fix this, I am adding minor nitpicks as well.

Code looks good overall, will approve once CI is clean.

Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM overall.

Thanks for the fix, will approve once CI is clean.

@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch from 34b1f06 to 0076eef Compare July 18, 2025 20:23
@mathieurobin1 mathieurobin1 force-pushed the feature/periodic-metric-reader-env-config branch from 0076eef to 2b44323 Compare July 18, 2025 20:27
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM.

Thanks for the fix, and the misc cleanup.

@marcalff marcalff merged commit 93475ff into open-telemetry:main Jul 18, 2025
70 checks passed
@marcalff
Copy link
Member

@mathieurobin1 Congratulations on your first patch. Merged.

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.

Support periodic exporting MetricReader config from env vars

3 participants