googleapis/mcp-toolbox · error
unable to set up trace provider: %w
Error message
unable to set up trace provider: %w
What it means
SetupOTel failed to create the OTLP/GCP trace provider. After the resource is built, newTracerProvider configures the tracer provider with the requested exporter (OTLP or GCP Cloud Trace); an exporter or batcher setup failure is wrapped as 'unable to set up trace provider' and passed to handleErr, aborting telemetry setup.
Source
Thrown at internal/telemetry/telemetry.go:74
// handleErr calls shutdown for cleanup and makes sure that all errors are returned.
handleErr := func(inErr error) {
err = errors.Join(inErr, shutdown(ctx))
}
// Configure Context Propagation to use the default W3C traceparent format.
otel.SetTextMapPropagator(autoprop.NewTextMapPropagator())
res, err := newResource(ctx, versionString, telemetryServiceName)
if err != nil {
errMsg := fmt.Errorf("unable to set up resource: %w", err)
handleErr(errMsg)
return
}
tracerProvider, err := newTracerProvider(ctx, res, telemetryOTLP, telemetryGCP, telemetryGCPProject)
if err != nil {
errMsg := fmt.Errorf("unable to set up trace provider: %w", err)
handleErr(errMsg)
return
}
shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown)
otel.SetTracerProvider(tracerProvider)
meterProvider, err := newMeterProvider(ctx, res, telemetryOTLP, telemetryGCP, telemetryGCPProject)
if err != nil {
errMsg := fmt.Errorf("unable to set up meter provider: %w", err)
handleErr(errMsg)
return
}
shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown)
otel.SetMeterProvider(meterProvider)
return shutdown, nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Read the error passed to handleErr; for OTLP, verify the endpoint URL and that the collector is reachable (curl the OTLP port).
- For GCP exporter, ensure GOOGLE_APPLICATION_CREDENTIALS/ADC is set and the project ID is valid.
- Check the --telemetry-traces / OTLP / GCP flags for typos; use a supported combination.
- Test network egress to the collector/Cloud Trace from the toolbox host (proxy/firewall rules).
- If tracing is optional, disable it to let the server start without telemetry.
Example fix
// before --telemetry-otlp-endpoint="http://collector:4317" // collector not deployed // after # deploy collector or point to the correct endpoint --telemetry-otlp-endpoint="http://otel-collector.observability:4317"
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: is the OTLP collector reachable?
import net from 'node:net';
const [h, p] = process.env.OTEL_EXPORTER_OTLP_ENDPOINT.replace('http://','').split(':');
net.createConnection({ host: h, port: Number(p ?? 4317) })
.on('connect', function(){ this.end(); })
.on('error', () => console.error('OTLP endpoint unreachable')); Try / catch
try { await setupOTel(); }
catch (e) {
if (String(e.message).includes("unable to set up trace provider")) {
// check OTLP endpoint/GCP creds; optionally restart with tracing disabled
}
} Prevention
- Verify the OTLP endpoint URL and that the collector is up and reachable.
- For GCP export, set valid credentials (ADC) and project ID before startup.
- Validate --telemetry flags; use supported exporter combinations.
- Confirm firewall/egress rules allow the OTLP/trace export ports.
- Keep tracing optional so the server can run without it if the backend is down.
When it happens
Trigger: Calling Setup/SetupOTel with telemetry tracing enabled where newTracerProvider errors — e.g., invalid OTLP endpoint, failed GCP project/credentials detection, unsupported exporter selection.
Common situations: Wrong OTEL_EXPORTER_OTLP_ENDPOINT or unreachable collector, missing Google Cloud credentials (GOOGLE_APPLICATION_CREDENTIALS) or project ID when telemetryGCP is set, network egress blocked in restricted environments, malformed telemetry flags.
Related errors
- unable to set up meter provider: %w
- unable to set up resource: %w
- error setting up OpenTelemetry: %w
- error shutting down OpenTelemetry: %w
- unable to create %s metric: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/2c04bf9518cb95a3.
Report an issue: GitHub.