{"record":{"id":"0b0094d49d4f11e0","repo":"GoogleContainerTools/skaffold","slug":"no-project-id-found-in-metrics-credentials","errorCode":null,"errorMessage":"no project id found in metrics credentials","messagePattern":"no project id found in metrics credentials","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/instrumentation/export.go","lineNumber":141,"sourceCode":"\t\treturn os.Remove(filename)\n\t}\n\treturn nil\n}\n\nfunc initCloudMonitoringExporterMetrics() (sdkmetric.Exporter, error) {\n\tb, err := fs.AssetsFS.ReadFile(\"assets/secrets_generated/keys.json\")\n\tif err != nil {\n\t\t// No keys have been set in this version so do not attempt to write metrics\n\t\tif os.IsNotExist(err) {\n\t\t\treturn devStdOutExporter()\n\t\t}\n\t\treturn nil, err\n\t}\n\n\tvar c creds\n\terr = json.Unmarshal(b, &c)\n\tif c.ProjectID == \"\" || err != nil {\n\t\treturn nil, fmt.Errorf(\"no project id found in metrics credentials\")\n\t}\n\n\tformatter := func(desc metricdata.Metrics) string {\n\t\treturn fmt.Sprintf(\"custom.googleapis.com/skaffold/%s\", desc.Name)\n\t}\n\n\totel.SetErrorHandler(errHandler{})\n\treturn mexporter.New(\n\t\tmexporter.WithProjectID(c.ProjectID),\n\t\tmexporter.WithMetricDescriptorTypeFormatter(formatter),\n\t\tmexporter.WithMonitoringClientOptions(option.WithCredentialsJSON(b)))\n}\n\nfunc devStdOutExporter() (sdkmetric.Exporter, error) {\n\t// export metrics to std out if local env is set.\n\tif _, ok := os.LookupEnv(\"SKAFFOLD_EXPORT_TO_STDOUT\"); ok {\n\t\tenc := json.NewEncoder(os.Stdout)\n\t\tenc.SetIndent(\"\", \"  \")","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/instrumentation/export.go#L123-L159","documentation":"initCloudMonitoringExporterMetrics reads Google Cloud application-default credentials from disk and unmarshals them to extract the project ID. If the credentials JSON has no project_id (or is not valid JSON), it fails with \"no project id found in metrics credentials\". The Cloud Monitoring metrics exporter cannot be created without a project to write metrics to.","triggerScenarios":"Metrics export to Cloud Monitoring is enabled but the credentials file (from GOOGLE_APPLICATION_CREDENTIALS or the ADC well-known path) contains no `project_id` field or is malformed.","commonSituations":"Using service-account keys created without a project, truncated/partial credentials files, or pointing GOOGLE_APPLICATION_CREDENTIALS at the wrong JSON.","solutions":["Verify the credentials JSON contains \"project_id\": `cat $GOOGLE_APPLICATION_CREDENTIALS | jq .project_id`.","Re-download or recreate the service account key with `gcloud iam service-accounts keys create`.","Re-run `gcloud auth application-default login` to regenerate valid ADC credentials."],"exampleFix":"// before: credentials missing project_id\n{\"type\": \"service_account\"}\n// after: valid key includes project_id\n{\"type\": \"service_account\", \"project_id\": \"my-project\", ...}","handlingStrategy":"validation","validationCode":"b, err := os.ReadFile(os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\"))\nif err == nil {\n    var c struct{ ProjectID string `json:\"project_id\"` }\n    if json.Unmarshal(b, &c) != nil || c.ProjectID == \"\" {\n        log.Println(\"credentials missing project_id\")\n    }\n}","typeGuard":"func credsHaveProjectID(b []byte) bool {\n    var c struct{ ProjectID string `json:\"project_id\"` }\n    return json.Unmarshal(b, &c) == nil && c.ProjectID != \"\"\n}","tryCatchPattern":"if err := runSkaffold(); err != nil {\n    if strings.Contains(err.Error(), \"no project id found in metrics credentials\") {\n        // refresh ADC or service-account key\n    }\n}","preventionTips":["Validate credentials JSON has project_id before use","Regenerate keys with gcloud instead of hand-editing them","Keep GOOGLE_APPLICATION_CREDENTIALS pointed at a complete service-account key"],"tags":["gcp","credentials","metrics"],"backgroundTag":"missing-credentials-project-id","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}