googleapis/mcp-toolbox · error
unable to set up meter provider: %w
Error message
unable to set up meter provider: %w
What it means
SetupOTel failed to create the metrics (meter) provider. After the tracer provider is installed, newMeterProvider wires the metric exporter (OTLP or GCP Cloud Monitoring); any failure is wrapped as 'unable to set up meter provider' and delivered to handleErr, aborting telemetry setup before instruments are created.
Source
Thrown at internal/telemetry/telemetry.go:83
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
}
// newResource create default resources for telemetry data.
// Resource represents the entity producing telemetry.
func newResource(ctx context.Context, versionString string, telemetryServiceName string) (*resource.Resource, error) {
// Ensure default SDK resources and the required service name are set.
r, err := resource.New(
ctx,
resource.WithFromEnv(), // Discover and provide attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables.
resource.WithTelemetrySDK(), // Discover and provide information about the OTel SDK used.
resource.WithOS(), // Discover and provide OS information.View on GitHub (pinned to 8cc6e09de2)
Solutions
- Inspect the error sent to handleErr; for OTLP, confirm the metrics endpoint and collector health.
- For GCP, verify ADC credentials, project ID, and that the Cloud Monitoring API is enabled.
- Validate the telemetry flags (--telemetry-metrics, otlp/gcp selection) for correct values.
- Check network egress/firewall to the metrics backend from the host.
- If metrics are optional, disable them so the server can start without telemetry.
Example fix
// before --telemetry-gcp --telemetry-gcp-project="" // empty project // after --telemetry-gcp --telemetry-gcp-project="my-gcp-project"
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: check metrics exporter reachability and GCP project
if (process.env.TELEMETRY_GCP === 'true' && !process.env.GOOGLE_CLOUD_PROJECT) {
console.error('telemetryGCP requires a project id');
} Try / catch
try { await setupOTel(); }
catch (e) {
if (String(e.message).includes("unable to set up meter provider")) {
// check metrics endpoint/GCP creds/monitoring API; restart with metrics disabled if optional
}
} Prevention
- Confirm the OTLP metrics endpoint and collector health before startup.
- Enable the Cloud Monitoring API and provide valid ADC credentials when using the GCP exporter.
- Set an explicit GCP project ID; avoid empty values.
- Validate telemetry CLI flags against documented combinations.
- Design deployments so metrics export failure does not block server startup.
When it happens
Trigger: Calling Setup/SetupOTel with metrics enabled where newMeterProvider errors — invalid OTLP metrics endpoint, GCP Cloud Monitoring credential/project failure, or exporter configuration errors.
Common situations: Unreachable OTLP collector on the metrics port, missing GCP credentials or monitoring API not enabled for the project, wrong --telemetry-metrics flags, egress/firewall blocking metric export.
Related errors
- unable to set up trace provider: %w
- unable to create %s metric: %w
- unable to set up resource: %w
- error setting up OpenTelemetry: %w
- error shutting down OpenTelemetry: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/c6f56180d1bb92f2.
Report an issue: GitHub.