Skip to content

fix(exporter/otlp/http): log error details from response on export failure#5155

Draft
grvmishra788 wants to merge 1 commit intoopen-telemetry:mainfrom
grvmishra788:worktree-issue-4526
Draft

fix(exporter/otlp/http): log error details from response on export failure#5155
grvmishra788 wants to merge 1 commit intoopen-telemetry:mainfrom
grvmishra788:worktree-issue-4526

Conversation

@grvmishra788
Copy link
Copy Markdown

@grvmishra788 grvmishra788 commented Apr 27, 2026

Description

Fixes #4526.

Before: When an OTLP HTTP export fails (non-2xx response), all three exporters (trace, metrics, logs) log only resp.reason — the HTTP reason phrase (e.g. "Bad Request"). The response body is never read, so server-provided error details (e.g. a protobuf-encoded error from telemetry.googleapis.com) are silently discarded.

After: On a non-2xx response, exporters parse the body using the Content-Type header before logging:

Content-Type Behaviour
application/x-protobuf Deserialise as Export*ServiceResponse; extract partial_success.error_message
application/json Parse JSON; extract partialSuccess.errorMessage or message (google.rpc.Status)
Unknown or missing Return resp.text
Empty body or parse failure Return resp.reason (previous behaviour, unchanged)

Type of change

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

How Has This Been Tested?

The fix was verified end-to-end by constructing a 400 response with a protobuf-encoded ExportTraceServiceResponse body (containing partial_success.error_message = "Request contains too many spans (limit: 10000)") and a mocked OTLP endpoint (via the responses library). Before the fix, the logged reason was "Bad Request"; after, it is the server-provided message. The same was confirmed for a JSON google.rpc.Status body and for an empty body (fallback to resp.reason, no regression).

Run from the repo root:

pytest exporter/opentelemetry-exporter-otlp-proto-http/tests/test_response_body_parsing.py \
       exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py \
       exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py
  • 11 unit tests in test_response_body_parsing.py — cover every branch of _parse_response_body: protobuf with/without error message, JSON partialSuccess and message fields, ; charset=utf-8 content-type variants, unknown content-type, empty body, malformed protobuf, malformed JSON.
  • 3 integration tests in test_proto_span_exporter.py and test_proto_log_exporter.py — verify the parsed message appears in the error log on a real export call.
  • All 41 tests pass; pylint 10.00/10.

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

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.

OTLP HTTP Exporter Should Parse response based on content-type header

1 participant