forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.go
More file actions
67 lines (57 loc) · 1.89 KB
/
factory.go
File metadata and controls
67 lines (57 loc) · 1.89 KB
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
package client
import (
"context"
"io"
"strings"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/thanos-io/thanos/pkg/tracing/elasticapm"
"github.com/thanos-io/thanos/pkg/tracing/jaeger"
"github.com/thanos-io/thanos/pkg/tracing/lightstep"
"github.com/thanos-io/thanos/pkg/tracing/stackdriver"
"gopkg.in/yaml.v2"
)
type TracingProvider string
const (
STACKDRIVER TracingProvider = "STACKDRIVER"
JAEGER TracingProvider = "JAEGER"
ELASTIC_APM TracingProvider = "ELASTIC_APM"
LIGHTSTEP TracingProvider = "LIGHTSTEP"
)
type TracingConfig struct {
Type TracingProvider `yaml:"type"`
Config interface{} `yaml:"config"`
}
func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Registry, confContentYaml []byte) (opentracing.Tracer, io.Closer, error) {
level.Info(logger).Log("msg", "loading tracing configuration")
tracingConf := &TracingConfig{}
if err := yaml.UnmarshalStrict(confContentYaml, tracingConf); err != nil {
return nil, nil, errors.Wrap(err, "parsing config tracing YAML")
}
var config []byte
var err error
if tracingConf.Config != nil {
config, err = yaml.Marshal(tracingConf.Config)
if err != nil {
return nil, nil, errors.Wrap(err, "marshal content of tracing configuration")
}
}
switch strings.ToUpper(string(tracingConf.Type)) {
case string(STACKDRIVER):
return stackdriver.NewTracer(ctx, logger, config)
case string(JAEGER):
return jaeger.NewTracer(ctx, logger, metrics, config)
case string(ELASTIC_APM):
return elasticapm.NewTracer(config)
case string(LIGHTSTEP):
return lightstep.NewTracer(ctx, config)
default:
return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type)
}
}
func NoopTracer() opentracing.Tracer {
return &opentracing.NoopTracer{}
}