diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 6cfefdc7453..3919175442d 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -23,21 +23,21 @@ import ( "go.opentelemetry.io/otel/trace" ) -// IDGenerator allows custom generators for TraceId and SpanId. +// IDGenerator allows custom generators for TraceID and SpanID. type IDGenerator interface { NewTraceID() trace.TraceID NewSpanID() trace.SpanID } -type defaultIDGenerator struct { +type randomIDGenerator struct { sync.Mutex randSource *rand.Rand } -var _ IDGenerator = &defaultIDGenerator{} +var _ IDGenerator = &randomIDGenerator{} // NewSpanID returns a non-zero span ID from a randomly-chosen sequence. -func (gen *defaultIDGenerator) NewSpanID() trace.SpanID { +func (gen *randomIDGenerator) NewSpanID() trace.SpanID { gen.Lock() defer gen.Unlock() sid := trace.SpanID{} @@ -47,7 +47,7 @@ func (gen *defaultIDGenerator) NewSpanID() trace.SpanID { // NewTraceID returns a non-zero trace ID from a randomly-chosen sequence. // mu should be held while this function is called. -func (gen *defaultIDGenerator) NewTraceID() trace.TraceID { +func (gen *randomIDGenerator) NewTraceID() trace.TraceID { gen.Lock() defer gen.Unlock() tid := trace.TraceID{} @@ -55,8 +55,8 @@ func (gen *defaultIDGenerator) NewTraceID() trace.TraceID { return tid } -func defIDGenerator() IDGenerator { - gen := &defaultIDGenerator{} +func defaultIDGenerator() IDGenerator { + gen := &randomIDGenerator{} var rngSeed int64 _ = binary.Read(crand.Reader, binary.LittleEndian, &rngSeed) gen.randSource = rand.New(rand.NewSource(rngSeed)) diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go index 2906e0888ba..4c6e6e2ecf0 100644 --- a/sdk/trace/provider.go +++ b/sdk/trace/provider.go @@ -66,7 +66,7 @@ func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider { } tp.config.Store(&Config{ DefaultSampler: ParentBased(AlwaysSample()), - IDGenerator: defIDGenerator(), + IDGenerator: defaultIDGenerator(), MaxAttributesPerSpan: DefaultMaxAttributesPerSpan, MaxEventsPerSpan: DefaultMaxEventsPerSpan, MaxLinksPerSpan: DefaultMaxLinksPerSpan, diff --git a/sdk/trace/sampling_test.go b/sdk/trace/sampling_test.go index 3c998773327..47ba8d89b02 100644 --- a/sdk/trace/sampling_test.go +++ b/sdk/trace/sampling_test.go @@ -168,7 +168,7 @@ func TestTraceIdRatioSamplesInclusively(t *testing.T) { numSamplers = 1000 numTraces = 100 ) - idg := defIDGenerator() + idg := defaultIDGenerator() for i := 0; i < numSamplers; i++ { ratioLo, ratioHi := rand.Float64(), rand.Float64() diff --git a/sdk/trace/trace_test.go b/sdk/trace/trace_test.go index da9e46ae323..63aeedc7fd5 100644 --- a/sdk/trace/trace_test.go +++ b/sdk/trace/trace_test.go @@ -213,7 +213,7 @@ func TestRecordingIsOn(t *testing.T) { } func TestSampling(t *testing.T) { - idg := defIDGenerator() + idg := defaultIDGenerator() const total = 10000 for name, tc := range map[string]struct { sampler Sampler