Skip to content

Commit d04eb02

Browse files
peppescgclaude
andauthored
fix(telemetry): warn instead of crashing when OTLP endpoint has no enabled exporters (#4648)
* fix(telemetry): warn instead of crashing when OTLP endpoint has no enabled exporters When an OTLP endpoint is configured via `thv config otel set-endpoint` but both tracing and metrics are disabled, `thv serve` crashes with a fatal validation error preventing the server from starting. Instead of failing, log a warning and clear the endpoint so the server starts normally. This avoids a confusing "Health check failed" error in ToolHive Studio. Fixes #4647 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor(telemetry): extract handleUnusedEndpoint to reduce cyclomatic complexity Move the unused endpoint check into a dedicated helper function to keep NewServeProvider under the gocyclo threshold (15). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(telemetry): enable tracing by default when OTLP endpoint has no enabled exporters Instead of clearing the endpoint (which would silently drop telemetry for users who configured an endpoint expecting it to work), enable tracing by default so the endpoint is actually used. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3a6c0c1 commit d04eb02

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

pkg/telemetry/serve.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func NewServeProvider(ctx context.Context) (provider *Provider, otelEnabled bool
2929

3030
otelCfg := appConfig.OTEL
3131
hasRegisteredProcessors := HasRegisteredSpanProcessors()
32+
33+
handleUnusedEndpoint(&otelCfg)
34+
3235
if otelCfg.Endpoint == "" && !otelCfg.EnablePrometheusMetricsPath && !hasRegisteredProcessors {
3336
return nil, false, nil
3437
}
@@ -74,3 +77,20 @@ func NewServeProvider(ctx context.Context) (provider *Provider, otelEnabled bool
7477

7578
return p, true, nil
7679
}
80+
81+
// handleUnusedEndpoint enables tracing by default when an OTLP endpoint is
82+
// configured but both tracing and metrics are disabled, so the server can start
83+
// normally instead of crashing with a fatal validation error.
84+
func handleUnusedEndpoint(otelCfg *config.OpenTelemetryConfig) {
85+
if otelCfg.Endpoint == "" {
86+
return
87+
}
88+
tracingOff := otelCfg.TracingEnabled == nil || !*otelCfg.TracingEnabled
89+
metricsOff := otelCfg.MetricsEnabled == nil || !*otelCfg.MetricsEnabled
90+
if tracingOff && metricsOff {
91+
slog.Warn("OTLP endpoint is configured but tracing and metrics are both disabled; enabling tracing by default",
92+
"endpoint", otelCfg.Endpoint)
93+
enabled := true
94+
otelCfg.TracingEnabled = &enabled
95+
}
96+
}

0 commit comments

Comments
 (0)