Skip to content

Commit

Permalink
Address PR feedback:
Browse files Browse the repository at this point in the history
* Fix IDGenerator godoc comment
* rename type defaultIDGenerator to randomIDGenerator
* rename defIDGenerator() to defaultIDGenerator()

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 committed Nov 23, 2020
1 parent 655ab60 commit f34bd2f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions sdk/trace/id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -47,16 +47,16 @@ 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{}
gen.randSource.Read(tid[:])
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))
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/sampling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f34bd2f

Please sign in to comment.