Skip to content

Commit

Permalink
Add option to enable gen128Bit for tracer (jaegertracing#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengsrc authored and black-adder committed Aug 25, 2017
1 parent 1f15fec commit 7c8937d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (c Configuration) New(
jaeger.TracerOptions.Metrics(tracerMetrics),
jaeger.TracerOptions.Logger(opts.logger),
jaeger.TracerOptions.CustomHeaderKeys(c.Headers),
jaeger.TracerOptions.Gen128Bit(opts.gen128Bit),
jaeger.TracerOptions.ZipkinSharedRPCSpan(opts.zipkinSharedRPCSpan),
}

Expand Down
19 changes: 19 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,22 @@ func TestBaggageRestrictionsConfig(t *testing.T) {
},
)
}

func TestConfigWithGen128Bit(t *testing.T) {
c := Configuration{
Sampler: &SamplerConfig{
Type: "const",
Param: 1,
},
RPCMetrics: true,
}
tracer, closer, err := c.New("test", Gen128Bit(true))
require.NoError(t, err)
defer closer.Close()

span := tracer.StartSpan("test")
defer span.Finish()
traceID := span.Context().(jaeger.SpanContext).TraceID()
require.True(t, traceID.High != 0)
require.True(t, traceID.Low != 0)
}
8 changes: 8 additions & 0 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Options struct {
reporter jaeger.Reporter
contribObservers []jaeger.ContribObserver
observers []jaeger.Observer
gen128Bit bool
zipkinSharedRPCSpan bool
tags []opentracing.Tag
}
Expand Down Expand Up @@ -80,6 +81,13 @@ func ContribObserver(observer jaeger.ContribObserver) Option {
}
}

// Gen128Bit specifies whether to generate 128bit trace IDs.
func Gen128Bit(gen128Bit bool) Option {
return func(c *Options) {
c.gen128Bit = gen128Bit
}
}

// ZipkinSharedRPCSpan creates an option that enables sharing span ID between client
// and server spans a la zipkin. If false, client and server spans will be assigned
// different IDs.
Expand Down
2 changes: 2 additions & 0 deletions config/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func TestApplyOptions(t *testing.T) {
Logger(jaeger.StdLogger),
Observer(observer),
ContribObserver(contribObserver),
Gen128Bit(true),
ZipkinSharedRPCSpan(true),
)
assert.Equal(t, jaeger.StdLogger, opts.logger)
assert.Equal(t, metricsFactory, opts.metrics)
assert.Equal(t, []jaeger.Observer{observer}, opts.observers)
assert.Equal(t, []jaeger.ContribObserver{contribObserver}, opts.contribObservers)
assert.True(t, opts.gen128Bit)
assert.True(t, opts.zipkinSharedRPCSpan)
}

Expand Down
6 changes: 6 additions & 0 deletions tracer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func (tracerOptions) ContribObserver(observer ContribObserver) TracerOption {
}
}

func (tracerOptions) Gen128Bit(gen128Bit bool) TracerOption {
return func(tracer *Tracer) {
tracer.options.gen128Bit = gen128Bit
}
}

func (tracerOptions) ZipkinSharedRPCSpan(zipkinSharedRPCSpan bool) TracerOption {
return func(tracer *Tracer) {
tracer.options.zipkinSharedRPCSpan = zipkinSharedRPCSpan
Expand Down
11 changes: 11 additions & 0 deletions tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ func TestEmptySpanContextAsParent(t *testing.T) {
assert.True(t, ctx.IsValid())
}

func TestGen128Bit(t *testing.T) {
tracer, tc := NewTracer("x", NewConstSampler(true), NewNullReporter(), TracerOptions.Gen128Bit(true))
defer tc.Close()

span := tracer.StartSpan("test", opentracing.ChildOf(emptyContext))
defer span.Finish()
traceID := span.Context().(SpanContext).TraceID()
assert.True(t, traceID.High != 0)
assert.True(t, traceID.Low != 0)
}

func TestZipkinSharedRPCSpan(t *testing.T) {
tracer, tc := NewTracer("x", NewConstSampler(true), NewNullReporter(), TracerOptions.ZipkinSharedRPCSpan(false))

Expand Down

0 comments on commit 7c8937d

Please sign in to comment.