@@ -78,7 +78,7 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
7878 .type(newTypeWiring(" Book" ). dataFetcher(" year" , new DataFetcher<CompletionStage<Integer > > () {
7979 @Override
8080 CompletionStage<Integer > get (DataFetchingEnvironment environment ) throws Exception {
81- return CompletableFuture . completedStage (2015 )
81+ return CompletableFuture . completedFuture (2015 )
8282 }
8383 }))
8484 .build()
@@ -359,31 +359,25 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
359359 " graphql.operation.name" null
360360 " error.message" { it. contains(" Field 'title' in type 'Book' is undefined" ) }
361361 " error.message" { it. contains(" (and 1 more errors)" ) }
362- defaultTags()
363- events {
364- event {
365- eventName " error"
366- attributes {
367- " error.type" " graphql.validation.ValidationError"
368- " error.message" " Field 'title' in type 'Book' is undefined"
369- " error.stack" String
370- " graphql.error.path" null
371- }
372- }
373- event {
374- eventName " error"
375- attributes {
376- " error.type" " graphql.validation.ValidationError"
377- " error.message" " Field 'color' in type 'Book' is undefined"
378- " error.stack" String
379- " graphql.error.path" null
380- }
381- }
362+ " events" {
363+ def events = new groovy.json.JsonSlurper (). parseText(it) as List
364+ events. size() == 2
365+ def event1 = events[0 ]
366+ event1. name == " dd.graphql.query.error"
367+ event1. time_unix_nano instanceof Long
368+ def attrs1 = event1. attributes
369+ attrs1. message == " Validation error of type FieldUndefined: Field 'title' in type 'Book' is undefined @ 'bookById/title'"
370+ attrs1. locations == [" 4:5" ]
371+
372+ def event2 = events[1 ]
373+ event2. name == " dd.graphql.query.error"
374+ event2. time_unix_nano instanceof Long
375+ def attrs2 = event2. attributes
376+ attrs2. message == " Validation error of type FieldUndefined: Field 'color' in type 'Book' is undefined @ 'bookById/color'"
377+ attrs2. locations == [" 5:5" ]
382378 }
383-
384-
379+ defaultTags()
385380 }
386-
387381 }
388382 span {
389383 operationName " graphql.validation"
@@ -439,19 +433,18 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
439433 " $Tags . COMPONENT " " graphql-java"
440434 " graphql.source" query
441435 " graphql.operation.name" null
442- " error.message" " Invalid Syntax : offending token ')' at line 2 column 30"
443- defaultTags()
444- }
445- events {
446- event {
447- eventName " error"
448- attributes {
449- " error.type" " graphql.parser.InvalidSyntaxException"
450- " error.message" " Invalid Syntax : offending token ')' at line 2 column 30"
451- " error.stack" String
452- " graphql.error.path" null
453- }
436+ " error.message" { it. toLowerCase(). startsWith(" invalid syntax" ) }
437+ " events" {
438+ def events = new groovy.json.JsonSlurper (). parseText(it) as List
439+ events. size() == 1
440+ def event = events[0 ]
441+ event. name == " dd.graphql.query.error"
442+ event. time_unix_nano instanceof Long
443+ def attrs = event. attributes
444+ attrs. message == " Invalid Syntax : offending token ')' at line 2 column 25"
445+ attrs. locations == [" 2:25" ]
454446 }
447+ defaultTags()
455448 }
456449 }
457450 span {
@@ -464,7 +457,7 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
464457 tags {
465458 " $Tags . COMPONENT " " graphql-java"
466459 " error.type" " graphql.parser.InvalidSyntaxException"
467- " error.message" " Invalid Syntax : offending token ')' at line 2 column 30 "
460+ " error.message" { it . toLowerCase() . startsWith( " invalid syntax " ) }
468461 " error.stack" String
469462 defaultTags()
470463 }
@@ -506,6 +499,17 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
506499 " graphql.source" expectedQuery
507500 " graphql.operation.name" " findBookById"
508501 " error.message" " Exception while fetching data (/bookById/cover) : TEST"
502+ " events" {
503+ def events = new groovy.json.JsonSlurper (). parseText(it) as List
504+ events. size() == 1
505+ def event = events[0 ]
506+ event. name == " dd.graphql.query.error"
507+ event. time_unix_nano instanceof Long
508+ def attrs = event. attributes
509+ attrs. message == " Exception while fetching data (/bookById/cover) : TEST"
510+ attrs. locations == [" 4:5" ]
511+ attrs. path == [" bookById" , " cover" ]
512+ }
509513 defaultTags()
510514 }
511515 }
@@ -682,152 +686,6 @@ abstract class GraphQLTest extends VersionedNamingTestBase {
682686 }
683687 }
684688 }
685-
686- def " query fetch error with span events" () {
687- setup :
688- def query = ' query findBookById {\n ' +
689- ' bookById(id: "book-1") {\n ' +
690- ' id #test\n ' +
691- ' cover\n ' + // throws an exception when fetched
692- ' year\n ' + // also throws an exception
693- ' }\n ' +
694- ' }'
695- def expectedQuery = ' query findBookById {\n ' +
696- ' bookById(id: {String}) {\n ' +
697- ' id\n ' +
698- ' cover\n ' +
699- ' year\n ' +
700- ' }\n ' +
701- ' }\n '
702- ExecutionResult result = graphql. execute(query)
703-
704- expect :
705- ! result. getErrors(). isEmpty()
706-
707- assertTraces(1 ) {
708- trace(7 ) {
709- span {
710- operationName operation()
711- resourceName " findBookById"
712- spanType DDSpanTypes . GRAPHQL
713- errored true
714- measured true
715- parent()
716- tags {
717- " $Tags . COMPONENT " " graphql-java"
718- " graphql.source" expectedQuery
719- " graphql.operation.name" " findBookById"
720- " error.message" { it. contains(" Exception while fetching data (/bookById/cover) : TEST" ) }
721- defaultTags()
722- }
723- events {
724- event {
725- eventName " error"
726- attributes {
727- " error.type" " java.lang.IllegalStateException"
728- " error.message" " TEST"
729- " error.stack" String
730- " graphql.error.path" " /bookById/cover"
731- }
732- }
733- event {
734- eventName " error"
735- attributes {
736- " error.type" " java.lang.IllegalStateException"
737- " error.message" " TEST"
738- " error.stack" String
739- " graphql.error.path" " /bookById/year"
740- }
741- }
742- }
743- }
744- span {
745- operationName " graphql.field"
746- resourceName " Book.cover"
747- childOf(span(0 ))
748- spanType DDSpanTypes . GRAPHQL
749- errored true
750- measured true
751- tags {
752- " $Tags . COMPONENT " " graphql-java"
753- " graphql.type" " String"
754- " graphql.coordinates" " Book.cover"
755- " error.type" " java.lang.IllegalStateException"
756- " error.message" " TEST"
757- " error.stack" String
758- defaultTags()
759- }
760- }
761- span {
762- operationName " Book.year"
763- resourceName " Book.year"
764- childOf(span(0 ))
765- spanType DDSpanTypes . GRAPHQL
766- errored true
767- measured true
768- tags {
769- " $Tags . COMPONENT " " graphql-java"
770- " graphql.type" " Int"
771- " graphql.coordinates" " Book.year"
772- " error.type" " java.lang.IllegalStateException"
773- " error.message" " TEST"
774- " error.stack" String
775- defaultTags()
776- }
777- }
778- span {
779- operationName " graphql.field"
780- resourceName " Query.bookById"
781- childOf(span(0 ))
782- spanType DDSpanTypes . GRAPHQL
783- errored false
784- measured true
785- tags {
786- " $Tags . COMPONENT " " graphql-java"
787- " graphql.type" " Book"
788- " graphql.coordinates" " Query.bookById"
789- defaultTags()
790- }
791- }
792- span {
793- operationName " getBookById"
794- resourceName " book"
795- childOf(span(3 ))
796- spanType null
797- errored false
798- measured false
799- tags {
800- " $Tags . COMPONENT " " trace"
801- defaultTags()
802- }
803- }
804- span {
805- operationName " graphql.validation"
806- resourceName " graphql.validation"
807- childOf(span(0 ))
808- spanType DDSpanTypes . GRAPHQL
809- errored false
810- measured true
811- tags {
812- " $Tags . COMPONENT " " graphql-java"
813- defaultTags()
814- }
815- }
816- span {
817- operationName " graphql.parsing"
818- resourceName " graphql.parsing"
819- childOf(span(0 ))
820- spanType DDSpanTypes . GRAPHQL
821- errored false
822- measured true
823- tags {
824- " $Tags . COMPONENT " " graphql-java"
825- defaultTags()
826- }
827- }
828- }
829- }
830- }
831689}
832690
833691@Flaky
0 commit comments