Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/instrumentation-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions instrumentation-docs/instrumentations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ dependencies {
testImplementation("org.apache.curator:curator-test:5.1.0")
}

tasks.withType<Test>().configureEach {
jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true")
tasks {
withType<Test>().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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -150,7 +154,7 @@ void testSimpleJob() {
regCenter,
job,
JobConfiguration.newBuilder("simpleElasticJob", 2)
.cron("0/5 * * * * ?")
.cron("0/30 * * * * ?")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was causing some headaches while i was refactoring, due to the small interval there were more spans created than expected

.shardingItemParameters("0=A,1=B")
.build());

Expand Down Expand Up @@ -350,6 +354,11 @@ private static String buildScriptCommandLine() throws IOException {
return tempScript.toString();
}

@Nullable
private static <T> T experimental(T value) {
return EXPERIMENTAL_ATTRIBUTES_ENABLED ? value : null;
}

private static List<AttributeAssertion> elasticJobAttributes(
String jobName,
long item,
Expand All @@ -358,16 +367,35 @@ private static List<AttributeAssertion> 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<AttributeAssertion> 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;
}
}
13 changes: 13 additions & 0 deletions instrumentation/apache-elasticjob-3.0/metadata.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading