Skip to content

Commit

Permalink
Merge pull request #43558 from NipunaMadhushan/set-span-status
Browse files Browse the repository at this point in the history
Set span status code
  • Loading branch information
gimantha authored Nov 22, 2024
2 parents 58727e7 + 91882d2 commit 58fe102
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -149,6 +150,10 @@ public void addEvent(String eventName, Attributes attributes) {
span.addEvent(eventName, attributes);
}

public void setStatus(StatusCode statusCode) {
span.setStatus(statusCode);
}

public void addTags(Map<String, String> tags) {
for (Map.Entry<String, String> entry : tags.entrySet()) {
span.setAttribute(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 58fe102

Please sign in to comment.