googleapis/mcp-toolbox · error

trace provider fail to set up resource: %w

Error message

trace provider fail to set up resource: %w

What it means

newResource builds the OpenTelemetry resource that identifies this service (name + version) via resource.New with semconv attributes. When resource.New returns an error (e.g. a resource detector fails or OTEL_RESOURCE_ATTRIBUTES is malformed), SetupOTel aborts and wraps the cause with this message.

Source

Thrown at internal/telemetry/telemetry.go:111

// 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.
		resource.WithContainer(),    // Discover and provide container information.
		resource.WithHost(),         //Discover and provide host information.
		resource.WithSchemaURL(semconv.SchemaURL), // Set the schema url.
		resource.WithAttributes( // Add other custom resource attributes.
			semconv.ServiceName(telemetryServiceName),
			semconv.ServiceVersion(versionString),
		),
	)
	if err != nil {
		return nil, fmt.Errorf("trace provider fail to set up resource: %w", err)
	}
	return r, nil
}

// newTracerProvider creates TracerProvider.
// TracerProvider is a factory for Tracers and is responsible for creating spans.
func newTracerProvider(ctx context.Context, r *resource.Resource, telemetryOTLP string, telemetryGCP bool, telemetryGCPProject string) (*tracesdk.TracerProvider, error) {
	traceOpts := []tracesdk.TracerProviderOption{}
	if telemetryOTLP != "" {
		// otlptracehttp provides an OTLP span exporter using HTTP with protobuf payloads.
		// By default, the telemetry is sent to https://localhost:4318/v1/traces.
		otlpExporter, err := otlptracehttp.New(ctx, otlptracehttp.WithEndpoint(telemetryOTLP))
		if err != nil {
			return nil, err
		}
		traceOpts = append(traceOpts, tracesdk.WithBatcher(otlpExporter))
	}
	if telemetryGCP {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Fix or unset OTEL_RESOURCE_ATTRIBUTES / OTEL_SERVICE_NAME env vars (format: key1=value1,key2=value2)
  2. Identify the wrapped inner detector error and address it (e.g. disable failing cloud/hostname detector)
  3. Pin compatible opentelemetry-go dependency versions
  4. Retry telemetry setup after fixing the environment

Example fix

// before
OTEL_RESOURCE_ATTRIBUTES=service.name=toolbox,=broken
// after
OTEL_RESOURCE_ATTRIBUTES=service.name=toolbox
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check OTel env before setup
if v := os.Getenv("OTEL_RESOURCE_ATTRIBUTES"); v != "" {
  for _, kv := range strings.Split(v, ",") {
    if len(strings.SplitN(kv, "=", 2)) != 2 {
      log.Fatalf("malformed OTEL_RESOURCE_ATTRIBUTES pair: %q", kv)
    }
  }
}

Type guard

func isResourceSetupErr(err error) bool {
  return err != nil && strings.Contains(err.Error(), "trace provider fail to set up resource")
}

Try / catch

if err := telemetry.SetupOTel(ctx, opts...); err != nil {
  log.Printf("otel resource setup failed (continuing without telemetry): %v", err)
}

Prevention

When it happens

Trigger: Calling SetupOTel when resource.New fails — typically a built-in resource detector error or an unparseable OTEL_RESOURCE_ATTRIBUTES / OTEL_SERVICE_NAME environment variable.

Common situations: Malformed OTEL_RESOURCE_ATTRIBUTES (missing '=' or bad key=value pairs), failing host/cloud resource detectors in restricted environments, incompatible otel-go dependency versions.

Related errors


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