├── .gitattributes
├── testobserve
├── tests
│ ├── src
│ │ └── test
│ │ │ ├── resources
│ │ │ ├── listener_tests
│ │ │ │ ├── .gitignore
│ │ │ │ ├── Ballerina.toml
│ │ │ │ ├── listener_endpoint_test.bal
│ │ │ │ └── Dependencies.toml
│ │ │ ├── logging.properties
│ │ │ └── testng.xml
│ │ │ └── java
│ │ │ └── io
│ │ │ └── ballerina
│ │ │ └── stdlib
│ │ │ └── testobserve
│ │ │ └── ListenerEndpointTest.java
│ └── build.gradle
├── ballerina
│ ├── Ballerina.toml
│ ├── Dependencies.toml
│ ├── utils.bal
│ ├── listener_endpoint_caller.bal
│ ├── listener_endpoint.bal
│ └── build.gradle
└── native
│ ├── src
│ └── main
│ │ ├── java
│ │ ├── module-info.java
│ │ └── org
│ │ │ └── ballerina
│ │ │ └── testobserve
│ │ │ ├── StandardExtensionPackageRepositoryProvider.java
│ │ │ ├── listenerendpoint
│ │ │ ├── Constants.java
│ │ │ ├── Utils.java
│ │ │ ├── Endpoint.java
│ │ │ └── Resource.java
│ │ │ └── NativeUtils.java
│ │ └── resources
│ │ └── META-INF
│ │ └── native-image
│ │ └── org.ballerina
│ │ └── testobserve
│ │ ├── native-image.properties
│ │ └── reflect-config.json
│ ├── spotbugs-exclude.xml
│ └── build.gradle
├── integration-tests
├── src
│ └── test
│ │ ├── resources
│ │ ├── observability
│ │ │ ├── metrics_tests
│ │ │ │ ├── .gitignore
│ │ │ │ ├── Config.toml
│ │ │ │ ├── Ballerina.toml
│ │ │ │ ├── commons.bal
│ │ │ │ ├── 03_custom_metric_tags.bal
│ │ │ │ ├── Dependencies.toml
│ │ │ │ ├── 01_main_function.bal
│ │ │ │ └── 02_resource_function.bal
│ │ │ └── tracing_tests
│ │ │ │ ├── .gitignore
│ │ │ │ ├── Config.toml
│ │ │ │ ├── Ballerina.toml
│ │ │ │ ├── 07_span_context.bal
│ │ │ │ ├── modules
│ │ │ │ └── utils
│ │ │ │ │ ├── observable_adder.bal
│ │ │ │ │ └── mock_client_endpoint.bal
│ │ │ │ ├── Dependencies.toml
│ │ │ │ ├── commons.bal
│ │ │ │ ├── 04_observability_annotation.bal
│ │ │ │ ├── 01_main_function.bal
│ │ │ │ ├── 03_remote_call.bal
│ │ │ │ ├── 06_custom_trace_spans.bal
│ │ │ │ ├── 02_resource_function.bal
│ │ │ │ └── 05_concurrency.bal
│ │ └── testng.xml
│ │ └── java
│ │ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── observability
│ │ ├── BaseTest.java
│ │ ├── tracing
│ │ ├── SpanContextTestCase.java
│ │ ├── TracingBaseTestCase.java
│ │ └── ObservableAnnotationTestCase.java
│ │ └── ObservabilityBaseTest.java
└── build.gradle
├── codecov.yml
├── ballerina
├── Module.md
├── Ballerina.toml
├── Package.md
├── init.bal
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .github
├── pull_request_template.md
├── CODEOWNERS
└── workflows
│ ├── trivy-scan.yml
│ ├── build-timestamped-master.yml
│ ├── pull-request.yml
│ └── publish-release.yml
├── native
├── spotbugs-exclude.xml
├── src
│ └── main
│ │ └── java
│ │ ├── module-info.java
│ │ └── io
│ │ └── ballerina
│ │ └── stdlib
│ │ └── observe
│ │ ├── internal
│ │ ├── ObservabilityInternalSystemPackageRepositoryProvider.java
│ │ └── NativeFunctions.java
│ │ └── observers
│ │ ├── BallerinaTracingObserver.java
│ │ ├── BallerinaMetricsLogsObserver.java
│ │ └── BallerinaMetricsObserver.java
└── build.gradle
├── .gitignore
├── issue_template.md
├── gradle.properties
├── settings.gradle
├── pull_request_template.md
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Ensure all Java files use LF.
2 | *.java eol=lf
3 |
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/listener_tests/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | fixes:
2 | - "ballerinai/observe/*/::ballerina/"
3 |
4 | ignore:
5 | - "**/tests"
6 |
--------------------------------------------------------------------------------
/ballerina/Module.md:
--------------------------------------------------------------------------------
1 | ## Module Overview
2 |
3 | This module provides the Ballerina observability initialization related implementation.
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ballerina-platform/module-ballerinai-observe/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/listener_tests/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "ballerina_test"
3 | name = "listener_tests"
4 | version = "0.0.1"
5 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | ## Examples
4 |
5 | ## Checklist
6 | - [ ] Linked to an issue
7 | - [ ] Updated the changelog
8 | - [ ] Added tests
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/Config.toml:
--------------------------------------------------------------------------------
1 | [ballerina.observe]
2 | metricsEnabled=true # Flag to enable Metrics
3 | metricsReporter="mock"
4 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/Config.toml:
--------------------------------------------------------------------------------
1 | [ballerina.observe]
2 | tracingEnabled=true # Flag to enable Tracing
3 | tracingProvider="mock"
4 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "intg_tests"
3 | name = "metrics_tests"
4 | version = "0.0.1"
5 |
6 | [build-options]
7 | observabilityIncluded=true
8 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "intg_tests"
3 | name = "tracing_tests"
4 | version = "0.0.1"
5 |
6 | [build-options]
7 | observabilityIncluded=true
8 |
--------------------------------------------------------------------------------
/testobserve/ballerina/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "ballerina"
3 | name = "testobserve"
4 | version = "0.0.0"
5 |
6 | [[platform.java21.dependency]]
7 | path = "../native/build/libs/testobserve-native-1.7.0-SNAPSHOT-all.jar"
8 |
--------------------------------------------------------------------------------
/ballerina/Ballerina.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | org = "ballerinai"
3 | name = "observe"
4 | version = "1.7.0"
5 | distribution = "2201.13.0"
6 |
7 | [platform.java21]
8 | graalvmCompatible = true
9 |
10 | [[platform.java21.dependency]]
11 | path = "../native/build/libs/observe-internal-native-1.7.0.jar"
12 |
--------------------------------------------------------------------------------
/native/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Lines starting with '#' are comments.
2 | # Each line is a file pattern followed by one or more owners.
3 |
4 | # See: https://help.github.com/articles/about-codeowners/
5 |
6 | # These owners will be the default owners for everything in the repo.
7 | * @chathurace @NipunaMadhushan @keizer619
8 |
--------------------------------------------------------------------------------
/testobserve/native/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module io.ballerina.observability.test.utils {
2 | requires com.google.gson;
3 | requires io.ballerina.runtime;
4 | requires io.netty.transport;
5 | requires io.netty.buffer;
6 | requires io.netty.codec.http;
7 | requires io.ballerina.lang;
8 | }
9 |
--------------------------------------------------------------------------------
/native/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module io.ballerina.observability {
2 | requires io.ballerina.lang;
3 | requires io.ballerina.runtime;
4 | requires io.opentelemetry.api;
5 | requires io.opentelemetry.context;
6 |
7 | uses io.ballerina.runtime.observability.metrics.spi.MetricProvider;
8 | uses io.ballerina.runtime.observability.tracer.spi.TracerProvider;
9 | }
10 |
--------------------------------------------------------------------------------
/ballerina/Package.md:
--------------------------------------------------------------------------------
1 | ## Package Overview
2 |
3 | The `observe` library is one of the internal library packages, it provides internal support for observing code.
4 |
5 | ## Report Issues
6 |
7 | To report bugs, request new features, start new discussions, view project boards, etc., go to the Ballerina standard library parent repository
8 |
9 | ## Useful Links
10 |
11 | * Chat live with us via our Discord server.
12 | * Post all technical questions on Stack Overflow with the #ballerina tag.
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | !gradle/wrapper/gradle-wrapper.jar
15 | *.jar
16 | *.war
17 | *.nar
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 |
26 | # Java related ignores
27 | build/
28 | target/
29 | .gradle/
30 |
31 | # MacOS
32 | *.DS_Store
33 |
34 | # IDE-related files
35 | .idea
36 | *.iml
37 | *.ipr
38 | *.iws
39 | .code
40 | .project
41 | .settings
42 | .vscode
43 |
44 | # Ballerina related ignores
45 | Ballerina.lock
46 | velocity.log*
47 | Dependencies.toml
48 |
--------------------------------------------------------------------------------
/testobserve/ballerina/Dependencies.toml:
--------------------------------------------------------------------------------
1 | # AUTO-GENERATED FILE. DO NOT MODIFY.
2 |
3 | # This file is auto-generated by Ballerina for managing dependency versions.
4 | # It should not be modified by hand.
5 |
6 | [ballerina]
7 | dependencies-toml-version = "2"
8 | distribution-version = "2201.13.0"
9 |
10 | [[package]]
11 | org = "ballerina"
12 | name = "jballerina.java"
13 | version = "0.0.0"
14 | modules = [
15 | {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
16 | ]
17 |
18 | [[package]]
19 | org = "ballerina"
20 | name = "testobserve"
21 | version = "0.0.0"
22 | dependencies = [
23 | {org = "ballerina", name = "jballerina.java"}
24 | ]
25 | modules = [
26 | {org = "ballerina", packageName = "testobserve", moduleName = "testobserve"}
27 | ]
28 |
29 |
--------------------------------------------------------------------------------
/testobserve/native/src/main/resources/META-INF/native-image/org.ballerina/testobserve/native-image.properties:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
2 | #
3 | # WSO2 LLC. licenses this file to you under the Apache License,
4 | # Version 2.0 (the "License"); you may not use this file except
5 | # in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing,
11 | # software distributed under the License is distributed on an
12 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | # KIND, either express or implied. See the License for the
14 | # specific language governing permissions and limitations
15 | # under the License.
16 |
17 | Args = --initialize-at-build-time=org.slf4j
18 |
--------------------------------------------------------------------------------
/issue_template.md:
--------------------------------------------------------------------------------
1 | **Description:**
2 |
3 |
4 | **Suggested Labels:**
5 |
6 |
7 | **Suggested Assignees:**
8 |
9 |
10 | **Affected Product Version:**
11 |
12 | **OS, DB, other environment details and versions:**
13 |
14 | **Steps to reproduce:**
15 |
16 |
17 | **Related Issues:**
18 |
--------------------------------------------------------------------------------
/.github/workflows/trivy-scan.yml:
--------------------------------------------------------------------------------
1 | name: Trivy
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: '0 0 * * *'
7 |
8 | jobs:
9 | ubuntu-build:
10 | name: Build on Ubuntu
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - name: Set up JDK 21
15 | uses: actions/setup-java@v3
16 | with:
17 | distribution: 'adopt'
18 | java-version: 21
19 | - name: Build with Gradle
20 | env:
21 | packageUser: ${{ github.actor }}
22 | packagePAT: ${{ secrets.GITHUB_TOKEN }}
23 | run: ./gradlew build -x check -x test --stacktrace --console=plain
24 | # Disabled since we are not using any external libraries
25 | # - name: Run Trivy vulnerability scanner
26 | # uses: aquasecurity/trivy-action@master
27 | # with:
28 | # scan-type: 'fs'
29 | # scan-ref: '/github/workspace/ballerina/lib'
30 | # format: 'table'
31 | # exit-code: '1'
32 |
--------------------------------------------------------------------------------
/testobserve/ballerina/utils.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/jballerina.java;
18 |
19 | # Sleep the current strand.
20 | #
21 | # + millis - The number of milliseconds to sleep for
22 | public isolated function sleep(int millis) = @java:Method {
23 | name: "sleep",
24 | 'class: "org.ballerina.testobserve.NativeUtils"
25 | } external;
26 |
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/logging.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | #
4 | # WSO2 Inc. licenses this file to you under the Apache License,
5 | # Version 2.0 (the "License"); you may not use this file except
6 | # in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | #
18 |
19 | .level=INFO
20 | handlers=java.util.logging.ConsoleHandler
21 |
22 | java.util.logging.ConsoleHandler.level=INFO
23 | java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
24 | java.util.logging.SimpleFormatter.format=[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS,%1$tL] %4$s {%3$s} - %5$s %n
25 |
26 | org.apache.directory.level=OFF
27 |
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/testobserve/ballerina/listener_endpoint_caller.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/jballerina.java;
18 |
19 | public client class Caller {
20 | remote isolated function respond(string message) returns error? {
21 | return externRespond(self, message);
22 | }
23 | }
24 |
25 | isolated function externRespond(Caller callerObj, string message) returns error? = @java:Method {
26 | 'class: "org.ballerina.testobserve.listenerendpoint.Endpoint",
27 | name: "respond"
28 | } external;
29 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/commons.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/observe.mockextension;
18 | import ballerina/testobserve;
19 |
20 | service /metricsRegistry on new testobserve:Listener(10090) {
21 | resource function post getMetrics(testobserve:Caller caller) {
22 | mockextension:Metrics metrics = mockextension:getMetrics();
23 | json metricsJson = checkpanic metrics.cloneWithType(json);
24 | checkpanic caller->respond(metricsJson.toJsonString());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | org.gradle.caching=true
16 | group=io.ballerina
17 | version=1.7.1-SNAPSHOT
18 |
19 | ballerinaLangVersion=2201.13.0
20 | spotbugsPluginVersion=6.0.18
21 | shadowJarPluginVersion=8.1.1
22 | downloadPluginVersion=5.4.0
23 | releasePluginVersion=2.8.0
24 | ballerinaTomlParserVersion=1.2.2
25 | ballerinaGradlePluginVersion=2.3.0
26 | checkstylePluginVersion=10.12.0
27 | openTelemetryVersion=1.7.0
28 | nettyCodecVersion=4.1.118.Final
29 | gsonVersion=2.10.1
30 |
31 | observeVersion=1.7.0
32 |
33 | # Test Dependency Versions
34 | testngVersion=7.6.1
35 | slf4jVersion=1.7.26
36 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/07_span_context.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/testobserve;
18 | import ballerina/observe;
19 |
20 | @display { label: "testServiceSeven" }
21 | service /testServiceSeven on new testobserve:Listener(19097) {
22 | resource function get resourceOne(testobserve:Caller caller) {
23 |
24 | map spanContext = observe:getSpanContext();
25 | json spanContextJson = checkpanic spanContext.cloneWithType(json);
26 | checkpanic caller->respond(spanContextJson.toJsonString());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/modules/utils/observable_adder.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/observe;
18 |
19 | public type ObservableAdderClass object {
20 | @observe:Observable
21 | public function getSum() returns int;
22 | };
23 |
24 | public class ObservableAdder {
25 | private int firstNumber;
26 | private int secondNumber;
27 |
28 | public function init(int a, int b) {
29 | self.firstNumber = a;
30 | self.secondNumber = b;
31 | }
32 |
33 | public function getSum() returns int {
34 | return self.firstNumber + self.secondNumber;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/03_custom_metric_tags.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/testobserve;
18 | import ballerina/observe;
19 |
20 | service /testServiceTwo on new testobserve:Listener(10092) {
21 | # Resource function for test custom tags
22 | resource function post testAddTagToMetrics(testobserve:Caller caller) {
23 | // Add a custom tag to span, this should not be included in system metrics
24 | error? res = observe:addTagToSpan("tracing", "Tracing Value");
25 | // Add a custom tag to system metrics
26 | _ = checkpanic observe:addTagToMetrics("metric", "Metric Value");
27 | checkpanic caller->respond("Invocation Successful");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/testobserve/native/src/main/java/org/ballerina/testobserve/StandardExtensionPackageRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | * WSO2 Inc. licenses this file to you under the Apache License,
4 | * Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing,
11 | * software distributed under the License is distributed on an
12 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | * KIND, either express or implied. See the License for the
14 | * specific language governing permissions and limitations
15 | * under the License.
16 | *
17 | */
18 |
19 | package org.ballerina.testobserve;
20 |
21 | import org.ballerinalang.annotation.JavaSPIService;
22 | import org.ballerinalang.spi.SystemPackageRepositoryProvider;
23 | import org.wso2.ballerinalang.compiler.packaging.repo.JarRepo;
24 | import org.wso2.ballerinalang.compiler.packaging.repo.Repo;
25 |
26 | /**
27 | * This is the class which registers the functions defined with the ballerina.
28 | */
29 | @JavaSPIService("org.ballerinalang.spi.SystemPackageRepositoryProvider")
30 | public class StandardExtensionPackageRepositoryProvider implements SystemPackageRepositoryProvider {
31 |
32 | @Override
33 | public Repo loadRepository() {
34 | return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.github/workflows/build-timestamped-master.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | workflow_dispatch:
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | if: github.repository_owner == 'ballerina-platform'
13 | steps:
14 | - name: Checkout Repository
15 | uses: actions/checkout@v3
16 | - name: Set up JDK 21
17 | uses: actions/setup-java@v3
18 | with:
19 | distribution: 'adopt'
20 | java-version: 21
21 | - name: Change to Timestamped Version
22 | run: |
23 | startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00')
24 | latestCommit=$(git log -n 1 --pretty=format:"%h")
25 | VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)
26 | updatedVersion=$VERSION-$startTime-$latestCommit
27 | echo $updatedVersion
28 | sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties
29 | - name: Grant execute permission for gradlew
30 | run: chmod +x gradlew
31 | - name: Build with Gradle
32 | env:
33 | packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
34 | packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
35 | publishUser: ${{ secrets.BALLERINA_BOT_USERNAME }}
36 | publishPAT: ${{ secrets.BALLERINA_BOT_TOKEN }}
37 | run: |
38 | ./gradlew publish --scan --no-daemon --stacktrace --console=plain
39 | - name: Generate CodeCov Report
40 | uses: codecov/codecov-action@v1
41 |
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/listener_tests/listener_endpoint_test.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/testobserve;
18 | import ballerina/lang.'int;
19 |
20 | service /testServiceOne on new testobserve:Listener(29091) {
21 | resource function post resourceOne(testobserve:Caller caller) {
22 | error? ret = caller->respond("Hello from Resource One");
23 | }
24 |
25 | resource function post resourceTwo(testobserve:Caller caller, string body) returns error? {
26 | int numberCount = check 'int:fromString(body);
27 | var sum = 0;
28 | foreach var i in 1 ... numberCount {
29 | sum = sum + i;
30 | }
31 | error? ret = caller->respond("Sum of numbers: " + sum.toString());
32 | }
33 |
34 | resource function post resourceThree(testobserve:Caller caller) returns error? {
35 | error e = error("Test Error");
36 | panic e;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/observe/internal/ObservabilityInternalSystemPackageRepositoryProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | *
18 | */
19 | package io.ballerina.stdlib.observe.internal;
20 |
21 | import org.ballerinalang.annotation.JavaSPIService;
22 | import org.ballerinalang.spi.SystemPackageRepositoryProvider;
23 | import org.wso2.ballerinalang.compiler.packaging.repo.JarRepo;
24 | import org.wso2.ballerinalang.compiler.packaging.repo.Repo;
25 |
26 | /**
27 | * This represents the standard Ballerina built-in system package repository provider.
28 | *
29 | * @since 2.0.0
30 | */
31 | @JavaSPIService("org.ballerinalang.spi.SystemPackageRepositoryProvider")
32 | public class ObservabilityInternalSystemPackageRepositoryProvider implements SystemPackageRepositoryProvider {
33 |
34 | @Override
35 | public Repo loadRepository() {
36 | return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/testobserve/native/src/main/java/org/ballerina/testobserve/listenerendpoint/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.ballerina.testobserve.listenerendpoint;
20 |
21 | import io.ballerina.runtime.api.Module;
22 |
23 | import static io.ballerina.runtime.api.constants.RuntimeConstants.BALLERINA_BUILTIN_PKG_PREFIX;
24 |
25 | /**
26 | * Mock Listener related constants.
27 | */
28 | public class Constants {
29 | public static final Module TEST_OBSERVE_PACKAGE = new Module(BALLERINA_BUILTIN_PKG_PREFIX, "testobserve",
30 | "0");
31 | public static final String MOCK_LISTENER_ERROR_TYPE = "MockListenerError";
32 | public static final String CALLER_TYPE_NAME = "Caller";
33 |
34 | // Keys used for storing native data inside Ballerina Objects
35 | public static final String WEB_SERVER_NATIVE_DATA_KEY = "_mock_listener_web_server";
36 | public static final String NETTY_CONTEXT_NATIVE_DATA_KEY = "_mock_listener_netty_context";
37 | }
38 |
--------------------------------------------------------------------------------
/testobserve/tests/src/test/resources/listener_tests/Dependencies.toml:
--------------------------------------------------------------------------------
1 | # AUTO-GENERATED FILE. DO NOT MODIFY.
2 |
3 | # This file is auto-generated by Ballerina for managing dependency versions.
4 | # It should not be modified by hand.
5 |
6 | [ballerina]
7 | dependencies-toml-version = "2"
8 | distribution-version = "2201.8.0-20230726-145300-b2bdf796"
9 |
10 | [[package]]
11 | org = "ballerina"
12 | name = "jballerina.java"
13 | version = "0.0.0"
14 |
15 | [[package]]
16 | org = "ballerina"
17 | name = "lang.__internal"
18 | version = "0.0.0"
19 | dependencies = [
20 | {org = "ballerina", name = "jballerina.java"},
21 | {org = "ballerina", name = "lang.object"}
22 | ]
23 |
24 | [[package]]
25 | org = "ballerina"
26 | name = "lang.int"
27 | version = "0.0.0"
28 | dependencies = [
29 | {org = "ballerina", name = "jballerina.java"},
30 | {org = "ballerina", name = "lang.__internal"},
31 | {org = "ballerina", name = "lang.object"}
32 | ]
33 | modules = [
34 | {org = "ballerina", packageName = "lang.int", moduleName = "lang.int"}
35 | ]
36 |
37 | [[package]]
38 | org = "ballerina"
39 | name = "lang.object"
40 | version = "0.0.0"
41 |
42 | [[package]]
43 | org = "ballerina"
44 | name = "testobserve"
45 | version = "0.0.0"
46 | dependencies = [
47 | {org = "ballerina", name = "jballerina.java"}
48 | ]
49 | modules = [
50 | {org = "ballerina", packageName = "testobserve", moduleName = "testobserve"}
51 | ]
52 |
53 | [[package]]
54 | org = "ballerina_test"
55 | name = "listener_tests"
56 | version = "0.0.1"
57 | dependencies = [
58 | {org = "ballerina", name = "lang.int"},
59 | {org = "ballerina", name = "testobserve"}
60 | ]
61 | modules = [
62 | {org = "ballerina_test", packageName = "listener_tests", moduleName = "listener_tests"}
63 | ]
64 |
65 |
--------------------------------------------------------------------------------
/integration-tests/src/test/java/io/ballerina/stdlib/observability/BaseTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.observability;
19 |
20 | import org.ballerinalang.test.context.BalServer;
21 | import org.ballerinalang.test.context.BallerinaTestException;
22 | import org.testng.annotations.AfterSuite;
23 | import org.testng.annotations.BeforeSuite;
24 |
25 | /**
26 | * Parent test class for all integration test cases under test-integration module. This will provide basic
27 | * functionality for integration test. This will initialize a single ballerina instance which will be used
28 | * by all the test cases throughout.
29 | */
30 | public class BaseTest {
31 |
32 | public static BalServer balServer;
33 |
34 | @BeforeSuite(alwaysRun = true)
35 | public void initialize() throws BallerinaTestException {
36 | balServer = new BalServer();
37 | }
38 |
39 | @AfterSuite(alwaysRun = true)
40 | public void destroy() throws BallerinaTestException {
41 | balServer.cleanup();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/Dependencies.toml:
--------------------------------------------------------------------------------
1 | # AUTO-GENERATED FILE. DO NOT MODIFY.
2 |
3 | # This file is auto-generated by Ballerina for managing dependency versions.
4 | # It should not be modified by hand.
5 |
6 | [ballerina]
7 | dependencies-toml-version = "2"
8 | distribution-version = "2201.7.0-20230619-175900-bb4e4544"
9 |
10 | [[package]]
11 | org = "ballerina"
12 | name = "jballerina.java"
13 | version = "0.0.0"
14 |
15 | [[package]]
16 | org = "ballerina"
17 | name = "observe"
18 | version = "1.1.0"
19 | dependencies = [
20 | {org = "ballerina", name = "jballerina.java"}
21 | ]
22 | modules = [
23 | {org = "ballerina", packageName = "observe", moduleName = "observe"},
24 | {org = "ballerina", packageName = "observe", moduleName = "observe.mockextension"}
25 | ]
26 |
27 | [[package]]
28 | org = "ballerina"
29 | name = "testobserve"
30 | version = "0.0.0"
31 | dependencies = [
32 | {org = "ballerina", name = "jballerina.java"}
33 | ]
34 | modules = [
35 | {org = "ballerina", packageName = "testobserve", moduleName = "testobserve"}
36 | ]
37 |
38 | [[package]]
39 | org = "ballerinai"
40 | name = "observe"
41 | version = "0.0.0"
42 | dependencies = [
43 | {org = "ballerina", name = "jballerina.java"},
44 | {org = "ballerina", name = "observe"}
45 | ]
46 | modules = [
47 | {org = "ballerinai", packageName = "observe", moduleName = "observe"}
48 | ]
49 |
50 | [[package]]
51 | org = "intg_tests"
52 | name = "metrics_tests"
53 | version = "0.0.1"
54 | dependencies = [
55 | {org = "ballerina", name = "observe"},
56 | {org = "ballerina", name = "testobserve"},
57 | {org = "ballerinai", name = "observe"}
58 | ]
59 | modules = [
60 | {org = "intg_tests", packageName = "metrics_tests", moduleName = "metrics_tests"}
61 | ]
62 |
63 |
--------------------------------------------------------------------------------
/testobserve/native/src/main/java/org/ballerina/testobserve/NativeUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package org.ballerina.testobserve;
20 |
21 | import io.ballerina.runtime.api.Environment;
22 | import io.ballerina.runtime.api.creators.ErrorCreator;
23 | import io.ballerina.runtime.api.utils.StringUtils;
24 |
25 | import java.util.concurrent.Executors;
26 | import java.util.concurrent.ScheduledExecutorService;
27 |
28 | /**
29 | * Native functions for the utilities in testobserve module.
30 | */
31 | public class NativeUtils {
32 | private static final int CORE_THREAD_POOL_SIZE = 1;
33 |
34 | private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(CORE_THREAD_POOL_SIZE);
35 |
36 | public static void sleep(Environment env, long delayMillis) {
37 | env.yieldAndRun(() -> {
38 | try {
39 | Thread.sleep(delayMillis);
40 | return null;
41 | } catch (InterruptedException e) {
42 | throw ErrorCreator.createError(StringUtils.fromString("error occurred during sleep"), e);
43 | }
44 | });
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/testobserve/native/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/Dependencies.toml:
--------------------------------------------------------------------------------
1 | # AUTO-GENERATED FILE. DO NOT MODIFY.
2 |
3 | # This file is auto-generated by Ballerina for managing dependency versions.
4 | # It should not be modified by hand.
5 |
6 | [ballerina]
7 | dependencies-toml-version = "2"
8 | distribution-version = "2201.7.0-20230619-175900-bb4e4544"
9 |
10 | [[package]]
11 | org = "ballerina"
12 | name = "jballerina.java"
13 | version = "0.0.0"
14 |
15 | [[package]]
16 | org = "ballerina"
17 | name = "observe"
18 | version = "1.1.0"
19 | dependencies = [
20 | {org = "ballerina", name = "jballerina.java"}
21 | ]
22 | modules = [
23 | {org = "ballerina", packageName = "observe", moduleName = "observe"},
24 | {org = "ballerina", packageName = "observe", moduleName = "observe.mockextension"}
25 | ]
26 |
27 | [[package]]
28 | org = "ballerina"
29 | name = "testobserve"
30 | version = "0.0.0"
31 | dependencies = [
32 | {org = "ballerina", name = "jballerina.java"}
33 | ]
34 | modules = [
35 | {org = "ballerina", packageName = "testobserve", moduleName = "testobserve"}
36 | ]
37 |
38 | [[package]]
39 | org = "ballerinai"
40 | name = "observe"
41 | version = "0.0.0"
42 | dependencies = [
43 | {org = "ballerina", name = "jballerina.java"},
44 | {org = "ballerina", name = "observe"}
45 | ]
46 | modules = [
47 | {org = "ballerinai", packageName = "observe", moduleName = "observe"}
48 | ]
49 |
50 | [[package]]
51 | org = "intg_tests"
52 | name = "tracing_tests"
53 | version = "0.0.1"
54 | dependencies = [
55 | {org = "ballerina", name = "observe"},
56 | {org = "ballerina", name = "testobserve"},
57 | {org = "ballerinai", name = "observe"}
58 | ]
59 | modules = [
60 | {org = "intg_tests", packageName = "tracing_tests", moduleName = "tracing_tests"},
61 | {org = "intg_tests", packageName = "tracing_tests", moduleName = "tracing_tests.utils"}
62 | ]
63 |
64 |
--------------------------------------------------------------------------------
/native/src/main/java/io/ballerina/stdlib/observe/observers/BallerinaTracingObserver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
3 | *
4 | * WSO2 LLC. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 | package io.ballerina.stdlib.observe.observers;
19 |
20 | import io.ballerina.runtime.observability.BallerinaObserver;
21 | import io.ballerina.runtime.observability.ObserverContext;
22 | import io.ballerina.runtime.observability.tracer.TracingUtils;
23 |
24 | /**
25 | * Observe the runtime and start/stop tracing.
26 | */
27 | public class BallerinaTracingObserver implements BallerinaObserver {
28 |
29 | @Override
30 | public void startServerObservation(ObserverContext observerContext) {
31 | TracingUtils.startObservation(observerContext, false);
32 | }
33 |
34 | @Override
35 | public void startClientObservation(ObserverContext observerContext) {
36 | TracingUtils.startObservation(observerContext, true);
37 | }
38 |
39 | @Override
40 | public void stopServerObservation(ObserverContext observerContext) {
41 | TracingUtils.stopObservation(observerContext);
42 | }
43 |
44 | @Override
45 | public void stopClientObservation(ObserverContext observerContext) {
46 | TracingUtils.stopObservation(observerContext);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/commons.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/observe;
18 | import ballerina/observe.mockextension;
19 | import ballerina/testobserve;
20 | import intg_tests/tracing_tests.utils as utils;
21 |
22 | utils:MockClient testClient = new();
23 |
24 | @display { label: "mockTracer" }
25 | service /mockTracer on new testobserve:Listener(19090) {
26 | resource function post getMockTraces(testobserve:Caller caller, string serviceName) {
27 | mockextension:Span[] spans = mockextension:getFinishedSpans(serviceName);
28 | json spansJson = checkpanic spans.cloneWithType(json);
29 | checkpanic caller->respond(spansJson.toJsonString());
30 | }
31 | }
32 |
33 | function panicAfterCalculatingSum(int a) {
34 | var sum = 0;
35 | foreach var i in 1 ... a {
36 | sum = sum + i;
37 | }
38 | error e = error("Test Error. Sum: " + sum.toString());
39 | panic e;
40 | }
41 |
42 | function calculateSum(int a, int b) returns int {
43 | var sum = a + b;
44 | return a + b;
45 | }
46 |
47 | @observe:Observable
48 | function calculateSumWithObservability(int a, int b) returns int {
49 | var sum = a + b;
50 | return a + b;
51 | }
52 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/testng.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/.github/workflows/pull-request.yml:
--------------------------------------------------------------------------------
1 | name: Ballerina Observe Internal module build
2 |
3 | on: [pull_request]
4 |
5 | jobs:
6 | ubuntu-build:
7 | name: Build on Ubuntu
8 | runs-on: ubuntu-latest
9 | steps:
10 | - name: Checkout Repository
11 | uses: actions/checkout@v3
12 | - name: Set up JDK 21
13 | uses: actions/setup-java@v3
14 | with:
15 | distribution: 'adopt'
16 | java-version: 21
17 | - name: Build with Gradle
18 | env:
19 | packageUser: ${{ github.actor }}
20 | packagePAT: ${{ secrets.GITHUB_TOKEN }}
21 | run: |
22 | ./gradlew build test --stacktrace --console=plain
23 | - name: Generate Codecov Report
24 | uses: codecov/codecov-action@v2
25 |
26 | windows-build:
27 | name: Build on Windows
28 | runs-on: windows-latest
29 | steps:
30 | - name: Checkout Repository
31 | uses: actions/checkout@v3
32 | - name: Set up JDK 21
33 | uses: actions/setup-java@v3
34 | with:
35 | distribution: 'adopt'
36 | java-version: 21
37 | - name: Build with Gradle
38 | env:
39 | packageUser: ${{ github.actor }}
40 | packagePAT: ${{ secrets.GITHUB_TOKEN }}
41 | JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
42 | run: |
43 | ./gradlew.bat build -x test --stacktrace --console=plain
44 | ./gradlew.bat test --stacktrace --console=plain
45 |
46 | ubuntu-build-without-native-tests:
47 | name: Build on Ubuntu without native tests
48 | runs-on: ubuntu-latest
49 | steps:
50 | - name: Checkout Repository
51 | uses: actions/checkout@v3
52 | - name: Set up JDK 21
53 | uses: actions/setup-java@v3
54 | with:
55 | distribution: 'adopt'
56 | java-version: 21
57 | - name: Build with Gradle
58 | env:
59 | packageUser: ${{ github.actor }}
60 | packagePAT: ${{ secrets.GITHUB_TOKEN }}
61 | run: ./gradlew build -x test --stacktrace --console=plain
62 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/04_observability_annotation.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/testobserve;
18 | import intg_tests/tracing_tests.utils as utils;
19 |
20 | @display { label: "testSvcFour" }
21 | service /testServiceFour on new testobserve:Listener(19094) {
22 | # Resource function for testing function call with observable annotation
23 | resource function post resourceOne(testobserve:Caller caller) {
24 | var sum = calculateSumWithObservability(10, 51);
25 | if (sum != 61) { // Check for validating if normal execution is intact from instrumentation
26 | error err = error("failed to find the sum of 10 and 51. expected: 61 received: " + sum.toString());
27 | panic err;
28 | }
29 | checkpanic caller->respond("Invocation Successful");
30 | }
31 |
32 | # Resource function for testing attached function call with observable annotation
33 | resource function post resourceTwo(testobserve:Caller caller) {
34 | utils:ObservableAdderClass adder = new utils:ObservableAdder(20, 34);
35 | var sum = adder.getSum();
36 | if (sum != 54) { // Check for validating if normal execution is intact from instrumentation
37 | error err = error("failed to find the sum of 20 and 34. expected: 54 received: " + sum.toString());
38 | panic err;
39 | }
40 | checkpanic caller->respond("Invocation Successful");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/metrics_tests/01_main_function.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/observe;
18 |
19 | public function main() returns error? {
20 | int a = 6;
21 | int b = 13;
22 |
23 | ObservableAdderClass adder = new ObservableAdder(a, b);
24 | var sumFromAdder = adder.getSum();
25 |
26 | var sumFromFunc = callCalculateSum(a, b);
27 | sumFromFunc = callCalculateSum(a, b);
28 | sumFromFunc = callCalculateSum(a, b);
29 |
30 | if (sumFromAdder != sumFromFunc) { // Sanity check for sum
31 | error e = error("Sum from Adder Object (" + sumFromAdder.toString() + ") and sum from Function ("
32 | + sumFromFunc.toString() + ")");
33 | return e;
34 | }
35 | }
36 |
37 | function callCalculateSum(int a, int b) returns int {
38 | return calculateSumWithObservability(a, b);
39 | }
40 |
41 | @observe:Observable
42 | function calculateSumWithObservability(int a, int b) returns int {
43 | var sum = a + b;
44 | return a + b;
45 | }
46 |
47 | type ObservableAdderClass object {
48 | @observe:Observable
49 | function getSum() returns int;
50 | };
51 |
52 | class ObservableAdder {
53 | private int firstNumber;
54 | private int secondNumber;
55 |
56 | function init(int a, int b) {
57 | self.firstNumber = a;
58 | self.secondNumber = b;
59 | }
60 |
61 | function getSum() returns int {
62 | return self.firstNumber + self.secondNumber;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/ballerina/init.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/jballerina.java;
18 | import ballerina/observe;
19 |
20 | function init() {
21 | if (observe:isMetricsEnabled()) {
22 | var err = externEnableMetrics(observe:getMetricsProvider());
23 | if (err is error) {
24 | externPrintError("failed to enable metrics");
25 | }
26 | }
27 |
28 | if (observe:isTracingEnabled()) {
29 | var err = externEnableTracing(observe:getTracingProvider());
30 | if (err is error) {
31 | externPrintError("failed to enable tracing");
32 | }
33 | }
34 |
35 | if (observe:isMetricsLogsEnabled()) {
36 | var err = externEnableMetricsLogging();
37 | if (err is error) {
38 | externPrintError("failed to enable tracing");
39 | }
40 | }
41 | }
42 |
43 | function externEnableMetrics(string provider) returns error? = @java:Method {
44 | 'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
45 | name: "enableMetrics"
46 | } external;
47 |
48 | function externEnableTracing(string provider) returns error? = @java:Method {
49 | 'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
50 | name: "enableTracing"
51 | } external;
52 |
53 | function externEnableMetricsLogging() returns error? = @java:Method {
54 | 'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
55 | name: "enableMetricsLogging"
56 | } external;
57 |
58 | function externPrintError(string message) = @java:Method {
59 | 'class: "io.ballerina.stdlib.observe.internal.NativeFunctions",
60 | name: "printError"
61 | } external;
62 |
--------------------------------------------------------------------------------
/integration-tests/src/test/resources/observability/tracing_tests/01_main_function.bal:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2 | //
3 | // WSO2 Inc. licenses this file to you under the Apache License,
4 | // Version 2.0 (the "License"); you may not use this file except
5 | // in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing,
11 | // software distributed under the License is distributed on an
12 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 | // KIND, either express or implied. See the License for the
14 | // specific language governing permissions and limitations
15 | // under the License.
16 |
17 | import ballerina/testobserve;
18 |
19 | public function main() returns error? {
20 | testClient->callAnotherRemoteFunction();
21 |
22 | var a = 63;
23 | var b = 81;
24 | var sum = testClient->calculateSum(a, b);
25 | var expectedSum = a + b;
26 | if (sum != expectedSum) { // Check for validating if normal execution is intact from instrumentation
27 | error err = error("failed to find the sum of " + a.toString() + " and " + b.toString()
28 | + ". expected: " + expectedSum.toString() + " received: " + sum.toString());
29 | panic err;
30 | }
31 |
32 | var ret1 = trap testClient->callWithPanic();
33 | if (!(ret1 is error)) {
34 | error e = error("Expected error not found");
35 | panic e;
36 | }
37 |
38 | var ret2 = testClient->callWithErrorReturn();
39 | if (!(ret2 is error)) {
40 | error e = error("Expected error not found");
41 | panic e;
42 | }
43 |
44 | service object {} testServiceInMain = service object {
45 | resource function post resourceOne(testobserve:Caller caller, string body) {
46 | int numberCount = checkpanic 'int:fromString(body);
47 | var total = 0;
48 | foreach var i in 1 ... numberCount {
49 | total = total + i;
50 | }
51 | checkpanic caller->respond("Sum of numbers: " + total.toString());
52 | }
53 | };
54 | var testObserveListener = new testobserve:Listener(19091);
55 | check testObserveListener.attach(testServiceInMain, "/testServiceOne");
56 | check testObserveListener.start();
57 | }
58 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | *
6 | * Detailed information about configuring a multi-project build in Gradle can be found
7 | * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html
8 | */
9 |
10 | pluginManagement {
11 | plugins {
12 | id "com.github.spotbugs" version "${spotbugsPluginVersion}"
13 | id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}"
14 | id "de.undercouch.download" version "${downloadPluginVersion}"
15 | id "net.researchgate.release" version "${releasePluginVersion}"
16 | id "io.ballerina.plugin" version "${ballerinaGradlePluginVersion}"
17 | }
18 |
19 | repositories {
20 | gradlePluginPortal()
21 | maven {
22 | url = 'https://maven.pkg.github.com/ballerina-platform/*'
23 | credentials {
24 | username System.getenv("packageUser")
25 | password System.getenv("packagePAT")
26 | }
27 | }
28 | }
29 | }
30 |
31 | plugins {
32 | id "com.gradle.enterprise" version "3.13.2"
33 | }
34 |
35 | rootProject.name = 'module-ballerinai-observe'
36 |
37 | include ':checkstyle'
38 | include ':testobserve-native'
39 | include ':testobserve-ballerina'
40 | include ':testobserve-ballerina-tests'
41 | include ':observe-internal-native'
42 | include ':observe-ballerina'
43 | include ':observe-ballerina-integration-tests'
44 |
45 | project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle")
46 |
47 | // Integration Test Utils
48 | project(':testobserve-native').projectDir = file("testobserve${File.separator}native")
49 | project(':testobserve-ballerina').projectDir = file("testobserve${File.separator}ballerina")
50 | project(':testobserve-ballerina-tests').projectDir = file("testobserve${File.separator}tests")
51 |
52 | // Observe Internal
53 | project(':observe-internal-native').projectDir = file('native')
54 | project(':observe-ballerina').projectDir = file('ballerina')
55 |
56 | // Integration tests
57 | project(':observe-ballerina-integration-tests').projectDir = file('integration-tests')
58 |
59 | gradleEnterprise {
60 | buildScan {
61 | termsOfServiceUrl = 'https://gradle.com/terms-of-service'
62 | termsOfServiceAgree = 'yes'
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/integration-tests/src/test/java/io/ballerina/stdlib/observability/tracing/SpanContextTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3 | *
4 | * WSO2 Inc. licenses this file to you under the Apache License,
5 | * Version 2.0 (the "License"); you may not use this file except
6 | * in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing,
12 | * software distributed under the License is distributed on an
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | * KIND, either express or implied. See the License for the
15 | * specific language governing permissions and limitations
16 | * under the License.
17 | */
18 |
19 | package io.ballerina.stdlib.observability.tracing;
20 |
21 | import com.google.gson.Gson;
22 | import com.google.gson.reflect.TypeToken;
23 | import io.ballerina.stdlib.observe.mockextension.BMockSpan;
24 | import org.ballerinalang.test.util.HttpClientRequest;
25 | import org.testng.Assert;
26 | import org.testng.annotations.Test;
27 |
28 | import java.lang.reflect.Type;
29 | import java.util.List;
30 | import java.util.Map;
31 | import java.util.Optional;
32 |
33 | /**
34 | * Test cases span context.
35 | *
36 | * @since 2.0.0
37 | */
38 | @Test(groups = "tracing-test")
39 | public class SpanContextTestCase extends TracingBaseTestCase {
40 | private static final String FILE_NAME = "07_span_context.bal";
41 |
42 | @Test
43 | public void test() throws Exception {
44 | String requestUrl = "http://localhost:19097/testServiceSeven/resourceOne/";
45 | String data = HttpClientRequest.doGet(requestUrl).getData();
46 | Type type = new TypeToken