Skip to content

[bug] PeriodicExportingMetricReader missing validation for export_timeout_millis <= 0 #5655

Description

@Dotify71

Describe your environment

OS: macOS / Linux
Python version: 3.10+
SDK version: main

What happened?

In opentelemetry-sdk (opentelemetry.sdk.metrics.export.PeriodicExportingMetricReader), export_interval_millis validates that its value is positive and raises a ValueError if export_interval_millis <= 0.

However, export_timeout_millis lacks validation for non-positive or negative values (<= 0). Initializing PeriodicExportingMetricReader(ConsoleMetricExporter(), export_timeout_millis=-1) or export_timeout_millis=0 is accepted without raising a ValueError.

Since _ticker() continuously calls self.collect(timeout_millis=self._export_timeout_millis), an unvalidated non-positive timeout value is passed into metric collection on every tick.

Steps to Reproduce

from opentelemetry.sdk.metrics.export import (
ConsoleMetricExporter,
PeriodicExportingMetricReader,
)

1. export_interval_millis correctly validates <= 0:

try:
PeriodicExportingMetricReader(
ConsoleMetricExporter(), export_interval_millis=0
)
except ValueError as e:
print("export_interval_millis validation working:", e)

2. export_timeout_millis lacks validation:

reader = PeriodicExportingMetricReader(
ConsoleMetricExporter(), export_timeout_millis=-1
)
print("Accepted without ValueError! actual=", reader._export_timeout_millis)

Expected Result

Initializing PeriodicExportingMetricReader with export_timeout_millis <= 0 should raise a ValueError (e.g. f"timeout value {self._export_timeout_millis} is invalid and needs to be larger than zero."), consistent with export_interval_millis.

Actual Result

Accepted without raising a ValueError.

Additional context

Location: opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py around lines 451-482.

I am opening a PR for this fix :))

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions