docker/compose · error

unexpected type for field %q: %T (expected: %T)

Error message

unexpected type for field %q: %T (expected: %T)

What it means

ConfigFromDockerContext reads the 'otel' field from the Docker context's additional metadata. If the field is present but is not a JSON object (map[string]any) — e.g. a string, number, array, or boolean — parsing aborts with 'unexpected type for field %q: %T (expected: %T)'. The message helpfully prints both the actual and expected Go types.

Source

Thrown at internal/tracing/docker_context.go:100

	meta, err := st.GetMetadata(name)
	if err != nil {
		return OTLPConfig{}, err
	}

	var otelCfg any
	switch m := meta.Metadata.(type) {
	case command.DockerContext:
		otelCfg = m.AdditionalFields[otelConfigFieldName]
	case map[string]any:
		otelCfg = m[otelConfigFieldName]
	}
	if otelCfg == nil {
		return OTLPConfig{}, nil
	}

	otelMap, ok := otelCfg.(map[string]any)
	if !ok {
		return OTLPConfig{}, fmt.Errorf(
			"unexpected type for field %q: %T (expected: %T)",
			otelConfigFieldName,
			otelCfg,
			otelMap,
		)
	}

	// keys from https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/
	cfg := OTLPConfig{
		Endpoint: valueOrDefault[string](otelMap, "OTEL_EXPORTER_OTLP_ENDPOINT"),
	}
	return cfg, nil
}

// valueOrDefault returns the type-cast value at the specified key in the map
// if present and the correct type; otherwise, it returns the default value for
// T.
func valueOrDefault[T any](m map[string]any, key string) T {

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Inspect the context: docker context inspect <name> --format '{{json .AdditionalFields}}' — check the shape of the otel value
  2. Rewrite it as an object: "otel": {"OTEL_EXPORTER_OTLP_ENDPOINT": "unix:///path/or/host:port"}
  3. If context tracing is unwanted, delete the otel field entirely (a missing field returns an empty config, no error)
  4. Recreate the context if meta.json editing feels risky: docker context rm <name> && docker context create ... (then let Docker Desktop re-add otel)

Example fix

# docker context inspect shows: "otel": "localhost:4317"
# fix meta.json under ~/.docker/contexts/meta/<hash>/meta.json:
#   before: "otel": "localhost:4317"
#   after:  "otel": {"OTEL_EXPORTER_OTLP_ENDPOINT": "localhost:4317"}
Defensive patterns

Strategy: type-guard

Validate before calling

null // metadata is loaded internally; validate at authoring time instead

Type guard

// in Go, when reading context metadata yourself
func isOTelConfigMap(v any) bool { _, ok := v.(map[string]any); return ok }

Try / catch

// catch the wrap from ConfigFromDockerContext/InitTracing; if it names the otel field, fix meta.json so otel is an object, then retry

Prevention

When it happens

Trigger: A Docker context whose metadata contains "otel": "localhost:4317" (string), "otel": 4317 (number), or any non-object JSON value instead of {"OTEL_EXPORTER_OTLP_ENDPOINT": "..."}. Applies to both DockerContext.AdditionalFields and raw map[string]any metadata shapes.

Common situations: Hand-authoring or scripting the otel config into meta.json with a scalar value; tooling that flattens the endpoint into a plain string; schema drift after Docker Desktop changes how it embeds otel config.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/46b3c0501cc4800f. Report an issue: GitHub.