mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-28 21:09:17 +02:00
Fix IDGenerator may generate zero TraceId / SpanId (#5514)
# Description Fix #5462 ## Type of change add a loop to generate the spanID and traceID. the loop will not stop until it generate a valid ID - [x] Bug fix (non-breaking change which fixes an issue) --------- Co-authored-by: Damien Mathieu <42@dmathieu.com> Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
parent
f5e613757f
commit
ffe855df33
@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Retry trace and span ID generation if it generated an invalid one in `go.opentelemetry.io/otel/sdk/trace`. (#5514)
|
||||||
- Log a warning to the OpenTelemetry internal logger when a `Record` in `go.opentelemetry.io/otel/sdk/log` drops an attribute due to a limit being reached. (#5376)
|
- Log a warning to the OpenTelemetry internal logger when a `Record` in `go.opentelemetry.io/otel/sdk/log` drops an attribute due to a limit being reached. (#5376)
|
||||||
- Identify the `Tracer` returned from the global `TracerProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
|
- Identify the `Tracer` returned from the global `TracerProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
|
||||||
- Identify the `Meter` returned from the global `MeterProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
|
- Identify the `Meter` returned from the global `MeterProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426)
|
||||||
|
@ -41,7 +41,12 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace
|
|||||||
gen.Lock()
|
gen.Lock()
|
||||||
defer gen.Unlock()
|
defer gen.Unlock()
|
||||||
sid := trace.SpanID{}
|
sid := trace.SpanID{}
|
||||||
|
for {
|
||||||
_, _ = gen.randSource.Read(sid[:])
|
_, _ = gen.randSource.Read(sid[:])
|
||||||
|
if sid.IsValid() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
return sid
|
return sid
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +56,19 @@ func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.
|
|||||||
gen.Lock()
|
gen.Lock()
|
||||||
defer gen.Unlock()
|
defer gen.Unlock()
|
||||||
tid := trace.TraceID{}
|
tid := trace.TraceID{}
|
||||||
_, _ = gen.randSource.Read(tid[:])
|
|
||||||
sid := trace.SpanID{}
|
sid := trace.SpanID{}
|
||||||
|
for {
|
||||||
|
_, _ = gen.randSource.Read(tid[:])
|
||||||
|
if tid.IsValid() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for {
|
||||||
_, _ = gen.randSource.Read(sid[:])
|
_, _ = gen.randSource.Read(sid[:])
|
||||||
|
if sid.IsValid() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
return tid, sid
|
return tid, sid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user