Skip to content

feat: Add gzip/deflate Content-Encoding support to OTLP traces endpoint#19024

Merged
harupy merged 10 commits intomlflow:masterfrom
Miaoxiang-philips:patch-2
Nov 27, 2025
Merged

feat: Add gzip/deflate Content-Encoding support to OTLP traces endpoint#19024
harupy merged 10 commits intomlflow:masterfrom
Miaoxiang-philips:patch-2

Conversation

@Miaoxiang-philips
Copy link
Contributor

@Miaoxiang-philips Miaoxiang-philips commented Nov 25, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19024/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19024/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19024/merge

Related Issues/PRs

Related #18613

What changes are proposed in this pull request?

MLflow's OTLP/HTTP traces ingestion currently does not support any compression format.
OpenTelemetry Collector sends OTLP/HTTP requests using gzip compression by default, which causes MLflow to return:

error": "not retryable error: Permanent error: rpc error: code = InvalidArgument desc = error exporting items, request to http://host.docker.internal:5000/v1/traces responded with HTTP Status Code 400", "dropped_items": 1}

This PR adds support for the required OTLP/HTTP compression encodings:

  • gzip (required by OTLP specification)
  • deflate
  • identity (default)

The server now automatically decompresses the request body before parsing the protobuf payload. This makes MLflow compatible with all standard OTLP/HTTP exporters without requiring the user to disable compression.

This change does not affect any existing functionality and maintains full backward compatibility.

Reproduce steps:

  1. prepare opentelemetry-collector.yaml:
receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

exporters:
  otlphttp:
    endpoint: http://host.docker.internal:5000 # if running otel collector by docker, This can be connect to localhost:5000
    headers:
      x-mlflow-experiment-id: "0" # default id

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [otlphttp]
  1. start otel collector by docker
docker run --name otel-collector -d -p 4318:4318 -v $(pwd)/opentelemetry-collector.yaml:/etc/otel/collector/config.yam otel/opentelemetry-collector-contrib # latest tag or 0.139.0(in my environment)
  1. send data with otlp

If you don't have a ready-made method, you can use telemetrygen to simulate data transmission, for example:

telemetrygen traces \
  --otlp-http http://localhost:4318 \
  --rate 10 \
  --duration 30s \
  --otlp-insecure

telemetrygen download link: telemetrygen package

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.

What is a minor/patch release?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

@github-actions github-actions bot added v3.6.1 area/tracing MLflow Tracing and its integrations rn/bug-fix Mention under Bug Fixes in Changelogs. labels Nov 25, 2025
Miaoxiang-philips and others added 2 commits November 26, 2025 11:20
Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
- Extract Content-Encoding decompression logic into `decompress_otlp_body` helper in `mlflow/tracing/utils/otlp.py`
- Support identity, gzip, and deflate encodings using pattern match (Python 3.10+)
- Simplify handler by delegating decompression to helper
- Improves maintainability and allows future reuse for other OTLP endpoints

Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
@Miaoxiang-philips
Copy link
Contributor Author

Hi @harupy , Thank you for your comments. I have made some adjustments. Please review again

Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

Documentation preview for 8f09079 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Miaoxiang-philips and others added 2 commits November 26, 2025 12:10
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
Removed docstring comments from test functions for clarity.

Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
Miaoxiang-philips and others added 3 commits November 26, 2025 12:51
Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
- Parameterize compression tests to cover multiple encodings (identity, gzip, deflate-rfc, deflate-raw)
- Parameterize error tests to cover invalid data for each encoding type
- Add type hints to test functions for better code clarity
- Use pytest 8.4+ check parameter for cleaner exception validation
- Increase test coverage from 3 to 7 test cases

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

LGTM!

@harupy
Copy link
Member

harupy commented Nov 26, 2025

@Miaoxiang-philips I've pushed a commit. Can you take a look and make sure everything looks ok?

@Miaoxiang-philips
Copy link
Contributor Author

@Miaoxiang-philips I've pushed a commit. Can you take a look and make sure everything looks ok?

I've checked it, and it's fine for me.

@harupy
Copy link
Member

harupy commented Nov 26, 2025

@Miaoxiang-philips Thanks for the confirmation. I wonder if we could add a lightweight integration test (that can reproducer the error on master but works on this PR) using docker (or anything that could've detected the error)

@Miaoxiang-philips
Copy link
Contributor Author

@Miaoxiang-philips Thanks for the confirmation. I wonder if we could add a lightweight integration test (that can reproducer the error on master but works on this PR) using docker (or anything that could've detected the error)

Sure, but I couldn't find anything related to integration testing in CONTRIBUTING.md. Could you give me some help information?

If you are only concerned about whether the change is reasonable, I can provide more information:

otel collector uses zip as compression by default when use otlphttp exporter, unless explicitly declared as none: otlphttpexporter

Generally, the /v1/traces endpoint needs to handle at least zip compression, which is quite normal

@harupy
Copy link
Member

harupy commented Nov 26, 2025

@Miaoxiang-philips Thanks for the reply! Could you share the steps to reproduce the error? I’ll turn them into a test case.

@Miaoxiang-philips
Copy link
Contributor Author

Sure, I updated to the description of PR @harupy

@harupy
Copy link
Member

harupy commented Nov 27, 2025

@Miaoxiang-philips Thanks! I think I'm missing something. I ran uv run mlflow server (on master ) and follow the steps you shared but could not reproduce the error.


http://localhost:55679/debug/tracez:

image

Never mind, I was able to reproduce the error.

@harupy
Copy link
Member

harupy commented Nov 27, 2025

Awesome, manually confirmed it works!

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
"""
from fastapi import HTTPException, status

match content_encoding:
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@harupy harupy Nov 27, 2025

Choose a reason for hiding this comment

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

I tested '' (empty string), 'none', and null. content_encoding is None for all of them.

receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

exporters:
  otlphttp:
    endpoint: http://host.docker.internal:5000 # if running otel collector by docker, This can be connect to localhost:5000
    compression: ... 👈
    headers:
      x-mlflow-experiment-id: "0" # default id

service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [otlphttp]

@harupy harupy added v3.7.0 and removed v3.6.1 labels Nov 27, 2025
@harupy harupy enabled auto-merge November 27, 2025 11:19
@harupy harupy added this pull request to the merge queue Nov 27, 2025
Merged via the queue into mlflow:master with commit 4fab98a Nov 27, 2025
52 checks passed
@B-Step62 B-Step62 mentioned this pull request Dec 3, 2025
29 tasks
BenWilson2 pushed a commit to BenWilson2/mlflow that referenced this pull request Dec 4, 2025
…nt (mlflow#19024)

Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Co-authored-by: miaoxiang.wang <miaoxiang.wang.extern@porsche.digital>
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Co-authored-by: harupy <17039389+harupy@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
BenWilson2 pushed a commit that referenced this pull request Dec 4, 2025
…nt (#19024)

Signed-off-by: Miaoxiang <zs1030823169@gmail.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Co-authored-by: miaoxiang.wang <miaoxiang.wang.extern@porsche.digital>
Co-authored-by: Harutaka Kawamura <hkawamura0130@gmail.com>
Co-authored-by: harupy <17039389+harupy@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/tracing MLflow Tracing and its integrations rn/bug-fix Mention under Bug Fixes in Changelogs. v3.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants