Skip to content

Use HTTP error bodies in HttpExporter warnings#8428

Open
ADITYA-CODE-SOURCE wants to merge 4 commits into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:issue-7704-http-exporter-warning
Open

Use HTTP error bodies in HttpExporter warnings#8428
ADITYA-CODE-SOURCE wants to merge 4 commits into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:issue-7704-http-exporter-warning

Conversation

@ADITYA-CODE-SOURCE
Copy link
Copy Markdown
Contributor

Fixes #7704.

Why

  • HttpExporter currently tries to parse every non-success HTTP response body as a serialized gRPC status.
  • When a custom server returns a JSON error body instead, export failure is reported correctly, but the warning text degrades to Unable to parse response body, which is noisy and hides the actual server response.

What

  • keep gRPC status parsing for responses that contain a serialized gRPC status body
  • fall back to logging the UTF-8 response body text when parsing fails
  • fall back to the HTTP status message when the body is empty
  • add a targeted test covering a JSON error response body

Testing

  • ./gradlew --no-daemon --max-workers=1 -Dorg.gradle.jvmargs="-Xmx768m -XX:MaxMetaspaceSize=256m" :exporters:common:test --tests io.opentelemetry.exporter.internal.http.HttpExporterTest
  • ./gradlew --no-daemon --max-workers=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:MaxMetaspaceSize=192m" :exporters:common:spotlessCheck

@ADITYA-CODE-SOURCE ADITYA-CODE-SOURCE requested a review from a team as a code owner May 27, 2026 14:17
Copy link
Copy Markdown
Contributor

@psx95 psx95 left a comment

Choose a reason for hiding this comment

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

This PR improves the default parsing experience of gRPC errors in HttpExporters by converting the raw bytes to a UTF-8 string as a fallback.

Looking at the original issue #7704 - the original ask was for a way to suppress the noisy logs - this PR makes the logs helpful, but does not suppress it - which IMO is ok (IIUC, a decision was not taken on it), but I'll defer to the maintainers here.

@@ -32,6 +34,7 @@
*/
@SuppressWarnings("checkstyle:JavadocMethod")
public final class HttpExporter {
private static final int MAX_RESPONSE_BODY_LOG_LENGTH = 1024;
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.

QQ: Why was this number chosen?

return "Response body missing, HTTP status message: " + statusMessage;
}
if (responseBody.length == 0) {
return "HTTP status message: " + statusMessage;
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: could add a better message indicating this is a length = 0 case.

Something like "Response body has 0 length, HTTP status message: "

}

private static String extractResponseBodyMessage(byte[] responseBody, String statusMessage) {
String responseBodyText = new String(responseBody, StandardCharsets.UTF_8).trim();
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: Minor improvement:

 int lengthToRead = Math.min(responseBody.length, MAX_RESPONSE_BODY_LOG_LENGTH);
 String responseBodyText = new String(responseBody, 0, lengthToRead, StandardCharsets.UTF_8).trim();

@ADITYA-CODE-SOURCE ADITYA-CODE-SOURCE force-pushed the issue-7704-http-exporter-warning branch from a12e8d8 to fff6013 Compare May 29, 2026 16:51
@ADITYA-CODE-SOURCE
Copy link
Copy Markdown
Contributor Author

ADITYA-CODE-SOURCE commented May 29, 2026

@psx95 Addressed the nits — bounded decoding, zero-length message, 1024 comment, and rebased onto latest main. I relied on CI for post-rebase verification since Gradle won't start locally due to paging-file limits.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.03%. Comparing base (2f1d950) to head (29c06ac).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8428      +/-   ##
============================================
+ Coverage     90.96%   91.03%   +0.06%     
- Complexity     7809     7824      +15     
============================================
  Files           892      893       +1     
  Lines         23702    23729      +27     
  Branches       2361     2366       +5     
============================================
+ Hits          21561    21602      +41     
+ Misses         1420     1408      -12     
+ Partials        721      719       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Suppression of warning log in extractErrorStatus in HttpExporter.java

2 participants