@@ -11254,6 +11254,139 @@ func TestFlakyTelemetry(t *testing.T) {
1125411254 })
1125511255 })
1125611256
11257+ t .Run ("verify errors being attached to unrelated span subgraphs" , func (t * testing.T ) {
11258+ simulateConnectionFailureOnClose := func (w http.ResponseWriter ) {
11259+ hj , ok := w .(http.Hijacker )
11260+ if ! ok {
11261+ // If the hijacker is not available, we switch to panic
11262+ // to simulate a failure
11263+ panic ("service failure" )
11264+ }
11265+ conn , _ , err := hj .Hijack ()
11266+ if err != nil {
11267+ // Hijacking failed, switch to panic
11268+ // to simulate a failure
11269+ panic (err )
11270+ }
11271+ _ = conn .Close ()
11272+ }
11273+
11274+ t .Run ("with one subgraph giving an error" , func (t * testing.T ) {
11275+ t .Parallel ()
11276+
11277+ exporter := tracetest .NewInMemoryExporter (t )
11278+ testenv .Run (t , & testenv.Config {
11279+ TraceExporter : exporter ,
11280+ Subgraphs : testenv.SubgraphsConfig {
11281+ Products : testenv.SubgraphConfig {
11282+ Middleware : func (_ http.Handler ) http.Handler {
11283+ return http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
11284+ simulateConnectionFailureOnClose (w )
11285+ })
11286+ },
11287+ },
11288+ },
11289+ }, func (t * testing.T , xEnv * testenv.Environment ) {
11290+ xEnv .MakeGraphQLRequestOK (testenv.GraphQLRequest {
11291+ Query : `query { employees { id isAvailable products derivedMood } }` ,
11292+ })
11293+
11294+ sn := exporter .GetSpans ().Snapshots ()
11295+
11296+ subgraphThatShouldHaveError := "products"
11297+
11298+ for _ , span := range sn {
11299+ if slices .Contains ([]string {"Engine - Fetch" }, span .Name ()) {
11300+ attributes := span .Attributes ()
11301+ events := span .Events ()
11302+
11303+ hasErrorEvent := false
11304+ subgraphName := ""
11305+
11306+ if len (events ) > 0 {
11307+ require .Len (t , events , 1 )
11308+ require .Equal (t , "exception" , events [0 ].Name )
11309+ hasErrorEvent = true
11310+ }
11311+
11312+ for _ , attributeEntry := range attributes {
11313+ if attributeEntry .Key == otel .WgSubgraphName {
11314+ subgraphName = attributeEntry .Value .AsString ()
11315+ }
11316+ }
11317+
11318+ if subgraphName == subgraphThatShouldHaveError {
11319+ require .True (t , hasErrorEvent )
11320+ } else {
11321+ require .False (t , hasErrorEvent )
11322+ }
11323+ }
11324+ }
11325+ })
11326+ })
11327+
11328+ t .Run ("with multiple subgraphs giving an error" , func (t * testing.T ) {
11329+ t .Parallel ()
11330+
11331+ exporter := tracetest .NewInMemoryExporter (t )
11332+ testenv .Run (t , & testenv.Config {
11333+ TraceExporter : exporter ,
11334+ Subgraphs : testenv.SubgraphsConfig {
11335+ Products : testenv.SubgraphConfig {
11336+ Middleware : func (_ http.Handler ) http.Handler {
11337+ return http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
11338+ simulateConnectionFailureOnClose (w )
11339+ })
11340+ },
11341+ },
11342+ Availability : testenv.SubgraphConfig {
11343+ Middleware : func (_ http.Handler ) http.Handler {
11344+ return http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
11345+ simulateConnectionFailureOnClose (w )
11346+ })
11347+ },
11348+ },
11349+ },
11350+ }, func (t * testing.T , xEnv * testenv.Environment ) {
11351+ xEnv .MakeGraphQLRequestOK (testenv.GraphQLRequest {
11352+ Query : `query { employees { id isAvailable derivedMood products } }` ,
11353+ })
11354+
11355+ sn := exporter .GetSpans ().Snapshots ()
11356+
11357+ subgraphsThatShouldHaveError := []string {"products" , "availability" }
11358+
11359+ for _ , span := range sn {
11360+ if slices .Contains ([]string {"Engine - Fetch" }, span .Name ()) {
11361+ attributes := span .Attributes ()
11362+ events := span .Events ()
11363+
11364+ hasErrorEvent := false
11365+ subgraphName := ""
11366+
11367+ if len (events ) > 0 {
11368+ require .Len (t , events , 1 )
11369+ require .Equal (t , "exception" , events [0 ].Name )
11370+ hasErrorEvent = true
11371+ }
11372+
11373+ for _ , attributeEntry := range attributes {
11374+ if attributeEntry .Key == otel .WgSubgraphName {
11375+ subgraphName = attributeEntry .Value .AsString ()
11376+ }
11377+ }
11378+
11379+ if slices .Contains (subgraphsThatShouldHaveError , subgraphName ) {
11380+ require .True (t , hasErrorEvent )
11381+ } else {
11382+ require .False (t , hasErrorEvent )
11383+ }
11384+ }
11385+ }
11386+ })
11387+ })
11388+ })
11389+
1125711390}
1125811391
1125911392func TestExcludeAttributesWithCustomExporter (t * testing.T ) {
0 commit comments