Skip to content

Commit

Permalink
Small clean up for tracing. (thanos-io#1720)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartek Plotka <[email protected]>
  • Loading branch information
bwplotka authored Nov 5, 2019
1 parent f501429 commit 27a578d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions pkg/server/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func New(logger log.Logger, reg prometheus.Registerer, tracer opentracing.Tracer
return status.Errorf(codes.Internal, "%s", p)
}

grpcOpts := []grpc.ServerOption{}
grpcOpts = append(grpcOpts,
grpcOpts := []grpc.ServerOption{
grpc.MaxSendMsgSize(math.MaxInt32),
grpc_middleware.WithUnaryServerChain(
met.UnaryServerInterceptor(),
Expand All @@ -72,7 +71,7 @@ func New(logger log.Logger, reg prometheus.Registerer, tracer opentracing.Tracer
tracing.StreamServerInterceptor(tracer),
grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
),
)
}

if options.tlsConfig != nil {
grpcOpts = append(grpcOpts, grpc.Creds(credentials.NewTLS(options.tlsConfig)))
Expand Down
8 changes: 6 additions & 2 deletions pkg/tracing/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ func StreamClientInterceptor(tracer opentracing.Tracer) grpc.StreamClientInterce

// UnaryServerInterceptor returns a new unary server interceptor for OpenTracing and injects given tracer.
func UnaryServerInterceptor(tracer opentracing.Tracer) grpc.UnaryServerInterceptor {
interceptor := grpc_opentracing.UnaryServerInterceptor(grpc_opentracing.WithTracer(tracer))
return func(parentCtx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return grpc_opentracing.UnaryServerInterceptor(grpc_opentracing.WithTracer(tracer))(ContextWithTracer(parentCtx, tracer), req, info, handler)
// Add our own tracer.
return interceptor(ContextWithTracer(parentCtx, tracer), req, info, handler)
}
}

// StreamServerInterceptor returns a new streaming server interceptor for OpenTracing and injects given tracer.
func StreamServerInterceptor(tracer opentracing.Tracer) grpc.StreamServerInterceptor {
interceptor := grpc_opentracing.StreamServerInterceptor(grpc_opentracing.WithTracer(tracer))
return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
// Add our own tracer.
wrappedStream := grpc_middleware.WrapServerStream(stream)
wrappedStream.WrappedContext = ContextWithTracer(stream.Context(), tracer)

return grpc_opentracing.StreamServerInterceptor(grpc_opentracing.WithTracer(tracer))(srv, wrappedStream, info, handler)
return interceptor(srv, wrappedStream, info, handler)
}
}

0 comments on commit 27a578d

Please sign in to comment.