{"record":{"id":"4fed3b4d256444a7","repo":"grpc/grpc-go","slug":"failed-to-create-stackdriver-exporter-v","errorCode":null,"errorMessage":"failed to create Stackdriver exporter: %v","messagePattern":"failed to create Stackdriver exporter: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/opencensus.go","lineNumber":105,"sourceCode":"\t// Custom labels completely overwrite any labels generated in the OpenCensus\n\t// library, including their label that uniquely identifies the process.\n\t// Thus, generate a unique process identifier here to uniquely identify\n\t// process for metrics exporting to function correctly.\n\tmetricsLabels := make(map[string]string, len(config.Labels)+1)\n\tfor k, v := range config.Labels {\n\t\tmetricsLabels[k] = v\n\t}\n\tmetricsLabels[\"opencensus_task\"] = generateUniqueProcessIdentifier()\n\texporter, err := stackdriver.NewExporter(stackdriver.Options{\n\t\tProjectID:               config.ProjectID,\n\t\tMonitoredResource:       mr,\n\t\tDefaultMonitoringLabels: labelsToMonitoringLabels(metricsLabels),\n\t\tDefaultTraceAttributes:  labelsToTraceAttributes(config.Labels),\n\t\tMonitoringClientOptions: cOptsDisableLogTrace,\n\t\tTraceClientOptions:      cOptsDisableLogTrace,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Stackdriver exporter: %v\", err)\n\t}\n\treturn exporter, nil\n}\n\n// generateUniqueProcessIdentifier returns a unique process identifier for the\n// process this code is running in. This is the same way the OpenCensus library\n// generates the unique process identifier, in the format of\n// \"go-<pid>@<hostname>\".\nfunc generateUniqueProcessIdentifier() string {\n\thostname, err := os.Hostname()\n\tif err != nil {\n\t\thostname = \"localhost\"\n\t}\n\treturn \"go-\" + strconv.Itoa(os.Getpid()) + \"@\" + hostname\n}\n\n// This method accepts config and exporter; the exporter argument is exposed to\n// assist unit testing of the OpenCensus behavior.","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/grpc/grpc-go/blob/03255a9237b6eb32710f6bc4f2de9a675b99fe36/gcp/observability/opencensus.go#L87-L123","documentation":"Returned by newStackdriverExporter when stackdriver.NewExporter returns a non-nil error. The exporter is the shared trace+metrics sink, so this blocks all OpenCensus instrumentation. The error wraps the underlying Stackdriver cause (auth, quota, options validation, project ID).","triggerScenarios":"Constructing the exporter with an empty or invalid ProjectID, missing Application Default Credentials, an unreachable Stackdriver/Monitoring API, or options that fail client-side validation (e.g. invalid DefaultMonitoringLabels).","commonSituations":"Workstation without ADC; misconfigured project ID; running on GCE/GKE without the cloud-platform scope; Stackdriver API disabled in the project; exceeding metrics custom-label limits.","solutions":["Confirm GOOGLE_APPLICATION_CREDENTIALS points to a valid key file or that a metadata server is reachable.","Verify config.ProjectID matches an enabled Stackdriver/Monitoring project; enable the API with `gcloud services enable monitoring.googleapis.com`.","On GCE/GKE, attach the https://www.googleapis.com/auth/monitoring and .../trace.append scopes.","Reduce or validate custom Labels to stay within Stackdriver label limits."],"exampleFix":"// before\nexporter, err := stackdriver.NewExporter(stackdriver.Options{ProjectID: \"\"})\n// after\nexporter, err := stackdriver.NewExporter(stackdriver.Options{\n    ProjectID: \"my-valid-project\", // plus ADC in env\n})","handlingStrategy":"validation","validationCode":"// Validate project ID and credentials presence before relying on the exporter.\nimport \"cloud.google.com/go/compute/metadata\"\nif project == \"\" && !metadata.OnGCE() {\n    if os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\") == \"\" {\n        return errors.New(\"no ADC: set GOOGLE_APPLICATION_CREDENTIALS or run on GCE\")\n    }\n}","typeGuard":null,"tryCatchPattern":"exporter, err := newStackdriverExporter(config)\nif err != nil {\n    return fmt.Errorf(\"cannot build Stackdriver exporter (check project/ADC): %w\", err)\n}","preventionTips":["Run `gcloud auth application-default login` on developer machines.","Pin a valid, non-empty ProjectID in the observability config.","Enable monitoring.googleapis.com and cloudtrace.googleapis.com in the project."],"tags":["grpc","observability","stackdriver","gcp","authentication","configuration"],"analyzedSha":"03255a9237b6eb32710f6bc4f2de9a675b99fe36","analyzedAt":"2026-08-07T00:29:34.215Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}