From dbe5649e3ec55e7dad51d543a64fc0abe1210624 Mon Sep 17 00:00:00 2001 From: Radu Simionescu Date: Tue, 12 Dec 2023 00:48:15 -0800 Subject: [PATCH] fix: typo triggers panic in certain scenarios (#82) --- tracer.go | 2 +- tracer_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tracer.go b/tracer.go index e596a1e..f0ea4ba 100644 --- a/tracer.go +++ b/tracer.go @@ -61,7 +61,7 @@ func (t Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHand semconv.GraphqlDocument(oc.RawQuery), ) if operationName != "" { - span.SetAttributes(semconv.GraphqlOperationName(oc.Operation.Name)) + span.SetAttributes(semconv.GraphqlOperationName(operationName)) } if stats := extension.GetComplexityStats(ctx); stats != nil { span.SetAttributes(graphqlComplexity.Int(stats.Complexity)) diff --git a/tracer_test.go b/tracer_test.go index 4150a1f..57f8000 100644 --- a/tracer_test.go +++ b/tracer_test.go @@ -115,13 +115,13 @@ func (s *TracerSuite) TestQuery_ParsingError() { query := "query GetGreeting { greeting" var res struct{ Greeting string } - s.Require().Error(c.Post(query, &res)) + s.Require().Error(c.Post(query, &res, func(req *client.Request) { req.OperationName = "GetGreeting" })) spans := s.Exporter.GetSpans() s.Require().Len(spans, 1) s.Require().Equal("GraphQL Operation", spans[0].Name) s.Require().Equal(codes.Error, spans[0].Status.Code) - s.Require().Len(spans[0].Attributes, 3) + s.Require().Len(spans[0].Attributes, 4) } func (s *TracerSuite) TestMutation_SpanCreated() {