{"record":{"id":"41544753aee04ba2","repo":"docker/compose","slug":"initializing-otel-connection-from-docker-context-m","errorCode":null,"errorMessage":"initializing otel connection from docker context metadata: %w","messagePattern":"initializing otel connection from docker context metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tracing/docker_context.go","lineNumber":72,"sourceCode":"\t\t\tif err := os.Setenv(k, v); err != nil {\n\t\t\t\tpanic(fmt.Errorf(\"restoring env for %q: %w\", k, err))\n\t\t\t}\n\t\t}\n\t}()\n\tfor k := range otelEnv {\n\t\tif err := os.Unsetenv(k); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"stashing env for %q: %w\", k, err)\n\t\t}\n\t}\n\n\tconn, err := grpc.NewClient(cfg.Endpoint,\n\t\tgrpc.WithContextDialer(memnet.DialEndpoint),\n\t\t// this dial is restricted to using a local Unix socket / named pipe,\n\t\t// so there is no need for TLS\n\t\tgrpc.WithTransportCredentials(insecure.NewCredentials()),\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"initializing otel connection from docker context metadata: %w\", err)\n\t}\n\n\tclient := otlptracegrpc.NewClient(otlptracegrpc.WithGRPCConn(conn))\n\treturn client, nil\n}\n\n// ConfigFromDockerContext inspects extra metadata included as part of the\n// specified Docker context to try and extract a valid OTLP client configuration.\nfunc ConfigFromDockerContext(st store.Store, name string) (OTLPConfig, error) {\n\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]","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/internal/tracing/docker_context.go#L54-L90","documentation":"With an OTLP endpoint configured via Docker context, compose builds a gRPC client with grpc.NewClient, a custom dialer restricted to local Unix sockets/named pipes (memnet.DialEndpoint), and insecure credentials. If client construction fails, tracing init returns 'initializing otel connection from docker context metadata: %w'. Note grpc.NewClient defers connection, so failures here are config-level (bad endpoint format), not connectivity.","triggerScenarios":"cfg.Endpoint from the Docker context 'otel' field being unparseable as a gRPC target — e.g. 'http://localhost:4317' instead of 'unix:///...' or 'localhost:4317' with an invalid authority component — causing grpc.NewClient to return err before any dial.","commonSituations":"Hand-editing the Docker context meta.json to add an otel block with an HTTP URL or typo'd endpoint; Docker Desktop writing an endpoint scheme the gRPC resolver rejects; endpoints with spaces or invalid characters.","solutions":["Fix the endpoint format in the Docker context metadata: use a gRPC target such as unix:///var/run/docker-desktop_OTLP.sock or host:port without a scheme","docker context export <name> (or edit meta.json) to inspect the otel.OTEL_EXPORTER_OTLP_ENDPOINT value and correct it","If you do not want context-based tracing, remove the otel field from the context metadata so cfg.Endpoint is empty and this path is skipped","Validate with: docker context inspect <name> --format '{{json .AdditionalFields}}'"],"exampleFix":"// ~/.docker/contexts/meta/<hash>/meta.json\n// before: \"otel\": {\"OTEL_EXPORTER_OTLP_ENDPOINT\": \"http://localhost:4317\"}\n// after:  \"otel\": {\"OTEL_EXPORTER_OTLP_ENDPOINT\": \"localhost:4317\"}","handlingStrategy":"validation","validationCode":"// validate the endpoint shape before it reaches grpc.NewClient\nfunc validGRPCTarget(ep string) bool {\n    return !strings.HasPrefix(ep, \"http://\") && !strings.HasPrefix(ep, \"https://\") &&\n        (strings.HasPrefix(ep, \"unix://\") || regexp.MustCompile(`^[A-Za-z0-9._~-]+(:\\d+)?$`).MatchString(ep))\n}","typeGuard":"null // endpoint arrives as untyped JSON from context metadata","tryCatchPattern":"// on this wrap, docker context inspect the otel block, fix the endpoint format (no http:// scheme), retry once","preventionTips":["Use gRPC target syntax in otel context config: unix:///... or host:port","Prefer letting Docker Desktop write the otel field rather than hand-editing"],"tags":["otel","grpc","docker-context","tracing","configuration","go"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}