From 5dfc5e8d383874ff7c7a613abd60e4fefa20c825 Mon Sep 17 00:00:00 2001 From: Fools Date: Sun, 16 Jun 2024 21:35:53 +0100 Subject: [PATCH 1/7] bug fix --- sdk/trace/id_generator.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index f9633d8c576..925bcf99305 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -41,7 +41,12 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace gen.Lock() defer gen.Unlock() sid := trace.SpanID{} - _, _ = gen.randSource.Read(sid[:]) + for { + _, _ = gen.randSource.Read(sid[:]) + if sid.IsValid() { + break + } + } return sid } @@ -51,9 +56,19 @@ func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace. gen.Lock() defer gen.Unlock() tid := trace.TraceID{} - _, _ = gen.randSource.Read(tid[:]) sid := trace.SpanID{} - _, _ = gen.randSource.Read(sid[:]) + for { + _, _ = gen.randSource.Read(tid[:]) + if tid.IsValid() { + break + } + } + for { + _, _ = gen.randSource.Read(sid[:]) + if sid.IsValid() { + break + } + } return tid, sid } From 1df95e643a5173ef7ab564bd3fd7a8f1e89e122f Mon Sep 17 00:00:00 2001 From: Fools Date: Sun, 16 Jun 2024 21:55:38 +0100 Subject: [PATCH 2/7] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 245f4cffa4b..03f313e8842 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed +- Fix IDGenerator may generate zero TraceId / SpanId. (#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) - 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) From ea40bd059ff1bf6bbad766ae7f0f949782020675 Mon Sep 17 00:00:00 2001 From: Fools <54661071+Charlie-lizhihan@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:13:09 +0100 Subject: [PATCH 3/7] Update CHANGELOG.md Co-authored-by: Damien Mathieu <42@dmathieu.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03f313e8842..dc1d5e9b253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed -- Fix IDGenerator may generate zero TraceId / SpanId. (#5514) +- 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) - 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) From 3b5fb78fdfe108ba7d5a18bec5ab48445a221d9b Mon Sep 17 00:00:00 2001 From: Fools <54661071+Charlie-lizhihan@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:29:24 +0100 Subject: [PATCH 4/7] Update sdk/trace/id_generator.go Co-authored-by: Damien Mathieu <42@dmathieu.com> --- sdk/trace/id_generator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 925bcf99305..be899009a9c 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -44,10 +44,9 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace for { _, _ = gen.randSource.Read(sid[:]) if sid.IsValid() { - break + return sid } } - return sid } // NewIDs returns a non-zero trace ID and a non-zero span ID from a From f1a0bf07f0521e01ae9ef7b810bbf527d5f56582 Mon Sep 17 00:00:00 2001 From: Fools Date: Tue, 18 Jun 2024 00:18:21 +0100 Subject: [PATCH 5/7] go idoms change --- sdk/trace/id_generator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 925bcf99305..7f887265dcd 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -66,10 +66,9 @@ func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace. for { _, _ = gen.randSource.Read(sid[:]) if sid.IsValid() { - break + return tid, sid } } - return tid, sid } func defaultIDGenerator() IDGenerator { From 94d06af815b1ab59a85a5304abd9ed965554f768 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 18 Jun 2024 15:03:37 +0200 Subject: [PATCH 6/7] Update sdk/trace/id_generator.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Pająk --- sdk/trace/id_generator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index 6abe00ff9d8..be899009a9c 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -65,9 +65,10 @@ func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace. for { _, _ = gen.randSource.Read(sid[:]) if sid.IsValid() { - return tid, sid + break } } + return tid, sid } func defaultIDGenerator() IDGenerator { From ecef23c7900a273785fbcc2350e0deb154aa7228 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Tue, 18 Jun 2024 15:03:42 +0200 Subject: [PATCH 7/7] Update sdk/trace/id_generator.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert Pająk --- sdk/trace/id_generator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/trace/id_generator.go b/sdk/trace/id_generator.go index be899009a9c..925bcf99305 100644 --- a/sdk/trace/id_generator.go +++ b/sdk/trace/id_generator.go @@ -44,9 +44,10 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace for { _, _ = gen.randSource.Read(sid[:]) if sid.IsValid() { - return sid + break } } + return sid } // NewIDs returns a non-zero trace ID and a non-zero span ID from a