From a4d4ad037435c62b8482b64d7268db3ed5c4ad99 Mon Sep 17 00:00:00 2001 From: Gagan Juneja Date: Tue, 3 Oct 2023 18:49:06 +0530 Subject: [PATCH] Address review comment Signed-off-by: Gagan Juneja --- .../java/org/opensearch/telemetry/tracing/OTelSpan.java | 4 +++- .../tracing/channels/TraceableTransportChannel.java | 6 +++--- .../org/opensearch/test/telemetry/tracing/MockSpan.java | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java index 588f7953e329f..fc917968579e1 100644 --- a/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java +++ b/plugins/telemetry-otel/src/main/java/org/opensearch/telemetry/tracing/OTelSpan.java @@ -57,7 +57,9 @@ public void addAttribute(String key, Boolean value) { @Override public void setError(Exception exception) { - delegateSpan.setStatus(StatusCode.ERROR, exception != null ? exception.getMessage() : "no description"); + if (exception != null) { + delegateSpan.setStatus(StatusCode.ERROR, exception.getMessage()); + } } @Override diff --git a/server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTransportChannel.java b/server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTransportChannel.java index 19d4d80a75d34..bf88b69a3a26e 100644 --- a/server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTransportChannel.java +++ b/server/src/main/java/org/opensearch/telemetry/tracing/channels/TraceableTransportChannel.java @@ -29,8 +29,6 @@ public class TraceableTransportChannel implements TransportChannel { private final Span span; private final Tracer tracer; - private final TcpChannel tcpChannel; - /** * Constructor. * @param delegate delegate @@ -41,7 +39,6 @@ public TraceableTransportChannel(TransportChannel delegate, Span span, Tracer tr this.delegate = delegate; this.span = span; this.tracer = tracer; - this.tcpChannel = tcpChannel; } /** @@ -88,6 +85,9 @@ public String getChannelType() { public void sendResponse(TransportResponse response) throws IOException { try (SpanScope scope = tracer.withSpanInScope(span)) { delegate.sendResponse(response); + } catch (final IOException ex) { + span.setError(ex); + throw ex; } finally { span.endSpan(); } diff --git a/test/telemetry/src/main/java/org/opensearch/test/telemetry/tracing/MockSpan.java b/test/telemetry/src/main/java/org/opensearch/test/telemetry/tracing/MockSpan.java index f13ef2d26284f..c5d179f6412a8 100644 --- a/test/telemetry/src/main/java/org/opensearch/test/telemetry/tracing/MockSpan.java +++ b/test/telemetry/src/main/java/org/opensearch/test/telemetry/tracing/MockSpan.java @@ -166,7 +166,9 @@ public Long getEndTime() { } public void setError(Exception exception) { - putMetadata("ERROR", exception != null ? exception.getMessage() : null); + if (exception != null) { + putMetadata("ERROR", exception.getMessage()); + } } private static class IdGenerator {