Skip to content

Commit 341bb2f

Browse files
Reformat
Signed-off-by: Steve Coffman <[email protected]>
1 parent 3531359 commit 341bb2f

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

gqlopencensus/tracer.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"context"
55
"fmt"
66

7+
"go.opencensus.io/trace"
8+
79
"github.com/99designs/gqlgen/graphql"
810
"github.com/99designs/gqlgen/graphql/handler/extension"
9-
"go.opencensus.io/trace"
1011
)
1112

1213
type (
@@ -30,7 +31,10 @@ func (a Tracer) Validate(schema graphql.ExecutableSchema) error {
3031
return nil
3132
}
3233

33-
func (a Tracer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
34+
func (a Tracer) InterceptOperation(
35+
ctx context.Context,
36+
next graphql.OperationHandler,
37+
) graphql.ResponseHandler {
3438
ctx, span := trace.StartSpan(ctx, operationName(ctx))
3539
if !span.IsRecordingEvents() {
3640
return next(ctx)
@@ -60,7 +64,10 @@ func (a Tracer) InterceptOperation(ctx context.Context, next graphql.OperationHa
6064

6165
for key, val := range oc.Variables {
6266
span.AddAttributes(
63-
trace.StringAttribute(fmt.Sprintf("request.variables.%s", key), fmt.Sprintf("%+v", val)),
67+
trace.StringAttribute(
68+
fmt.Sprintf("request.variables.%s", key),
69+
fmt.Sprintf("%+v", val),
70+
),
6471
)
6572
}
6673

@@ -89,7 +96,10 @@ func (a Tracer) InterceptField(ctx context.Context, next graphql.Resolver) (inte
8996
for _, arg := range fc.Field.Arguments {
9097
if arg.Value != nil {
9198
span.AddAttributes(
92-
trace.StringAttribute(fmt.Sprintf("resolver.args.%s", arg.Name), arg.Value.String()),
99+
trace.StringAttribute(
100+
fmt.Sprintf("resolver.args.%s", arg.Name),
101+
arg.Value.String(),
102+
),
93103
)
94104
}
95105
}
@@ -109,7 +119,10 @@ func (a Tracer) InterceptField(ctx context.Context, next graphql.Resolver) (inte
109119
for idx, err := range errList {
110120
span.AddAttributes(
111121
trace.StringAttribute(fmt.Sprintf("resolver.error.%d.message", idx), err.Error()),
112-
trace.StringAttribute(fmt.Sprintf("resolver.error.%d.kind", idx), fmt.Sprintf("%T", err)),
122+
trace.StringAttribute(
123+
fmt.Sprintf("resolver.error.%d.kind", idx),
124+
fmt.Sprintf("%T", err),
125+
),
113126
)
114127
}
115128
}

gqlopentracing/tracer.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/99designs/gqlgen/graphql"
87
"github.com/opentracing/opentracing-go"
98
"github.com/opentracing/opentracing-go/ext"
109
"github.com/opentracing/opentracing-go/log"
10+
11+
"github.com/99designs/gqlgen/graphql"
1112
)
1213

1314
type (
@@ -35,7 +36,10 @@ func (a Tracer) Validate(schema graphql.ExecutableSchema) error {
3536
return nil
3637
}
3738

38-
func (a Tracer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
39+
func (a Tracer) InterceptOperation(
40+
ctx context.Context,
41+
next graphql.OperationHandler,
42+
) graphql.ResponseHandler {
3943
oc := graphql.GetOperationContext(ctx)
4044

4145
// Get operation name
@@ -70,7 +74,6 @@ func (a Tracer) InterceptField(ctx context.Context, next graphql.Resolver) (inte
7074
defer span.Finish()
7175

7276
res, err := next(ctx)
73-
7477
if err != nil {
7578
ext.Error.Set(span, true)
7679
span.LogFields(

prometheus/internal/graph/resolver.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Resolver struct{}
4444
func (r *Resolver) Mutation() MutationResolver {
4545
return &mutationResolver{r}
4646
}
47+
4748
func (r *Resolver) Query() QueryResolver {
4849
return &queryResolver{r}
4950
}

prometheus/prometheus.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"time"
66

7-
"github.com/99designs/gqlgen/graphql"
87
prometheusclient "github.com/prometheus/client_golang/prometheus"
8+
9+
"github.com/99designs/gqlgen/graphql"
910
)
1011

1112
const (
@@ -111,12 +112,18 @@ func (a Tracer) Validate(schema graphql.ExecutableSchema) error {
111112
return nil
112113
}
113114

114-
func (a Tracer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
115+
func (a Tracer) InterceptOperation(
116+
ctx context.Context,
117+
next graphql.OperationHandler,
118+
) graphql.ResponseHandler {
115119
requestStartedCounter.Inc()
116120
return next(ctx)
117121
}
118122

119-
func (a Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHandler) *graphql.Response {
123+
func (a Tracer) InterceptResponse(
124+
ctx context.Context,
125+
next graphql.ResponseHandler,
126+
) *graphql.Response {
120127
errList := graphql.GetErrors(ctx)
121128

122129
var exitStatus string

prometheus/prometheus_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/99designs/gqlgen-contrib/prometheus"
10-
"github.com/99designs/gqlgen-contrib/prometheus/internal/graph"
11-
"github.com/99designs/gqlgen/graphql/handler"
129
"github.com/prometheus/client_golang/prometheus/promhttp"
1310
"github.com/stretchr/testify/assert"
1411
"github.com/stretchr/testify/require"
12+
13+
"github.com/99designs/gqlgen-contrib/prometheus"
14+
"github.com/99designs/gqlgen-contrib/prometheus/internal/graph"
15+
"github.com/99designs/gqlgen/graphql/handler"
1516
)
1617

1718
func TestPrometheus_ResolverMiddleware_RequestMiddleware(t *testing.T) {
18-
1919
prometheus.Register()
2020

2121
mux := http.NewServeMux()
@@ -45,7 +45,12 @@ func TestPrometheus_ResolverMiddleware_RequestMiddleware(t *testing.T) {
4545
assert.Contains(t, body, "graphql_resolver_completed_total")
4646
}
4747

48-
func doRequest(handler http.Handler, method string, target string, body string) *httptest.ResponseRecorder {
48+
func doRequest(
49+
handler http.Handler,
50+
method string,
51+
target string,
52+
body string,
53+
) *httptest.ResponseRecorder {
4954
r := httptest.NewRequest(method, target, strings.NewReader(body))
5055
r.Header.Set("Content-Type", "application/json")
5156
w := httptest.NewRecorder()

0 commit comments

Comments
 (0)