-
Notifications
You must be signed in to change notification settings - Fork 781
/
tracing.go
36 lines (30 loc) · 1.29 KB
/
tracing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cortex
import (
"context"
"github.com/opentracing/opentracing-go"
objstoretracing "github.com/thanos-io/objstore/tracing/opentracing"
"github.com/thanos-io/thanos/pkg/tracing"
"google.golang.org/grpc"
)
// ThanosTracerUnaryInterceptor injects the opentracing global tracer into the context
// in order to get it picked up by Thanos components.
func ThanosTracerUnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
ctx = objstoretracing.ContextWithTracer(ctx, opentracing.GlobalTracer())
return handler(tracing.ContextWithTracer(ctx, opentracing.GlobalTracer()), req)
}
// ThanosTracerStreamInterceptor injects the opentracing global tracer into the context
// in order to get it picked up by Thanos components.
func ThanosTracerStreamInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := objstoretracing.ContextWithTracer(ss.Context(), opentracing.GlobalTracer())
return handler(srv, wrappedServerStream{
ctx: tracing.ContextWithTracer(ctx, opentracing.GlobalTracer()),
ServerStream: ss,
})
}
type wrappedServerStream struct {
ctx context.Context
grpc.ServerStream
}
func (ss wrappedServerStream) Context() context.Context {
return ss.ctx
}