{"record":{"id":"651e6fb60ca765ff","repo":"kubernetes/kops","slug":"creating-directories-q-w","errorCode":null,"errorMessage":"creating directories %q: %w","messagePattern":"creating directories %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/otel.go","lineNumber":119,"sourceCode":"\t\tdest = os.Getenv(\"OTEL_EXPORTER_OTLP_TRACES_DIR\")\n\t\tif dest != \"\" {\n\t\t\tdestIsDirectory = true\n\t\t}\n\t}\n\tif dest == \"\" {\n\t\tdest = os.Getenv(\"OTEL_EXPORTER_OTLP_DIR\")\n\t\tif dest != \"\" {\n\t\t\tdestIsDirectory = true\n\t\t}\n\t}\n\tif dest == \"\" {\n\t\treturn nil, nil\n\t}\n\n\t// If we are writing to a directory, construct a (likely) unique name\n\tif destIsDirectory {\n\t\tif err := os.MkdirAll(dest, 0755); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating directories %q: %w\", dest, err)\n\t\t}\n\t\tprocessName, err := os.Executable()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"getting process name: %w\", err)\n\t\t}\n\t\tprocessName = filepath.Base(processName)\n\t\tprocessName = strings.TrimSuffix(processName, \".exe\")\n\t\tpid := os.Getpid()\n\t\ttimestamp := time.Now().UTC().Format(time.RFC3339)\n\t\tfilename := fmt.Sprintf(\"%s-%d-%s.otel\", processName, pid, timestamp)\n\t\tdest = filepath.Join(dest, filename)\n\t}\n\n\ttraceExporter, err := otlptracefile.New(ctx, otlptracefile.WithPath(dest))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/otel.go#L101-L137","documentation":"In kOps' OpenTelemetry setup (newTraceProvider), when the OTel exporter destination is a directory, the code ensures it exists with os.MkdirAll(dest, 0755). If directory creation fails, the error is wrapped as \"creating directories %q: %w\" and OTel SDK setup is aborted. It reports filesystem permission or path problems, wrapped with %w so os.Err* checks work.","triggerScenarios":"Running a kOps binary with OTLP file exporter configured (OTEL_EXPORTER_OTLP_ENDPOINT or traces destination set to a directory path) where the parent path does not exist and cannot be created, exists as a file, or the process lacks write permission (e.g. under / or another user's home).","commonSituations":"Container running as non-root with OTEL_* env vars pointing to /var/lib/traces; a file already exists at the destination path; typo'd path like /tpm instead of /tmp; read-only root filesystem.","solutions":["Pre-create the directory with correct ownership: mkdir -p <dest> && chmod/chown appropriately for the kOps process user","Verify the path is a directory, not an existing file, and the parent chain is writable","Check the wrapped os error (e.g. mkdir /x: permission denied) and adjust the OTEL destination env var to a writable location such as /tmp/traces"],"exampleFix":"# before\nOTEL_EXPORTER_OTLP_ENDPOINT=/var/lib/traces   # dir missing, non-root user\n# after\nmkdir -p /var/lib/traces && chown $(id -u) /var/lib/traces\nexport OTEL_EXPORTER_OTLP_ENDPOINT=/var/lib/traces","handlingStrategy":"validation","validationCode":"dest=\"$OTEL_EXPORTER_OTLP_ENDPOINT\"\nif [ -n \"$dest\" ]; then\n  mkdir -p \"$dest\" 2>/dev/null || { echo \"cannot create OTel dest '$dest': check permissions/path\"; exit 1; }\n  [ -d \"$dest\" ] || { echo \"$dest exists and is not a directory\"; exit 1; }\n  [ -w \"$dest\" ] || { echo \"$dest not writable by current user\"; exit 1; }\nfi","typeGuard":null,"tryCatchPattern":"provider, shutdown, err := newTraceProvider(ctx, dest)\nif err != nil {\n\tif errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrNotExist) {\n\t\t// degrade gracefully: run without tracing\n\t\treturn noopTracer(), nil\n\t}\n\treturn err\n}","preventionTips":["Pre-create OTel destination directories with correct ownership in Dockerfiles/entrypoints","Never point OTEL_* destinations at paths only root can write","Ensure the destination path is a directory, not an existing file","Run containers with a writable volume for trace output"],"tags":["otel","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}