From 07bdf08b2e5290d03b64d58d53e0ddb9de4beff2 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 8 Nov 2024 14:16:10 +0530 Subject: [PATCH 1/2] Set span status --- .../ballerina/runtime/observability/tracer/BSpan.java | 10 +++++----- .../runtime/observability/tracer/TracingUtils.java | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java index 8350ce227bb4..62e0743a2937 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java @@ -27,11 +27,7 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.values.MappingInitialValueEntry; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanBuilder; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.api.trace.*; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator; @@ -149,6 +145,10 @@ public void addEvent(String eventName, Attributes attributes) { span.addEvent(eventName, attributes); } + public void setStatus(StatusCode statusCode) { + span.setStatus(statusCode); + } + public void addTags(Map tags) { for (Map.Entry entry : tags.entrySet()) { span.setAttribute(entry.getKey(), entry.getValue()); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java index 1747c16ac9b4..944e804d333f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.internal.values.ErrorValue; import io.ballerina.runtime.observability.ObserverContext; import io.ballerina.runtime.observability.metrics.Tag; +import io.opentelemetry.api.trace.StatusCode; import java.util.Collections; import java.util.Map; @@ -79,6 +80,9 @@ public static void stopObservation(ObserverContext observerContext) { ErrorValue bError = (ErrorValue) observerContext.getProperty(PROPERTY_ERROR_VALUE); if (bError != null) { span.addTag(TAG_KEY_STR_ERROR_MESSAGE, bError.getPrintableStackTrace()); + span.setStatus(StatusCode.ERROR); + } else { + span.setStatus(StatusCode.OK); } // Adding specific error code to Trace Span From 91882d219c34177a325967d19e882f4808517cae Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 8 Nov 2024 14:19:37 +0530 Subject: [PATCH 2/2] Fix checkstyle errors --- .../io/ballerina/runtime/observability/tracer/BSpan.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java index 62e0743a2937..e2f5c9aa2fad 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java @@ -27,7 +27,12 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.internal.values.MappingInitialValueEntry; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.*; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanBuilder; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.api.trace.StatusCode; +import io.opentelemetry.api.trace.Tracer; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.TextMapGetter; import io.opentelemetry.context.propagation.TextMapPropagator;