grpc/grpc-go · error
failed to create cloudLoggingExporter
Error message
failed to create cloudLoggingExporter: %v
What it means
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.
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.
Example fix
// before: ADC missing $ ./svc failed to create cloudLoggingExporter: google: could not find default credentials // after $ gcloud auth application-default login $ export GOOGLE_CLOUD_PROJECT=my-proj $ ./svc
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: can we reach Cloud Logging with current ADC?
func canCreateLoggingClient(ctx context.Context, project string) error {
c, err := gcplogging.NewClient(ctx, "projects/"+project)
if err != nil { return err }
return c.Close()
}
if err := canCreateLoggingClient(ctx, projectID); err != nil { return err } Try / catch
if err := observability.Start(ctx); err != nil {
if strings.Contains(err.Error(), "failed to create cloudLoggingExporter") {
// most likely ADC / network / API; do not retry in-process, fix env and restart
log.Fatalf("Cloud Logging exporter unavailable (check ADC, project, API, network): %v", err)
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to start logging
- unable to create CloudLogging exporter
- credentials: audience cannot be empty
- credentials: ctx cannot be nil
- credentials: failed to create ID token credentials
AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11).
Data as JSON: /api/errors/da43aacb58a0a37a.
Report an issue: GitHub.
Appendix: source
Thrown at gcp/observability/exporting.go:67
// In future, we might expose this to allow users provide custom exporters. But
// now, it exists for testing purposes.
type loggingExporter interface {
// EmitGrpcLogRecord writes a gRPC LogRecord to cache without blocking.
EmitGcpLoggingEntry(entry gcplogging.Entry)
// Close flushes all pending data and closes the exporter.
Close() error
}
type cloudLoggingExporter struct {
projectID string
client *gcplogging.Client
logger *gcplogging.Logger
}
func newCloudLoggingExporter(ctx context.Context, config *config) (loggingExporter, error) {
c, err := gcplogging.NewClient(ctx, fmt.Sprintf("projects/%v", config.ProjectID), cOptsDisableLogTrace...)
if err != nil {
return nil, fmt.Errorf("failed to create cloudLoggingExporter: %v", err)
}
defer logger.Infof("Successfully created cloudLoggingExporter")
if len(config.Labels) != 0 {
logger.Infof("Adding labels: %+v", config.Labels)
}
return &cloudLoggingExporter{
projectID: config.ProjectID,
client: c,
logger: c.Logger("microservices.googleapis.com/observability/grpc", gcplogging.CommonLabels(config.Labels), gcplogging.BufferedByteLimit(1024*1024*50), gcplogging.DelayThreshold(time.Second*10)),
}, nil
}
func (cle *cloudLoggingExporter) EmitGcpLoggingEntry(entry gcplogging.Entry) {
cle.logger.Log(entry)
if logger.V(2) {
logger.Infof("Uploading event to CloudLogging: %+v", entry)
}
}View on GitHub (pinned to 0c51461d27)