Skip to content

Commit f8704d5

Browse files
committed
protect agains exception on gRPC response
1 parent 99ccb1f commit f8704d5

File tree

1 file changed

+25
-2
lines changed
  • extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/sender

1 file changed

+25
-2
lines changed

extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/exporter/otlp/sender/VertxGrpcSender.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import io.quarkus.vertx.core.runtime.BufferOutputStream;
2828
import io.smallrye.common.annotation.SuppressForbidden;
2929
import io.smallrye.mutiny.Uni;
30+
import io.vertx.core.Future;
3031
import io.vertx.core.Handler;
32+
import io.vertx.core.Promise;
3133
import io.vertx.core.Vertx;
3234
import io.vertx.core.buffer.Buffer;
3335
import io.vertx.core.http.HttpClientOptions;
@@ -303,12 +305,33 @@ public GrpcStatusCode getStatusCode() {
303305

304306
@Override
305307
public String getStatusDescription() {
306-
return status.toString();
308+
return status.name();
307309
}
308310

309311
@Override
310312
public byte[] getResponseMessage() {
311-
return null;// fixme
313+
if (response == null) {
314+
return null;
315+
}
316+
Promise<String> promise = Promise.promise();
317+
StringBuilder sb = new StringBuilder();
318+
response.handler(msg -> {
319+
sb.append(msg.toString());
320+
});
321+
response.endHandler(v -> {
322+
// Done reading stream
323+
promise.complete(sb.toString());
324+
});
325+
response.exceptionHandler(promise::fail);
326+
String result = promise.future()
327+
.timeout(exportTimeout.toMillis(), MILLISECONDS)
328+
.recover(throwable -> Future.succeededFuture(
329+
"Response error: " + throwable.getMessage()))
330+
.result();
331+
if (result == null || result.isEmpty()) {
332+
return null;
333+
}
334+
return result.getBytes(StandardCharsets.UTF_8);
312335
}
313336
});
314337
} else {

0 commit comments

Comments
 (0)