-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaeger.go
54 lines (45 loc) · 1.47 KB
/
jaeger.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"fmt"
"io"
"log"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
opentracing "github.com/opentracing/opentracing-go"
jaeger "github.com/uber/jaeger-client-go"
config "github.com/uber/jaeger-client-go/config"
jaegerConfig "github.com/uber/jaeger-client-go/config"
"google.golang.org/grpc"
)
func initJaeger(service string) (opentracing.Tracer, io.Closer) {
jcfg := &jaegerConfig.Configuration{
Sampler: &jaegerConfig.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &jaegerConfig.ReporterConfig{
LogSpans: false,
},
}
tracer, closer, err := jcfg.New(service, config.Logger(jaeger.StdLogger))
if err != nil {
panic(fmt.Sprintf("ERROR: cannot init Jaeger: %v\n", err))
}
return tracer, closer
}
// ctx is the incoming gRPC request's context
// addr is the address for the new outbound request
func createClientGRPCConn(ctx context.Context, addr string) (*grpc.ClientConn, error) {
span, _ := opentracing.StartSpanFromContext(ctx, "createGRPCConn")
defer span.Finish()
var opts []grpc.DialOption
opts = append(opts, grpc.WithStreamInterceptor(grpc_opentracing.StreamClientInterceptor()))
opts = append(opts, grpc.WithUnaryInterceptor(grpc_opentracing.UnaryClientInterceptor()))
opts = append(opts, grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, addr, opts...)
if err != nil {
log.Println("Failed to connect to application addr: ", err)
return nil, err
}
return conn, nil
}