From 1566c7c78e42bbeaa437d13c5a536dfb65a926fa Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 Jan 2025 15:25:39 +0530 Subject: [PATCH 1/3] Update otlp versions --- ballerina/Ballerina.toml | 38 +++++++------------ ballerina/Dependencies.toml | 25 +++++++++--- ballerina/build.gradle | 23 ++++++----- native/build.gradle | 9 ++--- .../newrelic/NewRelicTracerProvider.java | 4 +- .../newrelic/sampler/RateLimitingSampler.java | 35 +++++++++++------ 6 files changed, 76 insertions(+), 58 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f671760..0afe28a 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -18,7 +18,7 @@ org = "ballerinax" name = "newrelic" version = "@toml.version@" -distribution = "2201.8.2" +distribution = "2201.10.0" [platform.java17] graalvmCompatible = true @@ -66,52 +66,40 @@ artifactId = "kotlin-stdlib" version = "@kotlinStdlib.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-api-@opentelemetry.version@.jar" -groupId = "io.opentelemetry" -artifactId = "opentelemetry-api" -version = "@opentelemetry.version@" - -[[platform.java17.dependency]] -path = "./lib/opentelemetry-api-metrics-@openTelemetryAlpha.version@.jar" -groupId = "io.opentelemetry" -artifactId = "opentelemetry-api-metrics" -version = "@openTelemetryAlpha.version@" - -[[platform.java17.dependency]] -path = "./lib/opentelemetry-sdk-trace-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-sdk-trace-@opentelemetrySDK.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-sdk-trace" -version = "@opentelemetry.version@" +version = "@opentelemetrySDK.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-sdk-common-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-sdk-common-@opentelemetrySDK.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-sdk-common" -version = "@opentelemetry.version@" +version = "@opentelemetrySDK.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-semconv-@openTelemetryAlpha.version@.jar" +path = "./lib/opentelemetry-semconv-@opentelemetrySemconv.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-semconv" -version = "@openTelemetryAlpha.version@" +version = "@opentelemetrySemconv.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-proto-@openTelemetryAlpha.version@.jar" +path = "./lib/opentelemetry-proto-@opentelemetryProto.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-proto" -version = "@openTelemetryAlpha.version@" +version = "@opentelemetryProto.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-exporter-otlp-trace-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-exporter-otlp-trace-@opentelemetryExporter.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-exporter-otlp-trace" -version = "@opentelemetry.version@" +version = "@opentelemetryExporter.version@" [[platform.java17.dependency]] -path = "./lib/opentelemetry-exporter-otlp-common-@opentelemetry.version@.jar" +path = "./lib/opentelemetry-exporter-otlp-common-@opentelemetryExporter.version@.jar" groupId = "io.opentelemetry" artifactId = "opentelemetry-exporter-otlp-common" -version = "@opentelemetry.version@" +version = "@opentelemetryExporter.version@" [[platform.java17.dependency]] path = "./lib/opentelemetry-extension-trace-propagators-@opentelemetry.version@.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c1bd84a..1720715 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.4" +distribution-version = "2201.10.0" [[package]] org = "ballerina" name = "io" -version = "1.6.0" +version = "1.6.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -35,7 +35,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.9.0" +version = "2.10.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -49,7 +49,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.2.0" +version = "1.3.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -58,14 +58,27 @@ modules = [ {org = "ballerina", packageName = "observe", moduleName = "observe.mockextension"} ] +[[package]] +org = "ballerina" +name = "os" +version = "1.8.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "os", moduleName = "os"} +] + [[package]] org = "ballerinax" name = "newrelic" -version = "0.7.0" +version = "0.7.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, - {org = "ballerina", name = "observe"} + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "os"} ] modules = [ {org = "ballerinax", packageName = "newrelic", moduleName = "newrelic"} diff --git a/ballerina/build.gradle b/ballerina/build.gradle index ca0c30e..7a0c246 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -43,14 +43,13 @@ dependencies { externalJars "org.jetbrains.kotlin:kotlin-runtime:${kotlinVersion}" externalJars "org.jetbrains.kotlin:kotlin-stdlib:${kotlinStdlibVersion}" externalJars "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-api-metrics:${openTelemetryAlphaVersion}" externalJars "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-semconv:${openTelemetryAlphaVersion}" - externalJars "io.opentelemetry:opentelemetry-proto:${openTelemetryAlphaVersion}" - externalJars "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryVersion}" - externalJars "io.opentelemetry:opentelemetry-exporter-otlp-common:${openTelemetryVersion}" + externalJars "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetrySDKVersion}" + externalJars "io.opentelemetry:opentelemetry-sdk-common:${openTelemetrySDKVersion}" + externalJars "io.opentelemetry:opentelemetry-semconv:${openTelemetrySemconvVersion}" + externalJars "io.opentelemetry:opentelemetry-proto:${openTelemetryProtoVersion}" + externalJars "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryExporterVersion}" + externalJars "io.opentelemetry:opentelemetry-exporter-otlp-common:${openTelemetryExporterVersion}" externalJars "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" externalJars "io.grpc:grpc-api:${grpcVersion}" externalJars "io.grpc:grpc-context:${grpcVersion}" @@ -117,9 +116,12 @@ task updateTomlVersions { def kotlinVersion = project.kotlinVersion def kotlinStdlibVersion = project.kotlinStdlibVersion def openTelemetryVersion = project.openTelemetryVersion + def openTelemetryExporterVersion = project.openTelemetryExporterVersion + def openTelemetrySDKVersion = project.openTelemetrySDKVersion + def openTelemetrySemconvVersion = project.openTelemetrySemconvVersion + def openTelemetryProtoVersion = project.openTelemetryProtoVersion def grpcVersion = project.grpcVersion def perfmarkVersion = project.perfmarkVersion - def openTelemetryAlphaVersion = project.openTelemetryAlphaVersion def guavaVersion = project.guavaVersion def failureAccessVersion = project.failureAccessVersion @@ -131,7 +133,10 @@ task updateTomlVersions { newConfig = newConfig.replace("@kotlin.version@", kotlinVersion) newConfig = newConfig.replace("@kotlinStdlib.version@", kotlinStdlibVersion) newConfig = newConfig.replace("@opentelemetry.version@", openTelemetryVersion) - newConfig = newConfig.replace("@openTelemetryAlpha.version@", openTelemetryAlphaVersion) + newConfig = newConfig.replace("@opentelemetryExporter.version@", openTelemetryExporterVersion) + newConfig = newConfig.replace("@opentelemetrySDK.version@", openTelemetrySDKVersion) + newConfig = newConfig.replace("@opentelemetrySemconv.version@", openTelemetrySemconvVersion) + newConfig = newConfig.replace("@opentelemetryProto.version@", openTelemetryProtoVersion) newConfig = newConfig.replace("@grpc.version@", grpcVersion) newConfig = newConfig.replace("@perfmark.version@", perfmarkVersion) newConfig = newConfig.replace("@guava.version@", guavaVersion) diff --git a/native/build.gradle b/native/build.gradle index ac6b510..743f59e 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -27,12 +27,11 @@ dependencies { implementation "com.newrelic.telemetry:telemetry-all:${newrelicTelemetryVersion}" implementation "com.newrelic.telemetry:telemetry-http-okhttp:${newrelicTelemetryVersion}" implementation "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-api-metrics:${openTelemetryAlphaVersion}" implementation "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-sdk-common:${openTelemetryVersion}" - implementation "io.opentelemetry:opentelemetry-semconv:${openTelemetryAlphaVersion}" - implementation "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryVersion}" + implementation "io.opentelemetry:opentelemetry-sdk-trace:${openTelemetrySDKVersion}" + implementation "io.opentelemetry:opentelemetry-sdk-common:${openTelemetrySDKVersion}" + implementation "io.opentelemetry.semconv:opentelemetry-semconv:${openTelemetrySemconvVersion}" + implementation "io.opentelemetry:opentelemetry-exporter-otlp-trace:${openTelemetryExporterVersion}" implementation "io.opentelemetry:opentelemetry-extension-trace-propagators:${openTelemetryVersion}" implementation("com.google.guava:guava:${guavaVersion}") { exclude group: 'com.google.code.findbugs', module: 'jsr305' diff --git a/native/src/main/java/io/ballerina/observe/trace/newrelic/NewRelicTracerProvider.java b/native/src/main/java/io/ballerina/observe/trace/newrelic/NewRelicTracerProvider.java index e45f6dd..5b2aa1c 100644 --- a/native/src/main/java/io/ballerina/observe/trace/newrelic/NewRelicTracerProvider.java +++ b/native/src/main/java/io/ballerina/observe/trace/newrelic/NewRelicTracerProvider.java @@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit; -import static io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME; +import static io.opentelemetry.semconv.ResourceAttributes.SERVICE_NAME; /** * This is the New Relic tracing extension class for {@link TracerProvider}. @@ -107,7 +107,7 @@ public Tracer getTracer(String serviceName) { return tracerProviderBuilder.setResource( Resource.create(Attributes.of(SERVICE_NAME, serviceName))) - .build().get(TRACER_NAME); + .build().get("jaeger"); } @Override diff --git a/native/src/main/java/io/ballerina/observe/trace/newrelic/sampler/RateLimitingSampler.java b/native/src/main/java/io/ballerina/observe/trace/newrelic/sampler/RateLimitingSampler.java index 8c320d7..052d79a 100644 --- a/native/src/main/java/io/ballerina/observe/trace/newrelic/sampler/RateLimitingSampler.java +++ b/native/src/main/java/io/ballerina/observe/trace/newrelic/sampler/RateLimitingSampler.java @@ -4,29 +4,38 @@ */ package io.ballerina.observe.trace.newrelic.sampler; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.context.Context; -import io.opentelemetry.sdk.internal.SystemClock; +import io.opentelemetry.sdk.common.Clock; +import io.opentelemetry.sdk.internal.RateLimiter; import io.opentelemetry.sdk.trace.data.LinkData; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingDecision; import io.opentelemetry.sdk.trace.samplers.SamplingResult; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.List; +import static io.opentelemetry.api.common.AttributeKey.doubleKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + /** - * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.0.0/sdk-extensions/ + * This class is copied from https://github.com/open-telemetry/opentelemetry-java/blob/v1.32.0/sdk-extensions/ * jaeger-remote-sampler/src/main/java/io/opentelemetry/sdk/extension/trace/jaeger/sampler/RateLimitingSampler.java. * This sampler uses a leaky bucket rate limiter to ensure that traces are sampled with a certain constant rate. */ public class RateLimitingSampler implements Sampler { public static final String TYPE = "ratelimiting"; + private static final AttributeKey SAMPLER_TYPE = stringKey("sampler.type"); + private static final AttributeKey SAMPLER_PARAM = doubleKey("sampler.param"); - private final double maxTracesPerSecond; private final RateLimiter rateLimiter; private final SamplingResult onSamplingResult; private final SamplingResult offSamplingResult; + private final String description; /** * Creates rate limiting sampler. @@ -34,12 +43,13 @@ public class RateLimitingSampler implements Sampler { * @param maxTracesPerSecond the maximum number of sampled traces per second. */ public RateLimitingSampler(int maxTracesPerSecond) { - this.maxTracesPerSecond = maxTracesPerSecond; double maxBalance = maxTracesPerSecond < 1.0 ? 1.0 : maxTracesPerSecond; - this.rateLimiter = new RateLimiter(maxTracesPerSecond, maxBalance, SystemClock.getInstance()); - Attributes attributes = Attributes.empty(); + this.rateLimiter = new RateLimiter(maxTracesPerSecond, maxBalance, Clock.getDefault()); + Attributes attributes = + Attributes.of(SAMPLER_TYPE, TYPE, SAMPLER_PARAM, (double) maxTracesPerSecond); this.onSamplingResult = SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE, attributes); this.offSamplingResult = SamplingResult.create(SamplingDecision.DROP, attributes); + description = "RateLimitingSampler{" + decimalFormat(maxTracesPerSecond) + "}"; } @Override @@ -50,12 +60,12 @@ public SamplingResult shouldSample( SpanKind spanKind, Attributes attributes, List parentLinks) { - return this.rateLimiter.checkCredit(1.0) ? onSamplingResult : offSamplingResult; + return this.rateLimiter.trySpend(1.0) ? onSamplingResult : offSamplingResult; } @Override public String getDescription() { - return String.format("RateLimitingSampler{%.2f}", maxTracesPerSecond); + return description; } @Override @@ -63,8 +73,11 @@ public String toString() { return getDescription(); } - // Visible for testing - double getMaxTracesPerSecond() { - return maxTracesPerSecond; + private static String decimalFormat(double value) { + DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); + decimalFormatSymbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("0.00", decimalFormatSymbols); + return decimalFormat.format(value); } } From 648a4ce4d285c4b8cf89938f730f4594be55548a Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 Jan 2025 15:25:58 +0530 Subject: [PATCH 2/3] Update otlp versions --- gradle.properties | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 65039e1..a011ec8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # under the License. group=org.ballerinalang -version=0.7.1-SNAPSHOT +version=0.8.0-SNAPSHOT ballerinaLangVersion=2201.8.2 org.gradle.caching=true org.gradle.parallel=true @@ -28,11 +28,13 @@ okioVersion=3.5.0 okhttpVersion=4.11.0 kotlinVersion=1.2.71 kotlinStdlibVersion=1.8.22 -openTelemetryVersion=1.0.0 -openTelemetryAlphaVersion=1.0.0-alpha +openTelemetryVersion=1.32.0 +openTelemetryExporterVersion=1.14.0 +openTelemetrySDKVersion=1.32.0 +openTelemetrySemconvVersion=1.21.0-alpha +openTelemetryProtoVersion=1.7.1-alpha grpcVersion=1.60.0 -protobufVersion=3.20.3 +protobufVersion=3.25.5 perfmarkVersion=0.23.0 -guavaVersion=32.1.2-jre +guavaVersion=33.2.0-jre failureAccessVersion=1.0.1 - From 6c5df8f3ca81e8acba550a566342212475aa3c6b Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 9 Jan 2025 15:26:14 +0530 Subject: [PATCH 3/3] Update workflows --- .github/workflows/build-main.yml | 4 ++-- .github/workflows/central-publish.yml | 4 ++-- .github/workflows/daily-build.yml | 6 +++--- .github/workflows/graalvm-check.yml | 4 ++-- .github/workflows/publish-release.yml | 4 ++-- .github/workflows/pull-request.yml | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml index ac96380..6696ece 100644 --- a/.github/workflows/build-main.yml +++ b/.github/workflows/build-main.yml @@ -6,13 +6,13 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.10.3' push: branches: - main env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.10.3 # Update this with the latest Ballerina version jobs: build: diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 479234c..fb90f93 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -6,7 +6,7 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.10.3' environment: type: choice description: Select environment @@ -40,7 +40,7 @@ jobs: uses: aquasecurity/trivy-action@master with: scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' + scan-ref: "${{ github.workspace }}/ballerina/lib" format: 'table' timeout: '10m0s' exit-code: '1' diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index f54d7ff..6374c77 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -8,10 +8,10 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.10.3' env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.10.3 # Update this with the latest Ballerina version jobs: build: @@ -45,7 +45,7 @@ jobs: uses: aquasecurity/trivy-action@master with: scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' + scan-ref: "${{ github.workspace }}/ballerina/lib" format: 'table' timeout: '10m0s' exit-code: '1' diff --git a/.github/workflows/graalvm-check.yml b/.github/workflows/graalvm-check.yml index b80a806..7b47f27 100644 --- a/.github/workflows/graalvm-check.yml +++ b/.github/workflows/graalvm-check.yml @@ -8,10 +8,10 @@ on: ballerina_version: description: 'Ballerina version' required: true - default: '2201.8.3' + default: '2201.10.3' env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.10.3 # Update this with the latest Ballerina version jobs: build: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 14fc010..2d50d97 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -6,7 +6,7 @@ on: ballerina_version: description: 'Ballerina distribution version (e.g.; 2201.8.4)' required: true - default: '2201.8.4' + default: '2201.10.3' jobs: publish-release: @@ -49,7 +49,7 @@ jobs: uses: aquasecurity/trivy-action@master with: scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' + scan-ref: "${{ github.workspace }}/ballerina/lib" format: 'table' timeout: '10m0s' exit-code: '1' diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c028b70..d7b42cb 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,7 +3,7 @@ name: Validate Pull Request on: pull_request env: - BALLERINA_DISTRIBUTION_VERSION: 2201.8.3 # Update this with the latest Ballerina version + BALLERINA_DISTRIBUTION_VERSION: 2201.10.3 # Update this with the latest Ballerina version jobs: ubuntu-build: