Skip to content

fix(config): allow deflate for OTLP HTTP exporters#5075

Open
officialasishkumar wants to merge 3 commits intoopen-telemetry:mainfrom
officialasishkumar:config-http-deflate
Open

fix(config): allow deflate for OTLP HTTP exporters#5075
officialasishkumar wants to merge 3 commits intoopen-telemetry:mainfrom
officialasishkumar:config-http-deflate

Conversation

@officialasishkumar
Copy link
Copy Markdown

Description

Fixes #5059

Map declarative OTLP compression values through a shared helper that recognizes Deflate when the target exporter enum supports it. This allows the tracer and meter OTLP HTTP exporters to accept compression: deflate without changing gRPC validation.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • /tmp/opentelemetry-python/.venv-codex/bin/python -m pytest opentelemetry-sdk/tests/_configuration/test_common.py opentelemetry-sdk/tests/_configuration/test_tracer_provider.py opentelemetry-sdk/tests/_configuration/test_meter_provider.py
  • /tmp/opentelemetry-python/.venv-codex/bin/python -m ruff check opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_common.py opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_tracer_provider.py opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_meter_provider.py opentelemetry-sdk/tests/_configuration/test_common.py opentelemetry-sdk/tests/_configuration/test_tracer_provider.py opentelemetry-sdk/tests/_configuration/test_meter_provider.py

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80ca78e192

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +62 to +63
if value.lower() == "deflate" and hasattr(compression_enum, "Deflate"):
return compression_enum.Deflate # type: ignore[attr-defined]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict deflate mapping to OTLP HTTP exporters

The shared mapper now returns Deflate for any enum that exposes that member, and both gRPC exporter builders (_create_otlp_grpc_span_exporter and _create_otlp_grpc_metric_exporter) call this helper, so declarative otlp_grpc.compression: deflate is now accepted. That changes prior validation behavior and creates a mismatch with the gRPC exporter’s own env parsing (environ_to_compression only accepts gzip/none), so users can get different accepted values depending on configuration path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Handled in 053503a by making deflate opt-in for the HTTP exporter call sites while the shared mapper still rejects it by default.

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Generally looks good, thanks @officialasishkumar.

I notice we haven't added deflate support for logs, in the logger provider - was that intentional? Could we add it too?


- `opentelemetry-sdk`: Add `service` resource detector support to declarative file configuration via `detection_development.detectors[].service`
([#5003](https://github.com/open-telemetry/opentelemetry-python/pull/5003))
- `opentelemetry-sdk`: Allow declarative OTLP HTTP exporters to map `compression: deflate` instead of rejecting it as unsupported
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- `opentelemetry-sdk`: Allow declarative OTLP HTTP exporters to map `compression: deflate` instead of rejecting it as unsupported
- `opentelemetry-sdk`: Allow declarative OTLP HTTP exporters to map `compression: deflate` instead of rejecting it as unsupported
([#5003](https://github.com/open-telemetry/opentelemetry-python/pull/5075))

if (
value.lower() == "deflate"
and allow_deflate
and hasattr(compression_enum, "Deflate")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should separate these checks. If the user sets allow_deflat=True but the compression_enum doesn't include Deflate, we return an error to indicate what compression types are available (eg "Supported values: 'gzip', 'none'").

With them separate, we can check if Deflate is avaiable and return an error with that instead.

"Install it with: pip install opentelemetry-exporter-otlp-proto-grpc"
) from exc

compression = _map_compression(config.compression, grpc.Compression)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I notice we're not setting allow_deflate=True for gprc - is that intentional?

@github-project-automation github-project-automation bot moved this to Reviewed PRs that need fixes in Python PR digest Apr 13, 2026


def _map_compression(
value: Optional[str],
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.

nit:

Suggested change
value: Optional[str],
value: str | None,

(and elsewhere in this PR)

):
return compression_enum.Deflate # type: ignore[attr-defined]

supported_values = ["'gzip'", "'none'"]
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 move this code to up towards the beginning of the function and update lines 66-68 to just check if value.lower() in supported_values.

Map declarative OTLP compression values through a shared helper that recognizes Deflate when the exporter enum supports it, while leaving gRPC validation unchanged.

Add regression coverage for the shared mapping helper plus tracer and meter provider HTTP exporter construction.
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar
Copy link
Copy Markdown
Author

Extended the declarative OTLP HTTP deflate handling to the logs path as well, updated the shared helper, and force-pushed the branch.

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

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

bug(config): _map_compression does not support deflate for HTTP exporters

3 participants