2018-01-10 16:48:04 +00:00
|
|
|
package zipkin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
2018-11-27 16:42:04 +00:00
|
|
|
"time"
|
2018-01-10 16:48:04 +00:00
|
|
|
|
2018-04-16 15:42:03 +00:00
|
|
|
"github.com/containous/traefik/log"
|
2018-07-03 08:02:03 +00:00
|
|
|
"github.com/opentracing/opentracing-go"
|
2018-01-10 16:48:04 +00:00
|
|
|
zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
|
|
|
)
|
|
|
|
|
2018-11-14 09:18:03 +00:00
|
|
|
// Name sets the name of this tracer.
|
2018-01-10 16:48:04 +00:00
|
|
|
const Name = "zipkin"
|
|
|
|
|
2018-11-14 09:18:03 +00:00
|
|
|
// Config provides configuration settings for a zipkin tracer.
|
2018-01-10 16:48:04 +00:00
|
|
|
type Config struct {
|
2018-11-27 16:42:04 +00:00
|
|
|
HTTPEndpoint string `description:"HTTP Endpoint to report traces to." export:"false"`
|
|
|
|
SameSpan bool `description:"Use Zipkin SameSpan RPC style traces." export:"true"`
|
|
|
|
ID128Bit bool `description:"Use Zipkin 128 bit root span IDs." export:"true"`
|
|
|
|
Debug bool `description:"Enable Zipkin debug." export:"true"`
|
|
|
|
SampleRate float64 `description:"The rate between 0.0 and 1.0 of requests to trace." export:"true"`
|
2018-01-10 16:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup sets up the tracer
|
|
|
|
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
|
|
|
|
collector, err := zipkin.NewHTTPCollector(c.HTTPEndpoint)
|
2018-02-15 09:28:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2018-11-14 09:18:03 +00:00
|
|
|
|
2018-01-10 16:48:04 +00:00
|
|
|
recorder := zipkin.NewRecorder(collector, c.Debug, "0.0.0.0:0", serviceName)
|
2018-11-14 09:18:03 +00:00
|
|
|
|
2018-01-10 16:48:04 +00:00
|
|
|
tracer, err := zipkin.NewTracer(
|
|
|
|
recorder,
|
|
|
|
zipkin.ClientServerSameSpan(c.SameSpan),
|
|
|
|
zipkin.TraceID128Bit(c.ID128Bit),
|
|
|
|
zipkin.DebugMode(c.Debug),
|
2018-11-27 16:42:04 +00:00
|
|
|
zipkin.WithSampler(zipkin.NewBoundarySampler(c.SampleRate, time.Now().Unix())),
|
2018-01-10 16:48:04 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Without this, child spans are getting the NOOP tracer
|
|
|
|
opentracing.SetGlobalTracer(tracer)
|
|
|
|
|
2018-11-14 09:18:03 +00:00
|
|
|
log.WithoutContext().Debug("Zipkin tracer configured")
|
2018-04-16 15:42:03 +00:00
|
|
|
|
2018-01-10 16:48:04 +00:00
|
|
|
return tracer, collector, nil
|
|
|
|
}
|