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
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 adding the tag failed; otherwise null
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 - The value of the tag if present; otherwise null
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,28 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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,41 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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;
}
}