File tree Expand file tree Collapse file tree 2 files changed +32
-18
lines changed
dd-java-agent/instrumentation/graphql-java-14.0/src
main/java8/datadog/trace/instrumentation/graphqljava Expand file tree Collapse file tree 2 files changed +32
-18
lines changed Original file line number Diff line number Diff line change 1111import graphql .schema .DataFetchingEnvironment ;
1212import graphql .schema .GraphQLNamedType ;
1313import graphql .schema .GraphQLOutputType ;
14+ import java .util .concurrent .CompletableFuture ;
15+ import java .util .concurrent .CompletionException ;
1416
1517public class InstrumentedDataFetcher implements DataFetcher <Object > {
1618 private final DataFetcher <?> dataFetcher ;
@@ -41,7 +43,20 @@ public Object get(DataFetchingEnvironment environment) throws Exception {
4143 fieldSpan .setTag ("graphql.type" , typeName );
4244 }
4345 try (AgentScope scope = activateSpan (fieldSpan )) {
44- return dataFetcher .get (environment );
46+ Object result = dataFetcher .get (environment );
47+ if (result instanceof CompletableFuture ) {
48+ return ((CompletableFuture <?>) result )
49+ .whenComplete (
50+ (r , e ) -> {
51+ if (e instanceof CompletionException ) {
52+ CompletionException ce = (CompletionException ) e ;
53+ DECORATE .onError (fieldSpan , ce .getCause ());
54+ }
55+ });
56+ // TODO if it's a CompletableFuture then add a callback to set fieldSpan's error tags when
57+ // it fails
58+ }
59+ return result ;
4560 } catch (Exception e ) {
4661 fieldSpan .addThrowable (e );
4762 throw e ;
Original file line number Diff line number Diff line change @@ -115,18 +115,6 @@ class GraphQLAsyncTest extends AgentTestRunner {
115115 defaultTags()
116116 }
117117 }
118- span {
119- operationName " getBookById"
120- resourceName " book"
121- childOf(span(3 ))
122- spanType null
123- errored false
124- measured false
125- tags {
126- " $Tags . COMPONENT " " trace"
127- defaultTags()
128- }
129- }
130118 span {
131119 operationName " graphql.field"
132120 resourceName " graphql.field"
@@ -140,6 +128,18 @@ class GraphQLAsyncTest extends AgentTestRunner {
140128 defaultTags()
141129 }
142130 }
131+ span {
132+ operationName " getBookById"
133+ resourceName " book"
134+ childOf(span(2 ))
135+ spanType null
136+ errored false
137+ measured false
138+ tags {
139+ " $Tags . COMPONENT " " trace"
140+ defaultTags()
141+ }
142+ }
143143 span {
144144 operationName " graphql.validation"
145145 resourceName " graphql.validation"
@@ -210,15 +210,14 @@ class GraphQLAsyncTest extends AgentTestRunner {
210210 resourceName " graphql.field"
211211 childOf(span(0 ))
212212 spanType DDSpanTypes . GRAPHQL
213- // TODO this span is not marked as errored when async fetcher is in use
214- // errored true
213+ errored true
215214 measured true
216215 tags {
217216 " $Tags . COMPONENT " " graphql-java"
218217 " graphql.type" " String"
219- // "error.type" "java.lang.IllegalStateException"
220- // "error.msg" "TEST"
221- // "error.stack" String
218+ " error.type" " java.lang.IllegalStateException"
219+ " error.msg" " TEST"
220+ " error.stack" String
222221 defaultTags()
223222 }
224223 }
You can’t perform that action at this time.
0 commit comments