Skip to content

Commit 729f559

Browse files
authored
Metadata for graphql-java (#14526)
1 parent 46e9261 commit 729f559

File tree

8 files changed

+137
-7
lines changed

8 files changed

+137
-7
lines changed

docs/instrumentation-list.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,6 +3014,7 @@ libraries:
30143014
attributes: []
30153015
graphql:
30163016
- name: graphql-java-12.0
3017+
description: This instrumentation enables spans for GraphQL Java operations.
30173018
source_path: instrumentation/graphql-java/graphql-java-12.0
30183019
scope:
30193020
name: io.opentelemetry.graphql-java-12.0
@@ -3022,7 +3023,30 @@ libraries:
30223023
- com.graphql-java:graphql-java:[12,20)
30233024
library:
30243025
- com.graphql-java:graphql-java:[12.0,19.+)
3026+
configurations:
3027+
- name: otel.instrumentation.graphql.query-sanitizer.enabled
3028+
description: Enables sanitization of sensitive information from queries so they
3029+
aren't added as span attributes.
3030+
type: boolean
3031+
default: true
3032+
- name: otel.instrumentation.graphql.add-operation-name-to-span-name.enabled
3033+
description: |
3034+
Whether GraphQL operation name is added to the span name. WARNING: The GraphQL operation name is provided by the client and can have high cardinality. Use only when the server is not exposed to malicious clients.
3035+
type: boolean
3036+
default: false
3037+
telemetry:
3038+
- when: default
3039+
spans:
3040+
- span_kind: INTERNAL
3041+
attributes:
3042+
- name: graphql.document
3043+
type: STRING
3044+
- name: graphql.operation.name
3045+
type: STRING
3046+
- name: graphql.operation.type
3047+
type: STRING
30253048
- name: graphql-java-20.0
3049+
description: This instrumentation enables spans for GraphQL Java operations.
30263050
source_path: instrumentation/graphql-java/graphql-java-20.0
30273051
minimum_java_version: 11
30283052
scope:
@@ -3032,6 +3056,51 @@ libraries:
30323056
- com.graphql-java:graphql-java:[20,)
30333057
library:
30343058
- com.graphql-java:graphql-java:20.0
3059+
configurations:
3060+
- name: otel.instrumentation.graphql.query-sanitizer.enabled
3061+
description: Enables sanitization of sensitive information from queries so they
3062+
aren't added as span attributes.
3063+
type: boolean
3064+
default: true
3065+
- name: otel.instrumentation.graphql.add-operation-name-to-span-name.enabled
3066+
description: |
3067+
Whether GraphQL operation name is added to the span name. WARNING: The GraphQL operation name is provided by the client and can have high cardinality. Use only when the server is not exposed to malicious clients.
3068+
type: boolean
3069+
default: false
3070+
- name: otel.instrumentation.graphql.data-fetcher.enabled
3071+
description: Enables span generation for data fetchers.
3072+
type: boolean
3073+
default: false
3074+
- name: otel.instrumentation.graphql.trivial-data-fetcher.enabled
3075+
description: Whether to create spans for trivial data fetchers. A trivial data
3076+
fetcher is one that simply maps data from an object to a field.
3077+
type: boolean
3078+
default: false
3079+
telemetry:
3080+
- when: default
3081+
spans:
3082+
- span_kind: INTERNAL
3083+
attributes:
3084+
- name: graphql.document
3085+
type: STRING
3086+
- name: graphql.operation.name
3087+
type: STRING
3088+
- name: graphql.operation.type
3089+
type: STRING
3090+
- when: otel.instrumentation.graphql.data-fetcher.enabled=true
3091+
spans:
3092+
- span_kind: INTERNAL
3093+
attributes:
3094+
- name: graphql.document
3095+
type: STRING
3096+
- name: graphql.field.name
3097+
type: STRING
3098+
- name: graphql.field.path
3099+
type: STRING
3100+
- name: graphql.operation.name
3101+
type: STRING
3102+
- name: graphql.operation.type
3103+
type: STRING
30353104
grizzly:
30363105
- name: grizzly-2.3
30373106
description: This instrumentation enables HTTP SERVER spans and metrics for Grizzly

instrumentation-docs/instrumentations.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ readonly INSTRUMENTATIONS=(
137137
"grails-3.0:javaagent:test"
138138
"grizzly-2.3:javaagent:test"
139139
"gwt-2.0:javaagent:test"
140+
"graphql-java:graphql-java-12.0:javaagent:test"
141+
"graphql-java:graphql-java-20.0:javaagent:test"
142+
"graphql-java:graphql-java-20.0:javaagent:testDataFetcher"
140143
)
141144

142145
# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64

instrumentation/graphql-java/graphql-java-12.0/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ dependencies {
2727

2828
tasks.withType<Test>().configureEach {
2929
jvmArgs("-Dotel.instrumentation.graphql.add-operation-name-to-span-name.enabled=true")
30+
31+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
3032
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: This instrumentation enables spans for GraphQL Java operations.
2+
configurations:
3+
- name: otel.instrumentation.graphql.query-sanitizer.enabled
4+
description: Enables sanitization of sensitive information from queries so they aren't added as span attributes.
5+
type: boolean
6+
default: true
7+
- name: otel.instrumentation.graphql.add-operation-name-to-span-name.enabled
8+
description: >
9+
Whether GraphQL operation name is added to the span name. WARNING: The GraphQL operation name is
10+
provided by the client and can have high cardinality. Use only when the server is not exposed to malicious
11+
clients.
12+
type: boolean
13+
default: false

instrumentation/graphql-java/graphql-java-20.0/javaagent/build.gradle.kts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ dependencies {
2323
testImplementation(project(":instrumentation:graphql-java:graphql-java-common:testing"))
2424
}
2525

26-
tasks.withType<Test>().configureEach {
27-
jvmArgs("-Dotel.instrumentation.graphql.data-fetcher.enabled=true")
28-
jvmArgs("-Dotel.instrumentation.graphql.add-operation-name-to-span-name.enabled=true")
26+
tasks {
27+
withType<Test>().configureEach {
28+
jvmArgs("-Dotel.instrumentation.graphql.add-operation-name-to-span-name.enabled=true")
29+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
30+
}
31+
32+
val testDataFetcher by registering(Test::class) {
33+
jvmArgs("-Dotel.instrumentation.graphql.data-fetcher.enabled=true")
34+
systemProperty("metadataConfig", "otel.instrumentation.graphql.data-fetcher.enabled=true")
35+
}
36+
37+
check {
38+
dependsOn(testDataFetcher)
39+
}
2940
}
3041

3142
if (findProperty("testLatestDeps") as Boolean) {

instrumentation/graphql-java/graphql-java-20.0/library/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ if (findProperty("testLatestDeps") as Boolean) {
1414
minJavaVersionSupported.set(JavaVersion.VERSION_11)
1515
}
1616
}
17+
18+
tasks.withType<Test>().configureEach {
19+
jvmArgs("-Dotel.instrumentation.graphql.data-fetcher.enabled=true")
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
description: This instrumentation enables spans for GraphQL Java operations.
2+
configurations:
3+
- name: otel.instrumentation.graphql.query-sanitizer.enabled
4+
description: Enables sanitization of sensitive information from queries so they aren't added as span attributes.
5+
type: boolean
6+
default: true
7+
- name: otel.instrumentation.graphql.add-operation-name-to-span-name.enabled
8+
description: >
9+
Whether GraphQL operation name is added to the span name. WARNING: The GraphQL operation name is
10+
provided by the client and can have high cardinality. Use only when the server is not exposed to malicious
11+
clients.
12+
type: boolean
13+
default: false
14+
- name: otel.instrumentation.graphql.data-fetcher.enabled
15+
description: Enables span generation for data fetchers.
16+
type: boolean
17+
default: false
18+
- name: otel.instrumentation.graphql.trivial-data-fetcher.enabled
19+
description: Whether to create spans for trivial data fetchers. A trivial data fetcher is one that simply maps data from an object to a field.
20+
type: boolean
21+
default: false

instrumentation/graphql-java/graphql-java-common/testing/src/main/java/io/opentelemetry/instrumentation/graphql/AbstractGraphqlTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4545
public abstract class AbstractGraphqlTest {
4646

47+
private static final String DATA_FETCHER_PROPERTY =
48+
"otel.instrumentation.graphql.data-fetcher.enabled";
49+
4750
private final List<Map<String, String>> books = new ArrayList<>();
4851
private final List<Map<String, String>> authors = new ArrayList<>();
4952

@@ -58,6 +61,10 @@ protected boolean hasDataFetcherSpans() {
5861
return false;
5962
}
6063

64+
private boolean includeDataFetcher() {
65+
return Boolean.getBoolean(DATA_FETCHER_PROPERTY) && hasDataFetcherSpans();
66+
}
67+
6168
@BeforeAll
6269
void setup() throws IOException {
6370
addAuthor("author-1", "John");
@@ -162,7 +169,7 @@ void successfulQuery() {
162169
normalizedQueryEqualsTo(
163170
GraphqlIncubatingAttributes.GRAPHQL_DOCUMENT,
164171
"query findBookById { bookById(id: ?) { name } }")));
165-
if (hasDataFetcherSpans()) {
172+
if (includeDataFetcher()) {
166173
assertions.add(
167174
span ->
168175
span.hasName("bookById")
@@ -174,7 +181,7 @@ void successfulQuery() {
174181
assertions.add(
175182
span ->
176183
span.hasName("fetchBookById")
177-
.hasParent(trace.getSpan(hasDataFetcherSpans() ? 1 : 0)));
184+
.hasParent(trace.getSpan(includeDataFetcher() ? 1 : 0)));
178185

179186
trace.hasSpansSatisfyingExactly(assertions);
180187
});
@@ -207,7 +214,7 @@ void successfulQueryWithoutName() {
207214
normalizedQueryEqualsTo(
208215
AttributeKey.stringKey("graphql.document"),
209216
"{ bookById(id: ?) { name } }")));
210-
if (hasDataFetcherSpans()) {
217+
if (includeDataFetcher()) {
211218
assertions.add(
212219
span ->
213220
span.hasName("bookById")
@@ -219,7 +226,7 @@ void successfulQueryWithoutName() {
219226
assertions.add(
220227
span ->
221228
span.hasName("fetchBookById")
222-
.hasParent(trace.getSpan(hasDataFetcherSpans() ? 1 : 0)));
229+
.hasParent(trace.getSpan(includeDataFetcher() ? 1 : 0)));
223230
trace.hasSpansSatisfyingExactly(assertions);
224231
});
225232
}

0 commit comments

Comments
 (0)