[receiver/otlpreceiver] errorHandler returns 500 when Content-Type is unsupported or malformed
Component(s)
No response
Describe the issue you're reporting
Describe the bug
errorHandler in receiver/otlpreceiver/otlphttp.go encodes the error Status using the
request's Content-Type. When that type is neither protobuf nor JSON — unsupported (text/plain) or malformed (application/) — it drops the original status code and writes 500 {"code": 13, "message": "failed to marshal error message"}. Client errors such as a 401 from an auth extension are reported as server faults, so clients retry requests that can never succeed.
Steps to reproduce
Collector with the OTLP receiver and an authenticator on the HTTP endpoint:
curl -i -X POST localhost:4318/v1/traces \
-H 'Content-Type: text/plain' \
-H 'Authorization: Bearer auth_thisisnotarealtoken' \
--data-binary ''What did you expect to see?
401 Unauthorized, status message encoded as JSON.
What did you see instead?
500 Internal Server Error with {"code": 13, "message": "failed to marshal error message"}.
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.
Source: open-telemetry/opentelemetry-collector