Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set span status code #43558

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
span.addEvent(eventName, attributes);
}

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

Check warning on line 155 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/BSpan.java#L154-L155

Added lines #L154 - L155 were not covered by tests

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 @@
ErrorValue bError = (ErrorValue) observerContext.getProperty(PROPERTY_ERROR_VALUE);
if (bError != null) {
span.addTag(TAG_KEY_STR_ERROR_MESSAGE, bError.getPrintableStackTrace());
span.setStatus(StatusCode.ERROR);

Check warning on line 83 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java#L83

Added line #L83 was not covered by tests
} else {
span.setStatus(StatusCode.OK);

Check warning on line 85 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java#L85

Added line #L85 was not covered by tests
}

// Adding specific error code to Trace Span
Expand Down