Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **unit**: `unit.tracing.enabled` controls the trace exporter. Set it to `false` to keep the OTLP exporter from starting. The application receives a no-op tracer provider, and the W3C trace context propagator stays installed so inbound trace ids still reach the logs. The exporter stays on when the key is absent.

## [0.15.0] - 2026-10-28

### Changed
Expand Down
17 changes: 17 additions & 0 deletions unit/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
traceSdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -75,6 +76,7 @@ type (
}

TracingConfig struct {
Enabled bool `json:"enabled"`
Addr string `json:"addr"`
MaxBatchSize int `json:"max-batch-size"`
BatchTimeout int `json:"batch-timeout"`
Expand All @@ -95,6 +97,7 @@ func NewUnit(main Runnable, name, version, environment string) *Unit {
Addr: ":9090",
},
Tracing: TracingConfig{
Enabled: true,
Addr: ":4317",
MaxBatchSize: 1024,
BatchTimeout: 10,
Expand Down Expand Up @@ -304,6 +307,20 @@ func (u *Unit) runTracingExporter(ctx context.Context, initialized chan<- trace.
logger := u.logger.Named("unit.traces")
config := u.config.Tracing

if !config.Enabled {
tracerProvider := noop.NewTracerProvider()
otel.SetTracerProvider(tracerProvider)
otel.SetTextMapPropagator(propagation.TraceContext{})

initialized <- tracerProvider

logger.InfoCtx(ctx, "traces exporter disabled")

<-ctx.Done()

return nil
}

logger.InfoCtx(ctx, "starting traces exporter", log.String("addr", config.Addr))

otel.SetErrorHandler(&otelErrorHandler{logger: logger, ctx: ctx})
Expand Down