Skip to content
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
4 changes: 2 additions & 2 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "observe"
version = "1.5.0"
version = "1.5.1"
distribution = "2201.12.0"

[[package.modules]]
Expand All @@ -13,7 +13,7 @@ export = true
graalvmCompatible = true

[[platform.java21.dependency]]
path = "../native/build/libs/observe-native-1.5.0.jar"
path = "../native/build/libs/observe-native-1.5.1-SNAPSHOT.jar"
groupId = "ballerina"
artifactId = "observe"

Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.5.0"
version = "1.5.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
10 changes: 10 additions & 0 deletions ballerina/natives.bal
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public isolated function finishSpan(int spanId) returns error? = @java:Method {
name: "finishSpan"
} external;

# Finish the current span.
#
# + spanId - Id of span to finish
# + 'error - Error to be recorded in the span
# + return - An error if an error occurred while finishing the span
public isolated function finishSpanWithError(int spanId, error 'error) returns error? = @java:Method {
'class: "io.ballerina.stdlib.observe.nativeimpl.FinishSpan",
name: "finishSpanWithError"
} external;

# Retrieve a map of span context data.
#
# + return - Map of span context data (traceId and spanId).
Expand Down
2 changes: 1 addition & 1 deletion build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org = "ballerina"
name = "observe"
version = "@toml.version@"
distribution = "2201.11.0"
distribution = "2201.12.0"

[[package.modules]]
name = "observe.mockextension"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BError;

/**
* This function which implements the finishSpan method for observe.
Expand All @@ -40,4 +41,16 @@ public static Object finishSpan(Environment env, long spanId) {
return ErrorCreator.createError(StringUtils.fromString(("Can not finish span with id " + spanId + ". Span " +
"already finished")));
}

public static Object finishSpanWithError(Environment env, long spanId, BError error) {
boolean isFinished = OpenTracerBallerinaWrapper.getInstance().finishSpanWithError(env, spanId,
error);

if (isFinished) {
return null;
}

return ErrorCreator.createError(StringUtils.fromString(("Can not finish span with id " + spanId + ". Span " +
"already finished")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.observability.ObserveUtils;
import io.ballerina.runtime.observability.ObserverContext;
import io.ballerina.runtime.observability.tracer.BSpan;
Expand All @@ -36,6 +37,7 @@
import java.util.concurrent.atomic.AtomicLong;

import static io.ballerina.runtime.observability.ObservabilityConstants.DEFAULT_SERVICE_NAME;
import static io.ballerina.runtime.observability.ObservabilityConstants.PROPERTY_ERROR_VALUE;
import static io.ballerina.runtime.observability.ObservabilityConstants.TAG_KEY_ENTRYPOINT_FUNCTION_MODULE;
import static io.ballerina.runtime.observability.ObservabilityConstants.TAG_KEY_ENTRYPOINT_FUNCTION_NAME;
import static io.ballerina.runtime.observability.ObservabilityConstants.TAG_KEY_ENTRYPOINT_RESOURCE_ACCESSOR;
Expand Down Expand Up @@ -165,6 +167,33 @@ public boolean finishSpan(Environment env, long spanId) {
}
}

/**
* Method to mark a span as finished.
*
* @param env current environment
* @param spanId id of the Span
* @return boolean to indicate if span was finished
*/
public boolean finishSpanWithError(Environment env, long spanId, BError error) {

if (!enabled) {
return false;
}
ObserverContext observerContext = observerContextMap.get(spanId);
if (observerContext != null) {
observerContext.addProperty(PROPERTY_ERROR_VALUE, error);
if (observerContext.isSystemSpan()) {
ObserveUtils.setObserverContextToCurrentFrame(env, observerContext.getParent());
}
TracingUtils.stopObservation(observerContext);
observerContext.setFinished();
observerContextMap.remove(spanId);
return true;
} else {
return false;
}
}

/**
* Method to add tags to an existing span.
*
Expand Down