{"record":{"id":"ae717ea33f73ef84","repo":"grpc/grpc-go","slug":"error-reading-observability-configuration-file-q","errorCode":null,"errorMessage":"error reading observability configuration file %q: %v","messagePattern":"error reading observability configuration file %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/config.go","lineNumber":133,"sourceCode":"\t}\n\tif err := validateLoggingEvents(&config); err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing observability config: %v\", err)\n\t}\n\tif config.CloudTrace != nil && (config.CloudTrace.SamplingRate > 1 || config.CloudTrace.SamplingRate < 0) {\n\t\treturn nil, fmt.Errorf(\"error parsing observability config: invalid cloud trace sampling rate %v\", config.CloudTrace.SamplingRate)\n\t}\n\tlogger.Infof(\"Parsed ObservabilityConfig: %+v\", &config)\n\treturn &config, nil\n}\n\nfunc parseObservabilityConfig() (*config, error) {\n\tif f := envconfig.ObservabilityConfigFile; f != \"\" {\n\t\tif envconfig.ObservabilityConfig != \"\" {\n\t\t\tlogger.Warning(\"Ignoring GRPC_GCP_OBSERVABILITY_CONFIG and using GRPC_GCP_OBSERVABILITY_CONFIG_FILE contents.\")\n\t\t}\n\t\tcontent, err := os.ReadFile(f)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading observability configuration file %q: %v\", f, err)\n\t\t}\n\t\treturn unmarshalAndVerifyConfig(content)\n\t} else if envconfig.ObservabilityConfig != \"\" {\n\t\treturn unmarshalAndVerifyConfig([]byte(envconfig.ObservabilityConfig))\n\t}\n\t// If the ENV var doesn't exist, do nothing\n\treturn nil, nil\n}\n\nfunc ensureProjectIDInObservabilityConfig(ctx context.Context, config *config) error {\n\tif config.ProjectID == \"\" {\n\t\t// Try to fetch the GCP project id\n\t\tprojectID := fetchDefaultProjectID(ctx)\n\t\tif projectID == \"\" {\n\t\t\treturn fmt.Errorf(\"empty destination project ID\")\n\t\t}\n\t\tconfig.ProjectID = projectID\n\t}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/gcp/observability/config.go#L115-L151","documentation":"GRPC_GCP_OBSERVABILITY_CONFIG_FILE was set, but os.ReadFile failed on the referenced path. The %q is the file path and %v is the os error (most often 'no such file or directory' or 'permission denied'). This fires before any parsing.","triggerScenarios":"Setting GRPC_GCP_OBSERVABILITY_CONFIG_FILE to a path that does not exist, is unreadable due to permissions, is a directory, or lives on a mount that is not attached in the container. observability.Start -> parseObservabilityConfig -> os.ReadFile.","commonSituations":"Container/pod deploy with a wrong mountPath; ConfigMap not mounted; file path relative to a different working directory; permission bits too strict (0600 owned by another uid); typo in the env var value; secret volume not yet attached at process start.","solutions":["Confirm the path printed in %q exists: `ls -l <path>` from the same user/namespace the process runs as.","Fix permissions (e.g. `chmod 644 <path>`) or run the process under the owning uid.","If running in Kubernetes, verify the ConfigMap/Secret volumeMount and that the container starts after the mount.","Use an absolute path; do not rely on the process working directory.","If the file is optional, unset GRPC_GCP_OBSERVABILITY_CONFIG_FILE (fall back to GRPC_GCP_OBSERVABILITY_CONFIG) or leave both unset."],"exampleFix":"# before\nexport GRPC_GCP_OBSERVABILITY_CONFIG_FILE=etc/obs.json\n\n# after\nexport GRPC_GCP_OBSERVABILITY_CONFIG_FILE=/etc/grpc/observability.json","handlingStrategy":"validation","validationCode":"if f := os.Getenv(\"GRPC_GCP_OBSERVABILITY_CONFIG_FILE\"); f != \"\" {\n    info, err := os.Stat(f)\n    if err != nil { return fmt.Errorf(\"config file unreachable: %w\", err) }\n    if info.IsDir() { return fmt.Errorf(\"config file is a directory: %s\", f) }\n    if info.Mode().Perm()&0400 == 0 { return fmt.Errorf(\"config file not readable: %s\", f) }\n}","typeGuard":null,"tryCatchPattern":"if err := observability.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"error reading observability configuration file\") {\n        log.Fatalf(\"mount/permission problem for GRPC_GCP_OBSERVABILITY_CONFIG_FILE: %v\", err)\n    }\n    log.Fatalf(\"observability: %v\", err)\n}","preventionTips":["Use an absolute path for the config file env var.","In Kubernetes, set the container startAfter the ConfigMap/Secret mount.","chmod 644 the file or chown to the runtime uid."],"tags":["observability","config","filesystem","env"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}