{"record":{"id":"da43aacb58a0a37a","repo":"grpc/grpc-go","slug":"failed-to-create-cloudloggingexporter-v","errorCode":null,"errorMessage":"failed to create cloudLoggingExporter: %v","messagePattern":"failed to create cloudLoggingExporter: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/exporting.go","lineNumber":67,"sourceCode":"// In future, we might expose this to allow users provide custom exporters. But\n// now, it exists for testing purposes.\ntype loggingExporter interface {\n\t// EmitGrpcLogRecord writes a gRPC LogRecord to cache without blocking.\n\tEmitGcpLoggingEntry(entry gcplogging.Entry)\n\t// Close flushes all pending data and closes the exporter.\n\tClose() error\n}\n\ntype cloudLoggingExporter struct {\n\tprojectID string\n\tclient    *gcplogging.Client\n\tlogger    *gcplogging.Logger\n}\n\nfunc newCloudLoggingExporter(ctx context.Context, config *config) (loggingExporter, error) {\n\tc, err := gcplogging.NewClient(ctx, fmt.Sprintf(\"projects/%v\", config.ProjectID), cOptsDisableLogTrace...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create cloudLoggingExporter: %v\", err)\n\t}\n\tdefer logger.Infof(\"Successfully created cloudLoggingExporter\")\n\tif len(config.Labels) != 0 {\n\t\tlogger.Infof(\"Adding labels: %+v\", config.Labels)\n\t}\n\treturn &cloudLoggingExporter{\n\t\tprojectID: config.ProjectID,\n\t\tclient:    c,\n\t\tlogger:    c.Logger(\"microservices.googleapis.com/observability/grpc\", gcplogging.CommonLabels(config.Labels), gcplogging.BufferedByteLimit(1024*1024*50), gcplogging.DelayThreshold(time.Second*10)),\n\t}, nil\n}\n\nfunc (cle *cloudLoggingExporter) EmitGcpLoggingEntry(entry gcplogging.Entry) {\n\tcle.logger.Log(entry)\n\tif logger.V(2) {\n\t\tlogger.Infof(\"Uploading event to CloudLogging: %+v\", entry)\n\t}\n}","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/gcp/observability/exporting.go#L49-L85","documentation":"newCloudLoggingExporter could not construct the Cloud Logging client. The underlying cause comes from gcplogging.NewClient, which dials logging.googleapis.com using Application Default Credentials; the wrapped %v carries the real error. Emitted at exporting.go:67.","triggerScenarios":"No/bad Application Default Credentials, network blocked to logging.googleapis.com, an invalid project id (e.g. projects/<bad>), missing cloud-platform scope on the instance SA, quota/API disabled, or a context cancellation during dial.","commonSituations":"Local run without `gcloud auth application-default login`; SA key rotated but GOOGLE_APPLICATION_CREDENTIALS still pointing at old file; project id with uppercase or invalid chars; Cloud Logging API disabled in the target project; egress firewall/proxy blocking googleapis.com; test/stage environment without metadata access.","solutions":["Run `gcloud auth application-default login` (or set GOOGLE_APPLICATION_CREDENTIALS to a valid SA key JSON) and retry.","Check the inner error: '403' -> enable Cloud Logging API and grant roles/logging.logWriter; 'dial tcp' -> network/proxy problem.","Verify config.ProjectID is a valid, lowercase GCP project id where Cloud Logging is enabled.","If running on GCE/GKE/Cloud Run, confirm the node SA has logging.write scope and the metadata server is reachable.","Pass a context with a longer timeout if the failure is a deadline exceeded during dial."],"exampleFix":"// before: ADC missing\n$ ./svc\nfailed to create cloudLoggingExporter: google: could not find default credentials\n\n// after\n$ gcloud auth application-default login\n$ export GOOGLE_CLOUD_PROJECT=my-proj\n$ ./svc","handlingStrategy":"try-catch","validationCode":"// Pre-flight: can we reach Cloud Logging with current ADC?\nfunc canCreateLoggingClient(ctx context.Context, project string) error {\n    c, err := gcplogging.NewClient(ctx, \"projects/\"+project)\n    if err != nil { return err }\n    return c.Close()\n}\n\nif err := canCreateLoggingClient(ctx, projectID); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := observability.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to create cloudLoggingExporter\") {\n        // most likely ADC / network / API; do not retry in-process, fix env and restart\n        log.Fatalf(\"Cloud Logging exporter unavailable (check ADC, project, API, network): %v\", err)\n    }\n    return err\n}","preventionTips":["Run `gcloud auth application-default login` in dev; pin a SA key in CI.","Enable Cloud Logging API and grant roles/logging.logWriter before first deploy.","Verify egress to logging.googleapis.com from your network."],"tags":["observability","cloud-logging","gcp","credentials"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}