{"record":{"id":"2c04bf9518cb95a3","repo":"googleapis/mcp-toolbox","slug":"unable-to-set-up-trace-provider-w","errorCode":null,"errorMessage":"unable to set up trace provider: %w","messagePattern":"unable to set up trace provider: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/telemetry/telemetry.go","lineNumber":74,"sourceCode":"\n\t// handleErr calls shutdown for cleanup and makes sure that all errors are returned.\n\thandleErr := func(inErr error) {\n\t\terr = errors.Join(inErr, shutdown(ctx))\n\t}\n\n\t// Configure Context Propagation to use the default W3C traceparent format.\n\totel.SetTextMapPropagator(autoprop.NewTextMapPropagator())\n\n\tres, err := newResource(ctx, versionString, telemetryServiceName)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"unable to set up resource: %w\", err)\n\t\thandleErr(errMsg)\n\t\treturn\n\t}\n\n\ttracerProvider, err := newTracerProvider(ctx, res, telemetryOTLP, telemetryGCP, telemetryGCPProject)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"unable to set up trace provider: %w\", err)\n\t\thandleErr(errMsg)\n\t\treturn\n\t}\n\tshutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown)\n\totel.SetTracerProvider(tracerProvider)\n\n\tmeterProvider, err := newMeterProvider(ctx, res, telemetryOTLP, telemetryGCP, telemetryGCPProject)\n\tif err != nil {\n\t\terrMsg := fmt.Errorf(\"unable to set up meter provider: %w\", err)\n\t\thandleErr(errMsg)\n\t\treturn\n\t}\n\tshutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown)\n\totel.SetMeterProvider(meterProvider)\n\n\treturn shutdown, nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/telemetry/telemetry.go#L56-L92","documentation":"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.","triggerScenarios":"Calling Setup/SetupOTel with telemetry tracing enabled where newTracerProvider errors — e.g., invalid OTLP endpoint, failed GCP project/credentials detection, unsupported exporter selection.","commonSituations":"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.","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."],"exampleFix":"// before\n--telemetry-otlp-endpoint=\"http://collector:4317\" // collector not deployed\n// after\n# deploy collector or point to the correct endpoint\n--telemetry-otlp-endpoint=\"http://otel-collector.observability:4317\"","handlingStrategy":"try-catch","validationCode":"// Pre-flight: is the OTLP collector reachable?\nimport net from 'node:net';\nconst [h, p] = process.env.OTEL_EXPORTER_OTLP_ENDPOINT.replace('http://','').split(':');\nnet.createConnection({ host: h, port: Number(p ?? 4317) })\n  .on('connect', function(){ this.end(); })\n  .on('error', () => console.error('OTLP endpoint unreachable'));","typeGuard":null,"tryCatchPattern":"try { await setupOTel(); }\ncatch (e) {\n  if (String(e.message).includes(\"unable to set up trace provider\")) {\n    // check OTLP endpoint/GCP creds; optionally restart with tracing disabled\n  }\n}","preventionTips":["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."],"tags":["telemetry","opentelemetry","tracing","otlp","setup"],"backgroundTag":"otel-initialization-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}