Skip to content

fix(sdk): add validation for export_timeout_millis <= 0 in PeriodicExportingMetricReader - #5656

Open
Dotify71 wants to merge 5 commits into
open-telemetry:mainfrom
Dotify71:fix-periodic-metric-reader-timeout-validation
Open

Dotify71 wants to merge 5 commits into
open-telemetry:mainfrom
Dotify71:fix-periodic-metric-reader-timeout-validation

Conversation

@Dotify71

Copy link
Copy Markdown
Contributor

Description

Fixes #5655

Currently, PeriodicExportingMetricReader validates export_interval_millis during initialization and raises a ValueError if export_interval_millis <= 0. However, export_timeout_millis lacked validation for values <= 0, allowing non-positive integers (0 or negative values) to be passed without error.

Since _ticker() continuously calls self.collect(timeout_millis=self._export_timeout_millis), passing an unvalidated non-positive timeout causes collection timeout errors on every tick cycle.

This PR adds validation for export_timeout_millis <= 0 in PeriodicExportingMetricReader.__init__().

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit tests in opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py (test_timeout_value_exception_on_zero, test_timeout_value_exception_on_negative).

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@Dotify71
Dotify71 requested a review from a team as a code owner September 13, 2026 04:07
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 13, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-09-20 09:22 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Top-level threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@Dotify71

Copy link
Copy Markdown
Contributor Author

@lzchen This pr is ready for review

@herin049 herin049 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.

Thanks for the PR, if you have future small changes like these, please group them into a single PR.

@Dotify71

Copy link
Copy Markdown
Contributor Author

Thanks for the review and approval @herin049 I'll definitely group related small fixes into a single PR next time :))

@Shriprasad-P Shriprasad-P left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice focused PR. Please make sure docs/changelog stay aligned if the repo requires it for this kind of change.

@Dotify71
Dotify71 force-pushed the fix-periodic-metric-reader-timeout-validation branch from 7ab0768 to 3bdc868 Compare September 19, 2026 12:33
@Dotify71

Copy link
Copy Markdown
Contributor Author

All checks passed.... the pr is ready for review :))

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py Outdated
@Dotify71
Dotify71 requested a review from emdneto September 19, 2026 14:34
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py Outdated
Comment thread opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py Outdated

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.

Copilot review overview

🟢 Approval recommended

The validation is correct and adequately tested; the remaining error-message spacing issue is minor.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds positive-value validation for metric export timeouts.

Changes:

  • Rejects zero and negative export timeouts.
  • Adds focused unit tests.
  • Adds a changelog entry.
File Description
.changelog/​5656.fixed Records the fix.
opentelemetry-sdk/​src/​opentelemetry/​sdk/​metrics/​_internal/​export/​__init__.py Validates export timeout values.
opentelemetry-sdk/​tests/​metrics/​test_periodic_exporting_metric_reader.py Tests zero and negative timeout rejection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Dotify71
Dotify71 requested a review from herin049 September 20, 2026 08:29
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.

[bug] PeriodicExportingMetricReader missing validation for export_timeout_millis <= 0

5 participants