grpc/grpc-go · error
error parsing observability config: %v
Error message
error parsing observability config: %v
What it means
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).
Source
Thrown at gcp/observability/config.go:114
if err := validateLogEventMethod(clientRPCEvent.Methods, clientRPCEvent.Exclude); err != nil {
return fmt.Errorf("error in clientRPCEvent method: %v", err)
}
}
for _, serverRPCEvent := range config.CloudLogging.ServerRPCEvents {
if err := validateLogEventMethod(serverRPCEvent.Methods, serverRPCEvent.Exclude); err != nil {
return fmt.Errorf("error in serverRPCEvent method: %v", err)
}
}
return nil
}
// unmarshalAndVerifyConfig unmarshals a json string representing an
// observability config into its internal go format, and also verifies the
// configuration's fields for validity.
func unmarshalAndVerifyConfig(rawJSON json.RawMessage) (*config, error) {
var config config
if err := json.Unmarshal(rawJSON, &config); err != nil {
return nil, fmt.Errorf("error parsing observability config: %v", err)
}
if err := validateLoggingEvents(&config); err != nil {
return nil, fmt.Errorf("error parsing observability config: %v", err)
}
if config.CloudTrace != nil && (config.CloudTrace.SamplingRate > 1 || config.CloudTrace.SamplingRate < 0) {
return nil, fmt.Errorf("error parsing observability config: invalid cloud trace sampling rate %v", config.CloudTrace.SamplingRate)
}
logger.Infof("Parsed ObservabilityConfig: %+v", &config)
return &config, nil
}
func parseObservabilityConfig() (*config, error) {
if f := envconfig.ObservabilityConfigFile; f != "" {
if envconfig.ObservabilityConfig != "" {
logger.Warning("Ignoring GRPC_GCP_OBSERVABILITY_CONFIG and using GRPC_GCP_OBSERVABILITY_CONFIG_FILE contents.")
}
content, err := os.ReadFile(f)
if err != nil {View on GitHub (pinned to 03255a9237)
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.
Example fix
// before (env value)
GRPC_GCP_OBSERVABILITY_CONFIG='{ "project_id": "p", "cloud_logging": { "client_rpc_events": [], } }' // trailing comma
// after
GRPC_GCP_OBSERVABILITY_CONFIG='{ "project_id": "p", "cloud_logging": { "client_rpc_events": [] } }' Defensive patterns
Strategy: validation
Validate before calling
func validObservabilityJSON(b []byte) error {
var raw map[string]any
return json.Unmarshal(b, &raw)
} Try / catch
cfg, err := parseObservabilityConfig()
if err != nil { return fmt.Errorf("observability config parse: %w", err) } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error reading observability configuration file %q: %v
- invalid method string: %v, err: %v
- error in clientRPCEvent method: %v
- error in serverRPCEvent method: %v
- error parsing observability config: invalid cloud trace samp
AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07).
Data as JSON: /api/errors/8291c3100b3a8bbf.
Report an issue: GitHub.