caddyserver/caddy · error

creating resource error: %w

Error message

creating resource error: %w

What it means

Returned while constructing the OpenTelemetry wrapper for the tracing module when ot.newResource fails. The resource carries service.name (from the ServerHeader/version args) built via resource.New with attributes; failure means resource construction options were rejected by the otel SDK.

Source

Thrown at modules/caddyhttp/tracing/tracer.go:62

// newOpenTelemetryWrapper is responsible for the openTelemetryWrapper initialization using provided configuration.
func newOpenTelemetryWrapper(
	ctx context.Context,
	spanName string,
	spanAttributes map[string]string,
) (openTelemetryWrapper, error) {
	if spanName == "" {
		spanName = defaultSpanName
	}

	ot := openTelemetryWrapper{
		spanName:       spanName,
		spanAttributes: spanAttributes,
	}

	version, _ := caddy.Version()
	res, err := ot.newResource(caddyhttp.ServerHeader, version)
	if err != nil {
		return ot, fmt.Errorf("creating resource error: %w", err)
	}

	ot.propagators = autoprop.NewTextMapPropagator()

	// Defer creation of the exporter (and its batch span processor goroutine)
	// until we know a new provider is actually needed. When the global provider
	// already exists it is reused and these options are discarded; building them
	// here unconditionally would leak the exporter and a BatchSpanProcessor
	// goroutine on every config reload.
	tracerProvider, err := globalTracerProvider.getTracerProvider(func() ([]sdktrace.TracerProviderOption, error) {
		traceExporter, err := autoexport.NewSpanExporter(ctx)
		if err != nil {
			return nil, fmt.Errorf("creating trace exporter error: %w", err)
		}

		return []sdktrace.TracerProviderOption{
			sdktrace.WithBatcher(traceExporter),
			sdktrace.WithResource(res),

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Check the wrapped error for the offending attribute key/value
  2. Fix env vars: OTEL_SERVICE_NAME=myapp, OTEL_RESOURCE_ATTRIBUTES="key=value,key2=value2"
  3. Unset or sanitize custom OTEL_* vars and retry provisioning (`caddy validate` with tracing in config)
  4. In custom builds, align otel library versions with what Caddy's tracing module expects

Example fix

# before
export OTEL_RESOURCE_ATTRIBUTES="service.name myapp,deployment.env prod"

# after
export OTEL_SERVICE_NAME=myapp
export OTEL_RESOURCE_ATTRIBUTES="deployment.env=prod"
Defensive patterns

Strategy: validation

Validate before calling

# shell: verify OTEL env before starting caddy
[ -n "$OTEL_SERVICE_NAME" ] || export OTEL_SERVICE_NAME=myapp
echo "$OTEL_RESOURCE_ATTRIBUTES" | tr ',' '\n' | grep -vE '^[A-Za-z0-9_.\-/]+=.+$' && { echo 'bad OTEL_RESOURCE_ATTRIBUTES' >&2; exit 1; } || true

Prevention

When it happens

Trigger: Provisioning the tracing handler when resource.New returns an error, commonly from invalid OTEL_RESOURCE_ATTRIBUTES / OTEL_SERVICE_NAME environment variable values (malformed key=value pairs) or conflicting resource-merge options in the otel SDK version in use.

Common situations: Deployments setting OTEL_RESOURCE_ATTRIBUTES with bad syntax ('service.name foo' without '='), duplicated service name sources, or older/newer otel SDKs in custom builds with different validation strictness.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/72402e35fc38b7b1. Report an issue: GitHub.