grpc/grpc-go · error

failed to create cloudLoggingExporter: %v

Error message

failed to create cloudLoggingExporter: %v

What it means

newCloudLoggingExporter calls cloud.google.com/go/logging.NewClient(ctx, "projects/<ProjectID>", ...) to create the underlying Cloud Logging client; if that returns an error (auth, dial, bad project id, option misconfiguration) the exporter construction fails and the error is wrapped as "failed to create cloudLoggingExporter: %v".

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 03255a9237)

Solutions

  1. Verify ADC: `gcloud auth application-default print-access-token` succeeds and has logging.write scope.
  2. Confirm the project id is real and that the SA has Roles/Logging Writer (or equivalent).
  3. Check network egress to logging.googleapis.com:443 is allowed (proxy, firewall, NAT).
  4. Inspect the wrapped %v which usually says 'google: could not find default credentials' or a dial error.

Example fix

// before
// running with no ADC and GOOGLE_CLOUD_PROJECT set to a fake id

// after
export GOOGLE_CLOUD_PROJECT=real-project
export GOOGLE_APPLICATION_CREDENTIALS=/svc/sa.json
# `gcloud auth application-default login` for local dev
Defensive patterns

Strategy: try-catch

Validate before calling

func canCreateLoggingClient(ctx context.Context, project string) error {
    c, err := gcplogging.NewClient(ctx, "projects/"+project)
    if err != nil { return err }
    return c.Close()
}

Try / catch

le, err := newCloudLoggingExporter(ctx, cfg)
if err != nil { return fmt.Errorf("cloud logging exporter: %w", err) }
defer le.Close()

Prevention

When it happens

Trigger: Missing or invalid Application Default Credentials; GOOGLE_CLOUD_PROJECT / project_id not a real GCP project; network egress to logging.googleapis.com blocked; passing cOptsDisableLogTrace options that conflict with the environment.

Common situations: Workload has ADC scoped without https://www.googleapis.com/auth/logging.write; running in an air-gapped or network-restricted environment; project id typo after fixing 217; expired service-account token.

Related errors


AI-assisted analysis of grpc/grpc-go@03255a9237 (2026-08-07). Data as JSON: /api/errors/da43aacb58a0a37a. Report an issue: GitHub.