Skip to content

Commit 7cc394c

Browse files
authored
ElasticJob metadata (open-telemetry#15420)
1 parent 1e861ba commit 7cc394c

File tree

5 files changed

+118
-14
lines changed

5 files changed

+118
-14
lines changed

docs/instrumentation-list.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,53 @@ libraries:
527527
type: STRING
528528
- name: rpc.system
529529
type: STRING
530+
- name: apache-elasticjob-3.0
531+
display_name: Apache ElasticJob
532+
description: This instrumentation enables spans for Apache ElasticJob job executions.
533+
library_link: https://shardingsphere.apache.org/elasticjob/
534+
source_path: instrumentation/apache-elasticjob-3.0
535+
scope:
536+
name: io.opentelemetry.apache-elasticjob-3.0
537+
target_versions:
538+
javaagent:
539+
- org.apache.shardingsphere.elasticjob:elasticjob-lite-core:[3.0.0,)
540+
configurations:
541+
- name: otel.instrumentation.apache-elasticjob.experimental-span-attributes
542+
description: |
543+
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`.
544+
type: boolean
545+
default: false
546+
telemetry:
547+
- when: default
548+
spans:
549+
- span_kind: INTERNAL
550+
attributes:
551+
- name: code.function
552+
type: STRING
553+
- name: code.namespace
554+
type: STRING
555+
- when: otel.instrumentation.apache-elasticjob.experimental-span-attributes=true
556+
spans:
557+
- span_kind: INTERNAL
558+
attributes:
559+
- name: code.function
560+
type: STRING
561+
- name: code.namespace
562+
type: STRING
563+
- name: job.system
564+
type: STRING
565+
- name: scheduling.apache-elasticjob.job.name
566+
type: STRING
567+
- name: scheduling.apache-elasticjob.job.type
568+
type: STRING
569+
- name: scheduling.apache-elasticjob.sharding.item.index
570+
type: LONG
571+
- name: scheduling.apache-elasticjob.sharding.item.parameter
572+
type: STRING
573+
- name: scheduling.apache-elasticjob.sharding.total.count
574+
type: LONG
575+
- name: scheduling.apache-elasticjob.task.id
576+
type: STRING
530577
- name: apache-httpasyncclient-4.1
531578
display_name: Apache HttpAsyncClient
532579
description: This instrumentation enables HTTP client spans and HTTP client metrics

instrumentation-docs/instrumentations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ readonly INSTRUMENTATIONS=(
1414
"apache-dbcp-2.0:javaagent:test"
1515
"apache-dbcp-2.0:javaagent:testStableSemconv"
1616
"apache-dubbo-2.7:javaagent:testDubbo"
17+
"apache-elasticjob-3.0:javaagent:test"
18+
"apache-elasticjob-3.0:javaagent:testExperimental"
1719
"apache-httpasyncclient-4.1:javaagent:test"
1820
"apache-httpclient:apache-httpclient-2.0:javaagent:test"
1921
"apache-httpclient:apache-httpclient-4.0:javaagent:test"

instrumentation/apache-elasticjob-3.0/javaagent/build.gradle.kts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ dependencies {
1717
testImplementation("org.apache.curator:curator-test:5.1.0")
1818
}
1919

20-
tasks.withType<Test>().configureEach {
21-
jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true")
20+
tasks {
21+
withType<Test>().configureEach {
22+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
23+
}
24+
25+
val testExperimental by registering(Test::class) {
26+
testClassesDirs = sourceSets.test.get().output.classesDirs
27+
classpath = sourceSets.test.get().runtimeClasspath
28+
29+
jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true")
30+
systemProperty("metadataConfig", "otel.instrumentation.apache-elasticjob.experimental-span-attributes=true")
31+
}
32+
33+
check {
34+
dependsOn(testExperimental)
35+
}
2236
}

instrumentation/apache-elasticjob-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apacheelasticjob/v3_0/ElasticJobTest.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1212
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
1313
import static java.nio.charset.StandardCharsets.UTF_8;
14-
import static java.util.Arrays.asList;
1514

1615
import com.sun.net.httpserver.HttpServer;
1716
import io.opentelemetry.api.trace.SpanKind;
@@ -28,8 +27,10 @@
2827
import java.net.InetSocketAddress;
2928
import java.nio.file.Files;
3029
import java.nio.file.Path;
30+
import java.util.ArrayList;
3131
import java.util.List;
3232
import java.util.Locale;
33+
import javax.annotation.Nullable;
3334
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
3435
import org.apache.shardingsphere.elasticjob.http.props.HttpJobProperties;
3536
import org.apache.shardingsphere.elasticjob.infra.env.IpUtils;
@@ -55,6 +56,9 @@ class ElasticJobTest {
5556
private static CoordinatorRegistryCenter regCenter;
5657
private static HttpServer httpServer;
5758

59+
private static final boolean EXPERIMENTAL_ATTRIBUTES_ENABLED =
60+
Boolean.getBoolean("otel.instrumentation.apache-elasticjob.experimental-span-attributes");
61+
5862
@BeforeAll
5963
static void init() throws Exception {
6064
// ip address detection in ElasticJob may fail to find a valid address, we skip the detection
@@ -150,7 +154,7 @@ void testSimpleJob() {
150154
regCenter,
151155
job,
152156
JobConfiguration.newBuilder("simpleElasticJob", 2)
153-
.cron("0/5 * * * * ?")
157+
.cron("0/30 * * * * ?")
154158
.shardingItemParameters("0=A,1=B")
155159
.build());
156160

@@ -350,6 +354,11 @@ private static String buildScriptCommandLine() throws IOException {
350354
return tempScript.toString();
351355
}
352356

357+
@Nullable
358+
private static <T> T experimental(T value) {
359+
return EXPERIMENTAL_ATTRIBUTES_ENABLED ? value : null;
360+
}
361+
353362
private static List<AttributeAssertion> elasticJobAttributes(
354363
String jobName,
355364
long item,
@@ -358,16 +367,35 @@ private static List<AttributeAssertion> elasticJobAttributes(
358367
String codeFunction,
359368
String codeNamespace,
360369
String jobType) {
361-
return asList(
362-
equalTo(stringKey("code.function"), codeFunction),
363-
equalTo(stringKey("code.namespace"), codeNamespace),
364-
equalTo(stringKey("job.system"), "elasticjob"),
365-
equalTo(stringKey("scheduling.apache-elasticjob.job.name"), jobName),
366-
equalTo(stringKey("scheduling.apache-elasticjob.job.type"), jobType),
367-
equalTo(longKey("scheduling.apache-elasticjob.sharding.item.index"), item),
368-
equalTo(longKey("scheduling.apache-elasticjob.sharding.total.count"), totalCount),
369-
equalTo(stringKey("scheduling.apache-elasticjob.sharding.item.parameter"), parameter),
370+
List<AttributeAssertion> assertions = new ArrayList<>();
371+
372+
assertions.add(equalTo(stringKey("code.function"), codeFunction));
373+
assertions.add(equalTo(stringKey("code.namespace"), codeNamespace));
374+
375+
assertions.add(equalTo(stringKey("job.system"), experimental("elasticjob")));
376+
assertions.add(
377+
equalTo(stringKey("scheduling.apache-elasticjob.job.name"), experimental(jobName)));
378+
assertions.add(
379+
equalTo(stringKey("scheduling.apache-elasticjob.job.type"), experimental(jobType)));
380+
assertions.add(
381+
equalTo(longKey("scheduling.apache-elasticjob.sharding.item.index"), experimental(item)));
382+
assertions.add(
383+
equalTo(
384+
longKey("scheduling.apache-elasticjob.sharding.total.count"),
385+
experimental(totalCount)));
386+
assertions.add(
387+
equalTo(
388+
stringKey("scheduling.apache-elasticjob.sharding.item.parameter"),
389+
experimental(parameter)));
390+
assertions.add(
370391
satisfies(
371-
stringKey("scheduling.apache-elasticjob.task.id"), taskId -> taskId.contains(jobName)));
392+
stringKey("scheduling.apache-elasticjob.task.id"),
393+
taskId -> {
394+
if (EXPERIMENTAL_ATTRIBUTES_ENABLED) {
395+
taskId.contains(jobName);
396+
}
397+
}));
398+
399+
return assertions;
372400
}
373401
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
display_name: Apache ElasticJob
2+
description: This instrumentation enables spans for Apache ElasticJob job executions.
3+
library_link: https://shardingsphere.apache.org/elasticjob/
4+
configurations:
5+
- name: otel.instrumentation.apache-elasticjob.experimental-span-attributes
6+
description: >
7+
Enables experimental span attributes `job.system`, `scheduling.apache-elasticjob.job.name`,
8+
`scheduling.apache-elasticjob.task.id`, `scheduling.apache-elasticjob.sharding.item.index`,
9+
`scheduling.apache-elasticjob.sharding.total.count`,
10+
`scheduling.apache-elasticjob.sharding.item.parameter`, and
11+
`scheduling.apache-elasticjob.job.type`.
12+
type: boolean
13+
default: false

0 commit comments

Comments
 (0)