googleapis/mcp-toolbox · error

unable to set up resource: %w

Error message

unable to set up resource: %w

What it means

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.

Source

Thrown at internal/telemetry/telemetry.go:67

		var err error
		for _, fn := range shutdownFuncs {
			err = errors.Join(err, fn(ctx))
		}
		shutdownFuncs = nil
		return err
	}

	// 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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the error delivered to handleErr (it wraps the resource error); fix the invalid attribute it names.
  2. Ensure the version string and service name are non-empty, valid strings.
  3. Validate OTEL_RESOURCE_ATTRIBUTES format (key=value pairs, comma separated) if set.
  4. Avoid mixing resources with different schema URLs; use one consistent semconv version.
  5. Confirm the otel SDK/res module versions are compatible.

Example fix

// before
export OTEL_RESOURCE_ATTRIBUTES="bad-format-no-equals"
// after
export OTEL_RESOURCE_ATTRIBUTES="service.namespace=toolbox,deployment.environment=prod"
Defensive patterns

Strategy: validation

Validate before calling

// Validate resource attributes before enabling telemetry
if (!process.env.OTEL_SERVICE_NAME) process.env.OTEL_SERVICE_NAME = 'toolbox';
// ensure OTEL_RESOURCE_ATTRIBUTES entries are key=value pairs

Try / catch

try { await setupOTel(); }
catch (e) {
  if (String(e.message).includes("unable to set up resource")) {
    // fix service name / resource attrs, or continue without telemetry
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Empty or invalid OTEL_SERVICE_NAME / version string, resource.New with mismatched schema URLs, custom detector failures, malformed OTEL_RESOURCE_ATTRIBUTES env var.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/55491ab0da8fa3f5. Report an issue: GitHub.