Skip to content

Commit

Permalink
[service] implement a noop tracer provider
Browse files Browse the repository at this point in the history
This is to address some of the memory concerns around the SDK's noop tracer provider. Instead of using the
published noop tracer provider, we implement our own to avoid the cost of context propagation, which has
been proven to be high enough to cause issues for end users.

Part of #10858

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten committed Aug 30, 2024
1 parent b4fab2b commit 94b236d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion service/telemetry/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"

"go.opentelemetry.io/collector/config/configtelemetry"
Expand Down Expand Up @@ -47,10 +48,28 @@ func attributes(set Settings, cfg Config) map[string]interface{} {
return attrs
}

type noopNoContextTracer struct {
embedded.Tracer
}

var noopSpan = noop.Span{}

func (n *noopNoContextTracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
return ctx, noopSpan
}

type noopNoContextTracerProvider struct {
embedded.TracerProvider
}

func (n *noopNoContextTracerProvider) Tracer(name string, options ...trace.TracerOption) trace.Tracer {
return &noopNoContextTracer{}
}

// New creates a new Telemetry from Config.
func newTracerProvider(ctx context.Context, set Settings, cfg Config) (trace.TracerProvider, error) {
if globalgates.NoopTracerProvider.IsEnabled() || cfg.Traces.Level == configtelemetry.LevelNone {
return noop.NewTracerProvider(), nil
return &noopNoContextTracerProvider{}, nil
}

sch := semconv.SchemaURL
Expand Down

0 comments on commit 94b236d

Please sign in to comment.