Skip to content

Commit 6524673

Browse files
committed
fix(otel): honor OTEL_METRICS_EXPORTER=none to skip OTLP metric push
When the OTLP backend is traces-only (e.g. Grafana Tempo), the periodic metric exporter POSTs to /v1/metrics every 30s and gets 404s, spamming the logs. Since SOAD already exposes Prometheus /metrics for scraping, OTLP metric export is redundant in that topology. Follow the OTel spec: when OTEL_METRICS_EXPORTER=none, skip the OTLP metric reader while leaving trace export and the Prometheus reader intact. Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
1 parent 04a5867 commit 6524673

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

internal/otelsetup/otelsetup.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,21 @@ func Setup(ctx context.Context, serviceName string) (*Result, error) {
8989
propagation.Baggage{},
9090
))
9191

92-
metricExporter, err := otlpmetrichttp.New(otlpCtx)
93-
if err != nil {
94-
return &Result{Shutdown: shutdown, MetricsHandler: promhttp.Handler()}, err
92+
// OTEL_METRICS_EXPORTER=none skips OTLP metric push while keeping trace
93+
// export. Useful when the OTLP backend is traces-only (e.g. Tempo) and
94+
// metrics are scraped from /metrics by Prometheus instead.
95+
if os.Getenv("OTEL_METRICS_EXPORTER") == "none" {
96+
slog.Info("OpenTelemetry initialized with OTLP traces only (metrics disabled)", "service", serviceName)
97+
} else {
98+
metricExporter, err := otlpmetrichttp.New(otlpCtx)
99+
if err != nil {
100+
return &Result{Shutdown: shutdown, MetricsHandler: promhttp.Handler()}, err
101+
}
102+
readers = append(readers, metric.WithReader(
103+
metric.NewPeriodicReader(metricExporter, metric.WithInterval(30*time.Second)),
104+
))
105+
slog.Info("OpenTelemetry initialized with OTLP exporters", "service", serviceName)
95106
}
96-
readers = append(readers, metric.WithReader(
97-
metric.NewPeriodicReader(metricExporter, metric.WithInterval(30*time.Second)),
98-
))
99-
100-
slog.Info("OpenTelemetry initialized with OTLP exporters", "service", serviceName)
101107
} else {
102108
slog.Info("OpenTelemetry metrics enabled (Prometheus only, no OTLP)", "service", serviceName)
103109
}

0 commit comments

Comments
 (0)