diff --git a/docs/instrumentation-list.yaml b/docs/instrumentation-list.yaml index 0daa958b20d8..e9ae67b5dd1e 100644 --- a/docs/instrumentation-list.yaml +++ b/docs/instrumentation-list.yaml @@ -527,6 +527,53 @@ libraries: type: STRING - name: rpc.system type: STRING + - name: apache-elasticjob-3.0 + display_name: Apache ElasticJob + description: This instrumentation enables spans for Apache ElasticJob job executions. + library_link: https://shardingsphere.apache.org/elasticjob/ + source_path: instrumentation/apache-elasticjob-3.0 + scope: + name: io.opentelemetry.apache-elasticjob-3.0 + target_versions: + javaagent: + - org.apache.shardingsphere.elasticjob:elasticjob-lite-core:[3.0.0,) + configurations: + - name: otel.instrumentation.apache-elasticjob.experimental-span-attributes + description: | + Enables experimental span attributes `job.system`, `scheduling.apache-elasticjob.job.name`, `scheduling.apache-elasticjob.task.id`, `scheduling.apache-elasticjob.sharding.item.index`, `scheduling.apache-elasticjob.sharding.total.count`, `scheduling.apache-elasticjob.sharding.item.parameter`, and `scheduling.apache-elasticjob.job.type`. + type: boolean + default: false + telemetry: + - when: default + spans: + - span_kind: INTERNAL + attributes: + - name: code.function + type: STRING + - name: code.namespace + type: STRING + - when: otel.instrumentation.apache-elasticjob.experimental-span-attributes=true + spans: + - span_kind: INTERNAL + attributes: + - name: code.function + type: STRING + - name: code.namespace + type: STRING + - name: job.system + type: STRING + - name: scheduling.apache-elasticjob.job.name + type: STRING + - name: scheduling.apache-elasticjob.job.type + type: STRING + - name: scheduling.apache-elasticjob.sharding.item.index + type: LONG + - name: scheduling.apache-elasticjob.sharding.item.parameter + type: STRING + - name: scheduling.apache-elasticjob.sharding.total.count + type: LONG + - name: scheduling.apache-elasticjob.task.id + type: STRING - name: apache-httpasyncclient-4.1 display_name: Apache HttpAsyncClient description: This instrumentation enables HTTP client spans and HTTP client metrics diff --git a/instrumentation-docs/instrumentations.sh b/instrumentation-docs/instrumentations.sh index 292bec1a8058..c95e89ec3e1d 100755 --- a/instrumentation-docs/instrumentations.sh +++ b/instrumentation-docs/instrumentations.sh @@ -14,6 +14,8 @@ readonly INSTRUMENTATIONS=( "apache-dbcp-2.0:javaagent:test" "apache-dbcp-2.0:javaagent:testStableSemconv" "apache-dubbo-2.7:javaagent:testDubbo" + "apache-elasticjob-3.0:javaagent:test" + "apache-elasticjob-3.0:javaagent:testExperimental" "apache-httpasyncclient-4.1:javaagent:test" "apache-httpclient:apache-httpclient-2.0:javaagent:test" "apache-httpclient:apache-httpclient-4.0:javaagent:test" diff --git a/instrumentation/apache-elasticjob-3.0/javaagent/build.gradle.kts b/instrumentation/apache-elasticjob-3.0/javaagent/build.gradle.kts index aef31e483354..88929df590c5 100644 --- a/instrumentation/apache-elasticjob-3.0/javaagent/build.gradle.kts +++ b/instrumentation/apache-elasticjob-3.0/javaagent/build.gradle.kts @@ -17,6 +17,20 @@ dependencies { testImplementation("org.apache.curator:curator-test:5.1.0") } -tasks.withType().configureEach { - jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true") +tasks { + withType().configureEach { + systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false") + } + + val testExperimental by registering(Test::class) { + testClassesDirs = sourceSets.test.get().output.classesDirs + classpath = sourceSets.test.get().runtimeClasspath + + jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true") + systemProperty("metadataConfig", "otel.instrumentation.apache-elasticjob.experimental-span-attributes=true") + } + + check { + dependsOn(testExperimental) + } } diff --git a/instrumentation/apache-elasticjob-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apacheelasticjob/v3_0/ElasticJobTest.java b/instrumentation/apache-elasticjob-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apacheelasticjob/v3_0/ElasticJobTest.java index 01f70b72e63a..788220c69941 100644 --- a/instrumentation/apache-elasticjob-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apacheelasticjob/v3_0/ElasticJobTest.java +++ b/instrumentation/apache-elasticjob-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apacheelasticjob/v3_0/ElasticJobTest.java @@ -11,7 +11,6 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; import com.sun.net.httpserver.HttpServer; import io.opentelemetry.api.trace.SpanKind; @@ -28,8 +27,10 @@ import java.net.InetSocketAddress; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Locale; +import javax.annotation.Nullable; import org.apache.shardingsphere.elasticjob.api.JobConfiguration; import org.apache.shardingsphere.elasticjob.http.props.HttpJobProperties; import org.apache.shardingsphere.elasticjob.infra.env.IpUtils; @@ -55,6 +56,9 @@ class ElasticJobTest { private static CoordinatorRegistryCenter regCenter; private static HttpServer httpServer; + private static final boolean EXPERIMENTAL_ATTRIBUTES_ENABLED = + Boolean.getBoolean("otel.instrumentation.apache-elasticjob.experimental-span-attributes"); + @BeforeAll static void init() throws Exception { // ip address detection in ElasticJob may fail to find a valid address, we skip the detection @@ -150,7 +154,7 @@ void testSimpleJob() { regCenter, job, JobConfiguration.newBuilder("simpleElasticJob", 2) - .cron("0/5 * * * * ?") + .cron("0/30 * * * * ?") .shardingItemParameters("0=A,1=B") .build()); @@ -350,6 +354,11 @@ private static String buildScriptCommandLine() throws IOException { return tempScript.toString(); } + @Nullable + private static T experimental(T value) { + return EXPERIMENTAL_ATTRIBUTES_ENABLED ? value : null; + } + private static List elasticJobAttributes( String jobName, long item, @@ -358,16 +367,35 @@ private static List elasticJobAttributes( String codeFunction, String codeNamespace, String jobType) { - return asList( - equalTo(stringKey("code.function"), codeFunction), - equalTo(stringKey("code.namespace"), codeNamespace), - equalTo(stringKey("job.system"), "elasticjob"), - equalTo(stringKey("scheduling.apache-elasticjob.job.name"), jobName), - equalTo(stringKey("scheduling.apache-elasticjob.job.type"), jobType), - equalTo(longKey("scheduling.apache-elasticjob.sharding.item.index"), item), - equalTo(longKey("scheduling.apache-elasticjob.sharding.total.count"), totalCount), - equalTo(stringKey("scheduling.apache-elasticjob.sharding.item.parameter"), parameter), + List assertions = new ArrayList<>(); + + assertions.add(equalTo(stringKey("code.function"), codeFunction)); + assertions.add(equalTo(stringKey("code.namespace"), codeNamespace)); + + assertions.add(equalTo(stringKey("job.system"), experimental("elasticjob"))); + assertions.add( + equalTo(stringKey("scheduling.apache-elasticjob.job.name"), experimental(jobName))); + assertions.add( + equalTo(stringKey("scheduling.apache-elasticjob.job.type"), experimental(jobType))); + assertions.add( + equalTo(longKey("scheduling.apache-elasticjob.sharding.item.index"), experimental(item))); + assertions.add( + equalTo( + longKey("scheduling.apache-elasticjob.sharding.total.count"), + experimental(totalCount))); + assertions.add( + equalTo( + stringKey("scheduling.apache-elasticjob.sharding.item.parameter"), + experimental(parameter))); + assertions.add( satisfies( - stringKey("scheduling.apache-elasticjob.task.id"), taskId -> taskId.contains(jobName))); + stringKey("scheduling.apache-elasticjob.task.id"), + taskId -> { + if (EXPERIMENTAL_ATTRIBUTES_ENABLED) { + taskId.contains(jobName); + } + })); + + return assertions; } } diff --git a/instrumentation/apache-elasticjob-3.0/metadata.yaml b/instrumentation/apache-elasticjob-3.0/metadata.yaml new file mode 100644 index 000000000000..cffe60fe2711 --- /dev/null +++ b/instrumentation/apache-elasticjob-3.0/metadata.yaml @@ -0,0 +1,13 @@ +display_name: Apache ElasticJob +description: This instrumentation enables spans for Apache ElasticJob job executions. +library_link: https://shardingsphere.apache.org/elasticjob/ +configurations: + - name: otel.instrumentation.apache-elasticjob.experimental-span-attributes + description: > + Enables experimental span attributes `job.system`, `scheduling.apache-elasticjob.job.name`, + `scheduling.apache-elasticjob.task.id`, `scheduling.apache-elasticjob.sharding.item.index`, + `scheduling.apache-elasticjob.sharding.total.count`, + `scheduling.apache-elasticjob.sharding.item.parameter`, and + `scheduling.apache-elasticjob.job.type`. + type: boolean + default: false \ No newline at end of file