{"record":{"id":"a85cd63a36eca777","repo":"docker/compose","slug":"stashing-env-for-q-w","errorCode":null,"errorMessage":"stashing env for %q: %w","messagePattern":"stashing env for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tracing/docker_context.go","lineNumber":61,"sourceCode":"\t}\n\n\tif cfg.Endpoint == \"\" {\n\t\treturn nil, nil\n\t}\n\n\t// HACK: unfortunately _all_ public OTEL initialization functions\n\t// \timplicitly read from the OS env, so temporarily unset them all and\n\t// \trestore afterwards\n\tdefer func() {\n\t\tfor k, v := range otelEnv {\n\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","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/internal/tracing/docker_context.go#L43-L79","documentation":"Before creating the Docker-context OTLP client, compose stashes (unsets) every OTEL_* env var so OTEL's env-reading defaults do not interfere. If os.Unsetenv fails for a key, initialization returns 'stashing env for %q: %w'. The named key is the exact env var that could not be removed.","triggerScenarios":"traceClientFromDockerContext with a non-empty otelEnv map (OTEL_* vars present) and os.Unsetenv(k) failing — realistically only under memory-allocation failure or platform-specific env corruption; returned as an error, joined into InitProvider's result.","commonSituations":"Running compose with OTEL_EXPORTER_OTLP_* vars exported while the process hits memory pressure; containerized CI environments with very low memory limits at startup.","solutions":["Address the wrapped cause (usually allocation failure): raise the memory limit for the compose process/container","Retry the command — transient allocation failures at startup are the realistic case","If it reproduces deterministically with one key, inspect that env var for anomalies (embedded NULs, gigantic value) and re-export it cleanly: unset OTEL_X && export OTEL_X=..."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-sanitize OTEL env: drop vars with empty/oversized values before compose starts\nfor _, kv := range os.Environ() { if k, _, ok := strings.Cut(kv, \"=\"); ok && strings.HasPrefix(k, \"OTEL_\") && len(kv) > 4096 { os.Unsetenv(k) } }","typeGuard":null,"tryCatchPattern":"// treat as transient: catch the wrap from InitTracing, re-export the named OTEL_* var cleanly, retry the command once","preventionTips":["Export OTEL_* vars with sane lengths and no control characters","Provide adequate memory to CI containers running compose"],"tags":["otel","environment","tracing","go"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}