tracer/noop: disable allocation for trace and span id
All checks were successful
coverage / build (push) Successful in 2m22s
test / test (push) Successful in 4m22s
sync / sync (push) Successful in 26s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2025-05-05 09:48:22 +03:00
parent c8946dcdc8
commit 2c21cce076

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"time" "time"
"go.unistack.org/micro/v4/util/id" "github.com/google/uuid"
) )
var _ Tracer = (*noopTracer)(nil) var _ Tracer = (*noopTracer)(nil)
@@ -18,6 +18,8 @@ func (t *noopTracer) Spans() []Span {
return t.spans return t.spans
} }
var uuidNil = uuid.Nil.String()
func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) { func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span) {
options := NewSpanOptions(opts...) options := NewSpanOptions(opts...)
span := &noopSpan{ span := &noopSpan{
@@ -28,8 +30,8 @@ func (t *noopTracer) Start(ctx context.Context, name string, opts ...SpanOption)
labels: options.Labels, labels: options.Labels,
kind: options.Kind, kind: options.Kind,
} }
span.spanID.s, _ = id.New() span.spanID.s = uuidNil
span.traceID.s, _ = id.New() span.traceID.s = uuidNil
if span.ctx == nil { if span.ctx == nil {
span.ctx = context.Background() span.ctx = context.Background()
} }