1
0
Fork 0

Update Zipkin OpenTracing driver to latest 0.4.3 release

This commit is contained in:
Bas van Beek 2019-09-03 11:52:04 +02:00 committed by Traefiker Bot
parent 07eb9c5970
commit cb7c5a8ca1
14 changed files with 48 additions and 64 deletions

View file

@ -223,7 +223,6 @@ func TestDo_globalConfiguration(t *testing.T) {
HTTPEndpoint: "fff",
SameSpan: true,
ID128Bit: true,
Debug: true,
SampleRate: 53,
},
Datadog: &datadog.Config{

View file

@ -282,7 +282,6 @@ func Test_decodeFileToNode_Toml(t *testing.T) {
{Name: "serviceName", Value: "foobar"},
{Name: "spanNameLimit", Value: "42"},
{Name: "zipkin", Children: []*parser.Node{
{Name: "debug", Value: "true"},
{Name: "httpEndpoint", Value: "foobar"},
{Name: "id128Bit", Value: "true"},
{Name: "sameSpan", Value: "true"},
@ -517,7 +516,6 @@ func Test_decodeFileToNode_Yaml(t *testing.T) {
{Name: "serviceName", Value: "foobar"},
{Name: "spanNameLimit", Value: "42"},
{Name: "zipkin", Children: []*parser.Node{
{Name: "debug", Value: "true"},
{Name: "httpEndpoint", Value: "foobar"},
{Name: "id128Bit", Value: "true"},
{Name: "sameSpan", Value: "true"},

View file

@ -177,7 +177,6 @@
httpEndpoint = "foobar"
sameSpan = true
id128Bit = true
debug = true
sampleRate = 42.0
[tracing.datadog]
localAgentHostPort = "foobar"

View file

@ -188,7 +188,6 @@ tracing:
httpEndpoint: foobar
sameSpan: true
id128Bit: true
debug: true
sampleRate: 42
datadog:
localAgentHostPort: foobar

View file

@ -6,7 +6,9 @@ import (
"github.com/containous/traefik/v2/pkg/log"
"github.com/opentracing/opentracing-go"
zipkin "github.com/openzipkin-contrib/zipkin-go-opentracing"
zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
"github.com/openzipkin/zipkin-go"
"github.com/openzipkin/zipkin-go/reporter/http"
)
// Name sets the name of this tracer.
@ -17,43 +19,53 @@ type Config struct {
HTTPEndpoint string `description:"HTTP Endpoint to report traces to." json:"httpEndpoint,omitempty" toml:"httpEndpoint,omitempty" yaml:"httpEndpoint,omitempty"`
SameSpan bool `description:"Use Zipkin SameSpan RPC style traces." json:"sameSpan,omitempty" toml:"sameSpan,omitempty" yaml:"sameSpan,omitempty" export:"true"`
ID128Bit bool `description:"Use Zipkin 128 bit root span IDs." json:"id128Bit,omitempty" toml:"id128Bit,omitempty" yaml:"id128Bit,omitempty" export:"true"`
Debug bool `description:"Enable Zipkin debug." json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty" export:"true"`
SampleRate float64 `description:"The rate between 0.0 and 1.0 of requests to trace." json:"sampleRate,omitempty" toml:"sampleRate,omitempty" yaml:"sampleRate,omitempty" export:"true"`
}
// SetDefaults sets the default values.
func (c *Config) SetDefaults() {
c.HTTPEndpoint = "http://localhost:9411/api/v1/spans"
c.HTTPEndpoint = "http://localhost:9411/api/v2/spans"
c.SameSpan = false
c.ID128Bit = true
c.Debug = false
c.SampleRate = 1.0
}
// Setup sets up the tracer
func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error) {
collector, err := zipkin.NewHTTPCollector(c.HTTPEndpoint)
// create our local endpoint
endpoint, err := zipkin.NewEndpoint(serviceName, "0.0.0.0:0")
if err != nil {
return nil, nil, err
}
recorder := zipkin.NewRecorder(collector, c.Debug, "0.0.0.0:0", serviceName)
// create our sampler
sampler, err := zipkin.NewBoundarySampler(c.SampleRate, time.Now().Unix())
if err != nil {
return nil, nil, err
}
tracer, err := zipkin.NewTracer(
recorder,
zipkin.ClientServerSameSpan(c.SameSpan),
zipkin.TraceID128Bit(c.ID128Bit),
zipkin.DebugMode(c.Debug),
zipkin.WithSampler(zipkin.NewBoundarySampler(c.SampleRate, time.Now().Unix())),
// create the span reporter
reporter := http.NewReporter(c.HTTPEndpoint)
// create the native Zipkin tracer
nativeTracer, err := zipkin.NewTracer(
reporter,
zipkin.WithLocalEndpoint(endpoint),
zipkin.WithSharedSpans(c.SameSpan),
zipkin.WithTraceID128Bit(c.ID128Bit),
zipkin.WithSampler(sampler),
)
if err != nil {
return nil, nil, err
}
// wrap the Zipkin native tracer with the OpenTracing Bridge
tracer := zipkinot.Wrap(nativeTracer)
// Without this, child spans are getting the NOOP tracer
opentracing.SetGlobalTracer(tracer)
log.WithoutContext().Debug("Zipkin tracer configured")
return tracer, collector, nil
return tracer, reporter, nil
}