From 18f8eca1d54fe95e05a61c9a49af7a5dbfc3ef50 Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Tue, 7 Sep 2021 12:07:36 -0700 Subject: [PATCH] Permit setting a custom ID generator We have a use case where we're having the Trace ID serve dual purpose: First, for tracing; secondly, to maintain an audit log of data change events. To support the second use case, we'd like to generate our own ID's in accordance to the KSUID standard published by Segment.io, so that our ID's are time-sortable. Rather than pull the library in here, I instead propose a configuration option on the Tracer that would allow us to override the Generator with one of our own. --- tracer/tracer.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tracer/tracer.go b/tracer/tracer.go index b1dbeb1..63c9993 100755 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -58,6 +58,13 @@ func WithSampler(sampler Sampler) Option { } } +// WithGenerator configures Tracer to use a custom trace id generator implementation. +func WithGenerator(generator Generator) Option { + return func(t *WavefrontTracer) { + t.generator = generator + } +} + // WithJaegerPropagator configures Tracer to use Jaeger trace context propagation. func WithJaegerPropagator(traceId, baggagePrefix string) Option { return func(args *WavefrontTracer) { @@ -74,15 +81,13 @@ func WithJaegerPropagator(traceId, baggagePrefix string) Option { // WithW3CGenerator configures Tracer to generate Trace and Span IDs according to W3C spec. func WithW3CGenerator() Option { - return func(t *WavefrontTracer) { - t.generator = NewGeneratorW3C() - } + return WithGenerator(NewGeneratorW3C()) } // WithW3CPropagator configures Tracer to use trace context propagation according to W3C spec. func WithW3CPropagator() Option { return func(t *WavefrontTracer) { - // implies W3C Generator + // implies W3C Generator. Custom ID generators should use WithGenerator after this option. t.generator = NewGeneratorW3C() t.textPropagator = NewPropagatorW3C() }