forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace.go
44 lines (36 loc) · 1.02 KB
/
trace.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 trace
import (
"io"
"github.com/TykTechnologies/tyk/trace/jaeger"
"github.com/TykTechnologies/tyk/trace/openzipkin"
opentracing "github.com/opentracing/opentracing-go"
)
// InitFunc this is a function for initializing a Tracer
type InitFunc func(name string, service string, opts map[string]interface{}, logger Logger) (Tracer, error)
type Tracer interface {
Name() string
opentracing.Tracer
io.Closer
}
// NoopTracer wraps opentracing.NoopTracer to satisfy Tracer interface.
type NoopTracer struct {
opentracing.NoopTracer
}
// Close implements io.Closer interface by doing nothing.
func (n NoopTracer) Close() error {
return nil
}
func (n NoopTracer) Name() string {
return "NoopTracer"
}
// Init returns a tracer for a given name.
func Init(name string, service string, opts map[string]interface{}, logger Logger) (Tracer, error) {
switch name {
case jaeger.Name:
return jaeger.Init(service, opts, logger)
case openzipkin.Name:
return openzipkin.Init(service, opts)
default:
return NoopTracer{}, nil
}
}