docker/compose · error
initializing otel connection from docker context metadata: %
Error message
initializing otel connection from docker context metadata: %w
What it means
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.
Source
Thrown at internal/tracing/docker_context.go:72
if err := os.Setenv(k, v); err != nil {
panic(fmt.Errorf("restoring env for %q: %w", k, err))
}
}
}()
for k := range otelEnv {
if err := os.Unsetenv(k); err != nil {
return nil, fmt.Errorf("stashing env for %q: %w", k, err)
}
}
conn, err := grpc.NewClient(cfg.Endpoint,
grpc.WithContextDialer(memnet.DialEndpoint),
// this dial is restricted to using a local Unix socket / named pipe,
// so there is no need for TLS
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
return nil, fmt.Errorf("initializing otel connection from docker context metadata: %w", err)
}
client := otlptracegrpc.NewClient(otlptracegrpc.WithGRPCConn(conn))
return client, nil
}
// ConfigFromDockerContext inspects extra metadata included as part of the
// specified Docker context to try and extract a valid OTLP client configuration.
func ConfigFromDockerContext(st store.Store, name string) (OTLPConfig, error) {
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]View on GitHub (pinned to ddc4b044b6)
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}}'
Example fix
// ~/.docker/contexts/meta/<hash>/meta.json
// before: "otel": {"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317"}
// after: "otel": {"OTEL_EXPORTER_OTLP_ENDPOINT": "localhost:4317"} Defensive patterns
Strategy: validation
Validate before calling
// validate the endpoint shape before it reaches grpc.NewClient
func validGRPCTarget(ep string) bool {
return !strings.HasPrefix(ep, "http://") && !strings.HasPrefix(ep, "https://") &&
(strings.HasPrefix(ep, "unix://") || regexp.MustCompile(`^[A-Za-z0-9._~-]+(:\d+)?$`).MatchString(ep))
} Type guard
null // endpoint arrives as untyped JSON from context metadata
Try / catch
// on this wrap, docker context inspect the otel block, fix the endpoint format (no http:// scheme), retry once
Prevention
- Use gRPC target syntax in otel context config: unix:///... or host:port
- Prefer letting Docker Desktop write the otel field rather than hand-editing
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- loading otel config from docker context metadata: %w
- unexpected type for field %q: %T (expected: %T)
- restoring env for %q: %w
- stashing env for %q: %w
- failed to create resource: %w
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/41544753aee04ba2.
Report an issue: GitHub.