forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaeger.go
44 lines (36 loc) · 1.09 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
package jaeger
import (
"io"
"github.com/tickoalcantara12/micro/v3/service/logger"
"github.com/tickoalcantara12/micro/v3/util/opentelemetry"
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go/config"
)
const (
DefaultReporterAddress = "localhost:6831"
)
// New returns a configured Jaeger tracer:
func New(opts ...opentelemetry.Option) (opentracing.Tracer, io.Closer, error) {
options := opentelemetry.DefaultOptions()
for _, o := range opts {
o(&options)
}
logger.Debug("Creating a new Jaeger tracer")
// Prepare a Jaeger config using our options:
jaegerConfig := config.Configuration{
ServiceName: options.ServiceName,
Sampler: &config.SamplerConfig{
Type: "const", // No adaptive sampling or external lookups
Param: options.SamplingRate,
},
Reporter: &config.ReporterConfig{
LocalAgentHostPort: options.TraceReporterAddress,
},
}
// Prepare a new Jaeger tracer from this config:
tracer, closer, err := jaegerConfig.NewTracer()
if err != nil {
return nil, nil, err
}
return tracer, closer, nil
}