{"record":{"id":"57818c140066ef98","repo":"grpc/grpc-go","slug":"failed-to-start-logging-v","errorCode":null,"errorMessage":"failed to start logging: %v","messagePattern":"failed to start logging: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/observability.go","lineNumber":76,"sourceCode":"\tif err = ensureProjectIDInObservabilityConfig(ctx, config); err != nil {\n\t\treturn err\n\t}\n\n\t// Cleanup any created resources this function created in case this function\n\t// errors.\n\tdefer func() {\n\t\tif err != nil {\n\t\t\tEnd()\n\t\t}\n\t}()\n\n\t// Enabling tracing and metrics via OpenCensus\n\tif err = startOpenCensus(config); err != nil {\n\t\treturn fmt.Errorf(\"failed to instrument OpenCensus: %v\", err)\n\t}\n\n\tif err = startLogging(ctx, config); err != nil {\n\t\treturn fmt.Errorf(\"failed to start logging: %v\", err)\n\t}\n\n\t// Logging is controlled by the config at methods level.\n\treturn nil\n}\n\n// End is the clean-up API for gRPC Observability plugin. It is expected to be\n// invoked in the main function of the application. The suggested usage is\n// \"defer observability.End()\". This function also flushes data to upstream, and\n// cleanup resources.\n//\n// Note: this method should only be invoked once.\nfunc End() {\n\tstopLogging()\n\tstopOpenCensus()\n}\n","sourceCodeStart":58,"sourceCodeEnd":93,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/gcp/observability/observability.go#L58-L93","documentation":"A wrapper returned by Start() when startLogging(ctx, config) fails. This is the Cloud Logging subsystem initialization (binary log sink setup). OpenCensus tracing/metrics have already succeeded by this point, but the logging collector could not be installed; Start() rolls back everything via the deferred End().","triggerScenarios":"Enabling cloud_logging in the config while the environment cannot supply a usable Cloud Logging client (missing/invalid credentials, unreachable logging endpoint, bad project). Passing a config whose logging method filters are malformed.","commonSituations":"Local dev machine without GCP credentials but with cloud_logging enabled; restrictive network egress rules blocking logging.googleapis.com; service account missing roles/logging.logWriter.","solutions":["Read the wrapped error to determine whether the failure is auth, network, or config parsing.","Provide valid Application Default Credentials with the Logging Writer role.","If you only need tracing/metrics, disable the cloud_logging section in the config to bypass logging init.","Whitelist the Cloud Logging API endpoint in your firewall/proxy egress rules."],"exampleFix":"// before\nconfig: {\"cloud_logging\":{},\"cloud_trace\":{},\"cloud_monitoring\":{}}\n// after (disable logging if you cannot satisfy its auth/egress requirements)\nconfig: {\"cloud_trace\":{\"sampling_rate\":0.5},\"cloud_monitoring\":{}}","handlingStrategy":"try-catch","validationCode":"// Pre-flight: only enable cloud_logging if a Cloud Logging client can be built.\n// (There is no public pre-check API; gate via config instead.)\nif !loggingEnabled {\n    config.CloudLogging = nil // avoid the failing path entirely\n}","typeGuard":null,"tryCatchPattern":"if err := observability.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to start logging\") {\n        // Retry with cloud_logging disabled so trace/metrics still work.\n        log.Printf(\"disabling cloud_logging due to init failure: %v\", err)\n    }\n}","preventionTips":["Grant the Logging Writer IAM role to the service account used by Start().","Whitelist logging.googleapis.com in egress firewalls.","Disable the cloud_logging section in dev environments that lack GCP credentials."],"tags":["grpc","observability","cloud-logging","gcp","authentication","startup"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}