Skip to content

Commit df3fd14

Browse files
mprpicclaude
andauthored
fix: disable OTel metrics export when no collector is configured (#644)
Previously, InitMetrics defaulted to localhost:4317 when OTEL_EXPORTER_OTLP_ENDPOINT was unset, causing "failed to upload metrics" errors every 30s in environments without an OTel collector (kind, CRC, minikube, and any production cluster without one). Make metrics export opt-in: return a no-op when the endpoint is not configured, and log a single informational line at startup. This is mostly relevant for local dev where running the collector is not necessary (and is undefined in most overlays). The specific errors reported in the log are: ``` 2026/02/16 19:22:53 failed to upload metrics: context deadline exceeded: rpc error: code = Unavailable desc = name resolver error: produced zero addresses ``` Signed-off-by: Martin Prpič <mprpic@redhat.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1880c62 commit df3fd14

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

components/operator/internal/controller/otel_metrics.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ var (
4545
podRestarts metric.Int64Counter
4646
)
4747

48-
// InitMetrics initializes OpenTelemetry metrics
48+
// InitMetrics initializes OpenTelemetry metrics.
49+
// Set OTEL_EXPORTER_OTLP_ENDPOINT to configure the collector address.
50+
// Leave unset or empty to disable metrics export (no-op).
4951
func InitMetrics(ctx context.Context) (func(), error) {
50-
// Get OTLP endpoint from environment
52+
// Get OTLP endpoint from environment; skip if not configured
5153
endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
5254
if endpoint == "" {
53-
endpoint = "localhost:4317" // Default OTLP gRPC endpoint
55+
log.Println("OTEL_EXPORTER_OTLP_ENDPOINT not set, metrics export disabled")
56+
return func() {}, nil
5457
}
5558

5659
// Create resource with service information

0 commit comments

Comments
 (0)