{"record":{"id":"8291c3100b3a8bbf","repo":"grpc/grpc-go","slug":"error-parsing-observability-config-v","errorCode":null,"errorMessage":"error parsing observability config: %v","messagePattern":"error parsing observability config: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/config.go","lineNumber":114,"sourceCode":"\t\tif err := validateLogEventMethod(clientRPCEvent.Methods, clientRPCEvent.Exclude); err != nil {\n\t\t\treturn fmt.Errorf(\"error in clientRPCEvent method: %v\", err)\n\t\t}\n\t}\n\tfor _, serverRPCEvent := range config.CloudLogging.ServerRPCEvents {\n\t\tif err := validateLogEventMethod(serverRPCEvent.Methods, serverRPCEvent.Exclude); err != nil {\n\t\t\treturn fmt.Errorf(\"error in serverRPCEvent method: %v\", err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// unmarshalAndVerifyConfig unmarshals a json string representing an\n// observability config into its internal go format, and also verifies the\n// configuration's fields for validity.\nfunc unmarshalAndVerifyConfig(rawJSON json.RawMessage) (*config, error) {\n\tvar config config\n\tif err := json.Unmarshal(rawJSON, &config); err != nil {\n\t\treturn nil, fmt.Errorf(\"error parsing observability config: %v\", err)\n\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 {","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/gcp/observability/config.go#L96-L132","documentation":"unmarshalAndVerifyConfig could not json.Unmarshal the raw config bytes into the internal config struct. This is a structural JSON error in the observability config supplied via GRPC_GCP_OBSERVABILITY_CONFIG (env) or the file pointed to by GRPC_GCP_OBSERVABILITY_CONFIG_FILE. Distinct from 214 (which is field-validation failure) and 215 (sampling rate).","triggerScenarios":"Malformed JSON: trailing comma, unquoted keys, single quotes, comments, or unknown fields combined with DisallowUnknownFields-style strictness. The error happens before any field validation runs.","commonSituations":"Hand-editing the env var with a typo; YAML mistakenly used in place of JSON; trailing comma from a templating system; an unclosed brace after appending a section.","solutions":["Run the config through `jq -e .` (or `python -m json.tool`) to find the exact syntax error.","Ensure the contents are JSON, not YAML; convert with `yq -o=json` if needed.","Construct the config from a Go struct and json.Marshal it to guarantee validity."],"exampleFix":"// before (env value)\nGRPC_GCP_OBSERVABILITY_CONFIG='{ \"project_id\": \"p\", \"cloud_logging\": { \"client_rpc_events\": [], } }' // trailing comma\n\n// after\nGRPC_GCP_OBSERVABILITY_CONFIG='{ \"project_id\": \"p\", \"cloud_logging\": { \"client_rpc_events\": [] } }'","handlingStrategy":"validation","validationCode":"func validObservabilityJSON(b []byte) error {\n    var raw map[string]any\n    return json.Unmarshal(b, &raw)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := parseObservabilityConfig()\nif err != nil { return fmt.Errorf(\"observability config parse: %w\", err) }","preventionTips":["Lint env/file config with `jq -e .` before deploy.","Use JSON, not YAML, for GRPC_GCP_OBSERVABILITY_CONFIG.","Build config from structs via json.Marshal."],"tags":["grpc","observability","config","json","gcp","env"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}