{"record":{"id":"55491ab0da8fa3f5","repo":"googleapis/mcp-toolbox","slug":"unable-to-set-up-resource-w","errorCode":null,"errorMessage":"unable to set up resource: %w","messagePattern":"unable to set up resource: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/telemetry/telemetry.go","lineNumber":67,"sourceCode":"\t\tvar err error\n\t\tfor _, fn := range shutdownFuncs {\n\t\t\terr = errors.Join(err, fn(ctx))\n\t\t}\n\t\tshutdownFuncs = nil\n\t\treturn err\n\t}\n\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","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/telemetry/telemetry.go#L49-L85","documentation":"SetupOTel failed to construct the OpenTelemetry resource (service name, SDK version attributes). The resource is the foundation for all exporters; when newResource fails, SetupOTel reports via the handleErr callback ('handle the error' style, logging or os.Exit depending on setup) and aborts telemetry initialization.","triggerScenarios":"Calling Setup/SetupOTel where resource.New/resource.Merge returns an error — e.g., invalid service name, conflicting schema URLs, or an invalid SEMConv attribute value passed into the resource options.","commonSituations":"Empty or invalid OTEL_SERVICE_NAME / version string, resource.New with mismatched schema URLs, custom detector failures, malformed OTEL_RESOURCE_ATTRIBUTES env var.","solutions":["Check the error delivered to handleErr (it wraps the resource error); fix the invalid attribute it names.","Ensure the version string and service name are non-empty, valid strings.","Validate OTEL_RESOURCE_ATTRIBUTES format (key=value pairs, comma separated) if set.","Avoid mixing resources with different schema URLs; use one consistent semconv version.","Confirm the otel SDK/res module versions are compatible."],"exampleFix":"// before\nexport OTEL_RESOURCE_ATTRIBUTES=\"bad-format-no-equals\"\n// after\nexport OTEL_RESOURCE_ATTRIBUTES=\"service.namespace=toolbox,deployment.environment=prod\"","handlingStrategy":"validation","validationCode":"// Validate resource attributes before enabling telemetry\nif (!process.env.OTEL_SERVICE_NAME) process.env.OTEL_SERVICE_NAME = 'toolbox';\n// ensure OTEL_RESOURCE_ATTRIBUTES entries are key=value pairs","typeGuard":null,"tryCatchPattern":"try { await setupOTel(); }\ncatch (e) {\n  if (String(e.message).includes(\"unable to set up resource\")) {\n    // fix service name / resource attrs, or continue without telemetry\n  }\n}","preventionTips":["Provide a valid, non-empty service name and version string.","Format OTEL_RESOURCE_ATTRIBUTES as comma-separated key=value pairs.","Use a single consistent schema URL / semconv version across resources.","Check the error surfaced via handleErr and fix the named attribute."],"tags":["telemetry","opentelemetry","resource","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"}