-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaeger.go
71 lines (61 loc) · 2.9 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package tracing
import (
"io"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
jaegerCfg "github.com/uber/jaeger-client-go/config"
jaegerLogZap "github.com/uber/jaeger-client-go/log/zap"
jaegerProm "github.com/uber/jaeger-lib/metrics/prometheus"
"github.com/bygui86/go-k8s-probes/logging"
)
/*
Environment variables:
JAEGER_DISABLED to enable/disable Jaeger Tracer (default false)
JAEGER_AGENT_HOST to set target Jaeger host (default localhost)
JAEGER_AGENT_PORT to set target Jaeger port (default 6831)
JAEGER_SAMPLER_TYPE to set Sampler type (default none)(*)
JAEGER_SAMPLER_PARAM to set Sampler param (default 0) (**)
JAEGER_REPORTER_MAX_QUEUE_SIZE to set max how many spans the reporter can keep in memory before it starts
dropping new spans (default 0). The queue is continuously drained by a background go-routine, as
fast as spans can be sent out of process.
JAEGER_REPORTER_LOG_SPANS to set Reporter LogSpans (default false)
JAEGER_REPORTER_FLUSH_INTERVAL to set Reporter flush interval (default 0s) (***)
JAEGER_SERVICE_NAME to set service name on the side of Jaeger (default empty string)
(*) JAEGER_SAMPLER_TYPE available values:
"const" (SamplerTypeConst) is the type of sampler that always makes the same decision.
"remote" (SamplerTypeRemote) is the type of sampler that polls Jaeger agent for sampling strategy.
"probabilistic" (SamplerTypeProbabilistic) is the type of sampler that samples traces with a certain fixed probability.
"ratelimiting" (SamplerTypeRateLimiting) is the type of sampler that samples only up to a fixed number of traces per second.
(**) JAEGER_SAMPLER_PARAM available values:
for "const" sampler, 0 or 1 for always false/true respectively
for "probabilistic" sampler, a probability between 0 and 1
for "rateLimiting" sampler, the number of spans per second
for "remote" sampler, param is the same as for "probabilistic"
and indicates the initial sampling rate before the actual one
is received from the mothership.
(***) JAEGER_REPORTER_FLUSH_INTERVAL valid time units:
"ns", "us" (or "µs"), "ms", "s", "m", "h".
*/
/*
Use Zap logger to print out spans.
Use a Prometheus registerer to expose metrics.
*/
func InitTracer() (io.Closer, error) {
cfg, cfgErr := jaegerCfg.FromEnv()
if cfgErr != nil {
return nil, cfgErr
}
logging.SugaredLog.Debugf("Jaeger Configuration: %+v", cfg)
logging.SugaredLog.Debugf("Jaeger Sampler: %+v", cfg.Sampler)
logging.SugaredLog.Debugf("Jaeger Reporter: %+v", cfg.Reporter)
closer, tracerErr := cfg.InitGlobalTracer(
cfg.ServiceName,
jaegerCfg.Logger(jaegerLogZap.NewLogger(logging.Log)),
jaegerCfg.Metrics(jaegerProm.New(jaegerProm.WithRegisterer(prometheus.DefaultRegisterer))),
)
if tracerErr != nil {
return nil, tracerErr
}
logging.SugaredLog.Debugf("Jaeger global Tracer registered: %t", opentracing.IsGlobalTracerRegistered())
return closer, nil
}