Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 19 additions & 0 deletions ballerina/natives.bal
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ public isolated function startSpan(string spanName, map<string>? tags = (), int
name: "startSpan"
} external;

# Add a key value pair as a tag to the root.
#
# + tagKey - Key of the tag
# + tagValue - Value of the tag
# + return - An error if an error occurred while attaching tag to the span
public isolated function addTag(string tagKey, string tagValue) returns error? = @java:Method {
'class: "io.ballerina.stdlib.observe.nativeimpl.AddTag",
name: "addTag"
} external;

# Get the value of a given key of a tag.
#
# + tagKey - Key of the tag
# + return - An error if an error occurred while attaching tag to the span
public isolated function getTagValue(string tagKey) returns string? = @java:Method {
'class: "io.ballerina.stdlib.observe.nativeimpl.GetTagValue",
name: "getTagValue"
} external;

# Add a key value pair as a tag to the span.
#
# + spanId - Id of span to which the tags should be added or -1 to add tags to the current active span
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

org.gradle.caching=true
group=io.ballerina.stdlib
version=1.5.1-SNAPSHOT
ballerinaLangVersion=2201.12.0
version=1.6.0-SNAPSHOT
ballerinaLangVersion=2201.13.0-20251016-073200-0d348172

spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.ballerina.stdlib.observe.nativeimpl;

import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.observability.ObserveUtils;

public class AddTag {
public static void addTag(BString tagKey, BString tagValue) {
if (ObserveUtils.isObservabilityEnabled()) {
ObserveUtils.addTag(tagKey.getValue(), tagValue.getValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.ballerina.stdlib.observe.nativeimpl;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.observability.ObserveUtils;
import io.ballerina.runtime.observability.ObserverContext;
import io.ballerina.runtime.observability.metrics.Tag;

public class GetTagValue {
public static Object getTagValue(Environment env, BString tagKey) {
if (ObserveUtils.isObservabilityEnabled()) {
ObserverContext observerContext = ObserveUtils.getObserverContextOfCurrentFrame(env);
if (observerContext == null) {
return null;
}
Tag tag = observerContext.getTag(tagKey.getValue());
if (tag != null) {
return StringUtils.fromString(tag.getValue());
}
return null;
}
return null;
}
}