[#12] tracing: Optimize noop exporter

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-07-05 10:25:48 +03:00
parent cb37f5975e
commit 6dd265d949

View file

@ -3,7 +3,6 @@ package tracing
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -12,6 +11,7 @@ import (
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace" "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0" semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop" "go.opentelemetry.io/otel/trace/noop"
@ -133,7 +133,7 @@ func getExporter(ctx context.Context, cfg *Config) (sdktrace.SpanExporter, error
case StdoutExporter: case StdoutExporter:
return stdouttrace.New() return stdouttrace.New()
case NoOpExporter: case NoOpExporter:
return stdouttrace.New(stdouttrace.WithWriter(io.Discard)) return tracetest.NewNoopExporter(), nil
case OTLPgRPCExporter: case OTLPgRPCExporter:
return otlptracegrpc.New(ctx, otlptracegrpc.WithEndpoint(cfg.Endpoint), otlptracegrpc.WithInsecure()) return otlptracegrpc.New(ctx, otlptracegrpc.WithEndpoint(cfg.Endpoint), otlptracegrpc.WithInsecure())
} }