Skip to content

fix_otlp_timeout_parsing_fallback - #5448

Open
Eason09053360 wants to merge 3 commits into
open-telemetry:mainfrom
Eason09053360:fix-otlp-env-timeout-fallback
Open

fix_otlp_timeout_parsing_fallback#5448
Eason09053360 wants to merge 3 commits into
open-telemetry:mainfrom
Eason09053360:fix-otlp-env-timeout-fallback

Conversation

@Eason09053360

@Eason09053360 Eason09053360 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

The OTLP exporters parse their timeout env vars with a bare float() in __init__, so an invalid value like OTEL_EXPORTER_OTLP_TIMEOUT=10s— or a declared-but-empty variable — raises ValueError during exporter construction and takes down SDK startup.

This adds a shared _timeout_from_env() helper in opentelemetry-exporter-otlp-proto-common that warns and falls back to the default instead, matching how the repo already handles invalid temporality and export-interval values. Applied to all six call sites (HTTP trace/metric/log, gRPC mixin, gRPC trace/metric/log); precedence is unchanged.

Also fixes timeout or ... silently discarding an explicit timeout=0; it is now timeout is not None.

Type of change

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

How Has This Been Tested?

bashuv run --with pytest pytest exporter/opentelemetry-exporter-otlp-proto-common/tests/ -q   # 26 passed
uv run --with pytest pytest exporter/opentelemetry-exporter-otlp-proto-http/tests/ -q     # 62 passed
uv run --with pytest pytest exporter/opentelemetry-exporter-otlp-proto-grpc/tests/ -q     # 70 passed
uv run --with ruff ruff check <the three packages>                                        # clean
uv run --with ruff ruff format --check <the three packages>                               # clean

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

@Eason09053360
Eason09053360 marked this pull request as ready for review July 20, 2026 13:11
@Eason09053360
Eason09053360 requested a review from a team as a code owner July 20, 2026 13:11
return float(value)
except ValueError:
_logger.warning(
"Invalid value %r for %s, ignoring it.", value, environ_key

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.

Can we rephrase this a bit, and include the name of the environment variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can we rephrase this a bit, and include the name of the environment variable?

Thanks for reviewing!

applied It is clearer now.


class TestTimeoutFromEnv(unittest.TestCase):
@patch.dict("os.environ", {"TEST_TIMEOUT": "15"})
def test_valid_value(self):

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.

We can probably combine all of these tests into a single parameterized test.

@Eason09053360
Eason09053360 force-pushed the fix-otlp-env-timeout-fallback branch from 3baee13 to 76c758f Compare July 24, 2026 00:59
@xrmx xrmx moved this to Ready for review in Python PR digest Jul 24, 2026
- Clarify the invalid-value warning by spelling out "environment
  variable" instead of a bare %s substitution.
- Combine test_valid_value/test_unset_returns_default/
  test_empty_value_returns_default into a single table-driven
  test_simple_cases using subTest.
@Eason09053360
Eason09053360 force-pushed the fix-otlp-env-timeout-fallback branch from 76c758f to 5285f88 Compare August 1, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

3 participants