Skip to content

Commit

Permalink
Removed responseBody() call in HttpExporter to allow clients to con…
Browse files Browse the repository at this point in the history
…sume it via FailedExportException
  • Loading branch information
jarrodrobins committed Aug 22, 2024
1 parent 033e919 commit b5557f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.exporter.internal.ExporterMetrics;
import io.opentelemetry.exporter.internal.FailedExportException;
import io.opentelemetry.exporter.internal.grpc.GrpcExporterUtil;
import io.opentelemetry.exporter.internal.marshal.Marshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;

/**
* An exporter for http/protobuf or http/json using a signal-specific Marshaler.
Expand Down Expand Up @@ -74,23 +71,13 @@ public CompletableResultCode export(T exportRequest, int numItems) {

exporterMetrics.addFailed(numItems);

byte[] body = null;
try {
body = httpResponse.responseBody();
} catch (IOException ex) {
logger.log(Level.FINE, "Unable to obtain response body", ex);
}

String status = extractErrorStatus(httpResponse.statusMessage(), body);

logger.log(
Level.WARNING,
"Failed to export "
+ type
+ "s. Server responded with HTTP status code "
+ statusCode
+ ". Error message: "
+ status);
+ ".");

result.failExceptionally(FailedExportException.httpFailedWithResponse(httpResponse));
},
Expand All @@ -116,15 +103,4 @@ public CompletableResultCode shutdown() {
}
return httpSender.shutdown();
}

private static String extractErrorStatus(String statusMessage, @Nullable byte[] responseBody) {
if (responseBody == null) {
return "Response body missing, HTTP status message: " + statusMessage;
}
try {
return GrpcExporterUtil.getStatusMessage(responseBody);
} catch (IOException e) {
return "Unable to parse response body, HTTP status message: " + statusMessage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,7 @@ void error() {

LoggingEvent log =
logs.assertContains(
"Failed to export "
+ type
+ "s. Server responded with HTTP status code 500. Error message:");
"Failed to export " + type + "s. Server responded with HTTP status code 500.");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}

Expand Down

0 comments on commit b5557f4

Please sign in to comment.