Skip to content

Commit 781aae7

Browse files
[tracer] add tag response data
1 parent b6f37ed commit 781aae7

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

graphql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
196196

197197
validationFinish := s.validationTracer.TraceValidation(ctx)
198198
errs := validation.Validate(s.schema, doc, variables, s.maxDepth)
199-
validationFinish(errs)
199+
validationFinish(nil, errs)
200200
if len(errs) != 0 {
201201
return &Response{Errors: errs}
202202
}
@@ -253,7 +253,7 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
253253
}
254254
traceCtx, finish := s.tracer.TraceQuery(ctx, queryString, operationName, variables, varTypes)
255255
data, errs := r.Execute(traceCtx, res, op)
256-
finish(errs)
256+
finish(data, errs)
257257

258258
return &Response{
259259
Data: data,

internal/exec/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func execFieldSelection(ctx context.Context, r *Request, s *resolvable.Schema, f
190190

191191
traceCtx, finish := r.Tracer.TraceField(ctx, f.field.TraceLabel, f.field.TypeName, f.field.Name, !f.field.Async, f.field.Args)
192192
defer func() {
193-
finish(err)
193+
finish(f.out.Bytes(), err)
194194
}()
195195

196196
err = func() (err *errors.QueryError) {

subscriptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam
3838

3939
validationFinish := s.validationTracer.TraceValidation(ctx)
4040
errs := validation.Validate(s.schema, doc, variables, s.maxDepth)
41-
validationFinish(errs)
41+
validationFinish(nil, errs)
4242
if len(errs) != 0 {
4343
return sendAndReturnClosed(&Response{Errors: errs})
4444
}

trace/trace.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/opentracing/opentracing-go/log"
1212
)
1313

14-
type TraceQueryFinishFunc func([]*errors.QueryError)
15-
type TraceFieldFinishFunc func(*errors.QueryError)
14+
type TraceQueryFinishFunc func([]byte, []*errors.QueryError)
15+
type TraceFieldFinishFunc func([]byte, *errors.QueryError)
1616

1717
type Tracer interface {
1818
TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, TraceQueryFinishFunc)
@@ -33,7 +33,7 @@ func (OpenTracingTracer) TraceQuery(ctx context.Context, queryString string, ope
3333
span.LogFields(log.Object("graphql.variables", variables))
3434
}
3535

36-
return spanCtx, func(errs []*errors.QueryError) {
36+
return spanCtx, func(data []byte, errs []*errors.QueryError) {
3737
if len(errs) > 0 {
3838
msg := errs[0].Error()
3939
if len(errs) > 1 {
@@ -58,7 +58,7 @@ func (OpenTracingTracer) TraceField(ctx context.Context, label, typeName, fieldN
5858
span.SetTag("graphql.args."+name, value)
5959
}
6060

61-
return spanCtx, func(err *errors.QueryError) {
61+
return spanCtx, func(data []byte, err *errors.QueryError) {
6262
if err != nil {
6363
ext.Error.Set(span, true)
6464
span.SetTag("graphql.error", err.Error())
@@ -67,30 +67,14 @@ func (OpenTracingTracer) TraceField(ctx context.Context, label, typeName, fieldN
6767
}
6868
}
6969

70-
func (OpenTracingTracer) TraceValidation(ctx context.Context) TraceValidationFinishFunc {
71-
span, _ := opentracing.StartSpanFromContext(ctx, "Validate Query")
72-
73-
return func(errs []*errors.QueryError) {
74-
if len(errs) > 0 {
75-
msg := errs[0].Error()
76-
if len(errs) > 1 {
77-
msg += fmt.Sprintf(" (and %d more errors)", len(errs)-1)
78-
}
79-
ext.Error.Set(span, true)
80-
span.SetTag("graphql.error", msg)
81-
}
82-
span.Finish()
83-
}
84-
}
85-
86-
func noop(*errors.QueryError) {}
70+
func noop([]byte, *errors.QueryError) {}
8771

8872
type NoopTracer struct{}
8973

9074
func (NoopTracer) TraceQuery(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, varTypes map[string]*introspection.Type) (context.Context, TraceQueryFinishFunc) {
91-
return ctx, func(errs []*errors.QueryError) {}
75+
return ctx, func(data []byte, errs []*errors.QueryError) {}
9276
}
9377

9478
func (NoopTracer) TraceField(ctx context.Context, label, typeName, fieldName string, trivial bool, args map[string]interface{}) (context.Context, TraceFieldFinishFunc) {
95-
return ctx, func(err *errors.QueryError) {}
79+
return ctx, func(data []byte, err *errors.QueryError) {}
9680
}

trace/validation_trace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ type NoopValidationTracer struct{}
2121

2222
// Deprecated: use a Tracer which implements ValidationTracerContext.
2323
func (NoopValidationTracer) TraceValidation() TraceValidationFinishFunc {
24-
return func(errs []*errors.QueryError) {}
24+
return func(data []byte, errs []*errors.QueryError) {}
2525
}

0 commit comments

Comments
 (0)