grpc/grpc-go · error

empty destination project ID

Error message

empty destination project ID

What it means

ensureProjectIDInObservabilityConfig requires a destination GCP project to which logs/metrics/traces are exported. The config's project_id is empty and fetchDefaultProjectID also returned empty (no GOOGLE_CLOUD_PROJECT env var and the Application Default Credentials either failed to load or had no project_id). Without a project the exporters cannot be constructed, so initialization aborts.

Source

Thrown at gcp/observability/config.go:148

		}
		content, err := os.ReadFile(f)
		if err != nil {
			return nil, fmt.Errorf("error reading observability configuration file %q: %v", f, err)
		}
		return unmarshalAndVerifyConfig(content)
	} else if envconfig.ObservabilityConfig != "" {
		return unmarshalAndVerifyConfig([]byte(envconfig.ObservabilityConfig))
	}
	// If the ENV var doesn't exist, do nothing
	return nil, nil
}

func ensureProjectIDInObservabilityConfig(ctx context.Context, config *config) error {
	if config.ProjectID == "" {
		// Try to fetch the GCP project id
		projectID := fetchDefaultProjectID(ctx)
		if projectID == "" {
			return fmt.Errorf("empty destination project ID")
		}
		config.ProjectID = projectID
	}
	return nil
}

type clientRPCEvents struct {
	// Methods is a list of strings which can select a group of methods. By
	// default, the list is empty, matching no methods.
	//
	// The value of the method is in the form of <service>/<method>.
	//
	// "*" is accepted as a wildcard for:
	//    1. The method name. If the value is <service>/*, it matches all
	//    methods in the specified service.
	//    2. The whole value of the field which matches any <service>/<method>.
	//    It’s not supported when Exclude is true.
	//    3. The * wildcard cannot be used on the service name independently,

View on GitHub (pinned to 03255a9237)

Solutions

  1. Set the GOOGLE_CLOUD_PROJECT env var to your GCP project ID before starting the process.
  2. Set "project_id" in the observability config JSON directly so the lookup is skipped.
  3. Provide Application Default Credentials whose JSON includes a project_id (gcloud auth application-default login with a SA key that has the project).

Example fix

// before
export GOOGLE_APPLICATION_CREDENTIALS=/svc/sa.json
# (sa.json has no project_id, no GOOGLE_CLOUD_PROJECT)

// after
export GOOGLE_CLOUD_PROJECT=my-gcp-project
export GOOGLE_APPLICATION_CREDENTIALS=/svc/sa.json
Defensive patterns

Strategy: validation

Validate before calling

func ensureProjectID(cfg *config) error {
    if cfg.ProjectID != "" { return nil }
    if os.Getenv("GOOGLE_CLOUD_PROJECT") != "" { return nil }
    return errors.New("no project id: set config.project_id or GOOGLE_CLOUD_PROJECT or provide ADC with a project_id")
}

Try / catch

if err := ensureProjectIDInObservabilityConfig(ctx, cfg); err != nil {
    return fmt.Errorf("observability: %w", err)
}

Prevention

When it happens

Trigger: Running outside GCE/GKE without GOOGLE_CLOUD_PROJECT set and without GOOGLE_APPLICATION_CREDENTIALS pointing to a service-account JSON that contains a project_id; running locally with aADC that lacks project metadata (e.g. external account credentials).

Common situations: Local dev without setting GOOGLE_CLOUD_PROJECT; CI runner that uses a token-based credential without a project; service account key JSON stripped of its project_id field.

Related errors


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