Skip to content

Commit 978aa55

Browse files
Merge branch 'main' of github.com:ghareeb-falazi/opentelemetry-java-instrumentation
2 parents ea200d3 + 2cb4f4f commit 978aa55

File tree

20 files changed

+240
-33
lines changed

20 files changed

+240
-33
lines changed

.github/renovate.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
'smoke-tests-otel-starter/spring-smoke-testing/build.gradle.kts',
200200
],
201201
matchPackageNames: [
202-
'org.springframework.boot:spring-boot-dependencies:**',
202+
'org.springframework.boot:spring-boot-dependencies',
203203
],
204204
enabled: false
205205
},

docs/instrumentation-list.yaml

Lines changed: 68 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
@@ -6573,12 +6620,33 @@ libraries:
65736620
type: STRING
65746621
jfinal:
65756622
- name: jfinal-3.2
6623+
display_name: JFinal
6624+
description: |
6625+
This instrumentation enriches HTTP server spans with route information, and enables controller spans for JFinal controller methods (controller spans are disabled by default).
6626+
library_link: https://github.com/jfinal/jfinal
6627+
features:
6628+
- HTTP_ROUTE
6629+
- CONTROLLER_SPANS
65766630
source_path: instrumentation/jfinal-3.2
65776631
scope:
65786632
name: io.opentelemetry.jfinal-3.2
65796633
target_versions:
65806634
javaagent:
65816635
- com.jfinal:jfinal:[3.2,)
6636+
configurations:
6637+
- name: otel.instrumentation.common.experimental.controller-telemetry.enabled
6638+
description: Enables the creation of experimental controller spans.
6639+
type: boolean
6640+
default: false
6641+
telemetry:
6642+
- when: default
6643+
spans:
6644+
- span_kind: INTERNAL
6645+
attributes:
6646+
- name: code.function
6647+
type: STRING
6648+
- name: code.namespace
6649+
type: STRING
65826650
jms:
65836651
- name: jms-1.1
65846652
display_name: JMS (Java Message Service)

instrumentation-docs/instrumentations.sh

Lines changed: 3 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"
@@ -148,6 +150,7 @@ readonly INSTRUMENTATIONS=(
148150
"jsf:jsf-myfaces-3.0:javaagent:test"
149151
"jsp-2.3:javaagent:test"
150152
"jsp-2.3:javaagent:testExperimental"
153+
"jfinal-3.2:javaagent:test"
151154
"kafka:kafka-clients:kafka-clients-2.6:library:test"
152155
"kafka:kafka-connect-2.6:testing:test"
153156
"ktor:ktor-1.0:library: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

instrumentation/graphql-java/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
|------------------------------------------------------------------------|---------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55
| `otel.instrumentation.graphql.query-sanitizer.enabled` | Boolean | `true` | Whether to remove sensitive information from query source that is added as span attribute. |
66
| `otel.instrumentation.graphql.add-operation-name-to-span-name.enabled` | Boolean | `false` | Whether GraphQL operation name is added to the span name. <p>**WARNING**: GraphQL operation name is provided by the client and can have high cardinality. Use only when the server is not exposed to malicious clients. |
7+
| `otel.instrumentation.graphql.capture-query` | Boolean | `true` | Whether to capture the query in `graphql.document` span attribute. |
78

89
# Settings for the GraphQL 20 instrumentation
910

instrumentation/graphql-java/graphql-java-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/graphql/v12_0/GraphqlSingletons.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
public final class GraphqlSingletons {
1515

16+
private static final boolean CAPTURE_QUERY =
17+
AgentInstrumentationConfig.get()
18+
.getBoolean("otel.instrumentation.graphql.capture-query", true);
1619
private static final boolean QUERY_SANITIZATION_ENABLED =
1720
AgentInstrumentationConfig.get()
1821
.getBoolean("otel.instrumentation.graphql.query-sanitizer.enabled", true);
@@ -23,6 +26,7 @@ public final class GraphqlSingletons {
2326

2427
private static final GraphQLTelemetry TELEMETRY =
2528
GraphQLTelemetry.builder(GlobalOpenTelemetry.get())
29+
.setCaptureQuery(CAPTURE_QUERY)
2630
.setSanitizeQuery(QUERY_SANITIZATION_ENABLED)
2731
.setAddOperationNameToSpanName(ADD_OPERATION_NAME_TO_SPAN_NAME)
2832
.build();

instrumentation/graphql-java/graphql-java-12.0/library/src/main/java/io/opentelemetry/instrumentation/graphql/v12_0/GraphQLTelemetry.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ public static GraphQLTelemetryBuilder builder(OpenTelemetry openTelemetry) {
2828
private final OpenTelemetryInstrumentationHelper helper;
2929

3030
GraphQLTelemetry(
31-
OpenTelemetry openTelemetry, boolean sanitizeQuery, boolean addOperationNameToSpanName) {
31+
OpenTelemetry openTelemetry,
32+
boolean captureQuery,
33+
boolean sanitizeQuery,
34+
boolean addOperationNameToSpanName) {
3235
helper =
3336
OpenTelemetryInstrumentationHelper.create(
34-
openTelemetry, INSTRUMENTATION_NAME, sanitizeQuery, addOperationNameToSpanName);
37+
openTelemetry,
38+
INSTRUMENTATION_NAME,
39+
captureQuery,
40+
sanitizeQuery,
41+
addOperationNameToSpanName);
3542
}
3643

3744
/**

instrumentation/graphql-java/graphql-java-12.0/library/src/main/java/io/opentelemetry/instrumentation/graphql/v12_0/GraphQLTelemetryBuilder.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ public final class GraphQLTelemetryBuilder {
1414

1515
private final OpenTelemetry openTelemetry;
1616

17+
private boolean captureQuery = true;
1718
private boolean sanitizeQuery = true;
1819
private boolean addOperationNameToSpanName = false;
1920

2021
GraphQLTelemetryBuilder(OpenTelemetry openTelemetry) {
2122
this.openTelemetry = openTelemetry;
2223
}
2324

25+
/**
26+
* Sets whether query should be captured in {@code graphql.document} span attribute. Default is
27+
* {@code true}.
28+
*/
29+
@CanIgnoreReturnValue
30+
public GraphQLTelemetryBuilder setCaptureQuery(boolean captureQuery) {
31+
this.captureQuery = captureQuery;
32+
return this;
33+
}
34+
2435
/** Sets whether sensitive information should be removed from queries. Default is {@code true}. */
2536
@CanIgnoreReturnValue
2637
public GraphQLTelemetryBuilder setSanitizeQuery(boolean sanitizeQuery) {
@@ -45,6 +56,7 @@ public GraphQLTelemetryBuilder setAddOperationNameToSpanName(boolean addOperatio
4556
* GraphQLTelemetryBuilder}.
4657
*/
4758
public GraphQLTelemetry build() {
48-
return new GraphQLTelemetry(openTelemetry, sanitizeQuery, addOperationNameToSpanName);
59+
return new GraphQLTelemetry(
60+
openTelemetry, captureQuery, sanitizeQuery, addOperationNameToSpanName);
4961
}
5062
}

0 commit comments

Comments
 (0)