{"record":{"id":"46b3c0501cc4800f","repo":"docker/compose","slug":"unexpected-type-for-field-q-t-expected-t","errorCode":null,"errorMessage":"unexpected type for field %q: %T (expected: %T)","messagePattern":"unexpected type for field %q: %T \\(expected: %T\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tracing/docker_context.go","lineNumber":100,"sourceCode":"\tmeta, err := st.GetMetadata(name)\n\tif err != nil {\n\t\treturn OTLPConfig{}, err\n\t}\n\n\tvar otelCfg any\n\tswitch m := meta.Metadata.(type) {\n\tcase command.DockerContext:\n\t\totelCfg = m.AdditionalFields[otelConfigFieldName]\n\tcase map[string]any:\n\t\totelCfg = m[otelConfigFieldName]\n\t}\n\tif otelCfg == nil {\n\t\treturn OTLPConfig{}, nil\n\t}\n\n\totelMap, ok := otelCfg.(map[string]any)\n\tif !ok {\n\t\treturn OTLPConfig{}, fmt.Errorf(\n\t\t\t\"unexpected type for field %q: %T (expected: %T)\",\n\t\t\totelConfigFieldName,\n\t\t\totelCfg,\n\t\t\totelMap,\n\t\t)\n\t}\n\n\t// keys from https://opentelemetry.io/docs/concepts/sdk-configuration/otlp-exporter-configuration/\n\tcfg := OTLPConfig{\n\t\tEndpoint: valueOrDefault[string](otelMap, \"OTEL_EXPORTER_OTLP_ENDPOINT\"),\n\t}\n\treturn cfg, nil\n}\n\n// valueOrDefault returns the type-cast value at the specified key in the map\n// if present and the correct type; otherwise, it returns the default value for\n// T.\nfunc valueOrDefault[T any](m map[string]any, key string) T {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/internal/tracing/docker_context.go#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the context: docker context inspect <name> --format '{{json .AdditionalFields}}' — check the shape of the otel value","Rewrite it as an object: \"otel\": {\"OTEL_EXPORTER_OTLP_ENDPOINT\": \"unix:///path/or/host:port\"}","If context tracing is unwanted, delete the otel field entirely (a missing field returns an empty config, no error)","Recreate the context if meta.json editing feels risky: docker context rm <name> && docker context create ... (then let Docker Desktop re-add otel)"],"exampleFix":"# docker context inspect shows: \"otel\": \"localhost:4317\"\n# fix meta.json under ~/.docker/contexts/meta/<hash>/meta.json:\n#   before: \"otel\": \"localhost:4317\"\n#   after:  \"otel\": {\"OTEL_EXPORTER_OTLP_ENDPOINT\": \"localhost:4317\"}","handlingStrategy":"type-guard","validationCode":"null // metadata is loaded internally; validate at authoring time instead","typeGuard":"// in Go, when reading context metadata yourself\nfunc isOTelConfigMap(v any) bool { _, ok := v.(map[string]any); return ok }","tryCatchPattern":"// catch the wrap from ConfigFromDockerContext/InitTracing; if it names the otel field, fix meta.json so otel is an object, then retry","preventionTips":["Author otel context config as {\"OTEL_EXPORTER_OTLP_ENDPOINT\": \"host:port\"}","Validate meta.json with jq after scripted edits","Keep Docker Desktop's generated otel blocks untouched"],"tags":["otel","docker-context","type-mismatch","configuration","json","go"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}