-
Notifications
You must be signed in to change notification settings - Fork 12
/
jaeger.go
45 lines (38 loc) · 1.62 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
package tracing
import (
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/logger"
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/log/zap"
"io"
)
type JaegerConfig struct {
ServiceName string `env:"JAEGER_SERVICE_NAME" validate:"required"`
AgentHost string `env:"JAEGER_AGENT_HOST" envDefault:"localhost" validate:"required"`
AgentPort string `env:"JAEGER_AGENT_PORT" envDefault:"6831" validate:"required"`
Enabled bool `env:"JAEGER_ENABLED" envDefault:"true"`
LogSpans bool `env:"JAEGER_REPORTER_LOG_SPANS" envDefault:"false" `
SamplerType string `env:"JAEGER_SAMPLER_TYPE" envDefault:"const" validate:"required"`
SamplerParam float64 `env:"JAEGER_SAMPLER_PARAM" envDefault:"1" validate:"required"`
}
func NewJaegerTracer(jaegerConfig *JaegerConfig, log logger.Logger) (opentracing.Tracer, io.Closer, error) {
cfg := initJaeger(jaegerConfig)
return cfg.NewTracer(config.Logger(zap.NewLogger(log.Logger())))
}
func initJaeger(jaegerConfig *JaegerConfig) *config.Configuration {
cfg := &config.Configuration{
ServiceName: jaegerConfig.ServiceName,
Disabled: !jaegerConfig.Enabled,
// "const" sampler is a binary sampling strategy: 0=never sample, 1=always sample.
Sampler: &config.SamplerConfig{
Type: jaegerConfig.SamplerType,
Param: jaegerConfig.SamplerParam,
},
// Log the emitted spans to stdout.
Reporter: &config.ReporterConfig{
LogSpans: jaegerConfig.LogSpans,
LocalAgentHostPort: jaegerConfig.AgentHost + ":" + jaegerConfig.AgentPort,
},
}
return cfg
}