{"record":{"id":"6a8c8bfe87bfea11","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-cloud-logging-admin-client-for-pr","errorCode":null,"errorMessage":"failed to create Cloud Logging Admin client for project %q: %w","messagePattern":"failed to create Cloud Logging Admin client for project %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudloggingadmin/cloud_logging_admin.go","lineNumber":404,"sourceCode":"\t\t\toption.WithUserAgent(userAgent),\n\t\t\toption.WithTokenSource(cloudPlatformTokenSource),\n\t\t}\n\t} else {\n\t\t// Use default credentials\n\t\tcred, err := google.FindDefaultCredentials(ctx, logging.AdminScope)\n\t\tif err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"failed to find default Google Cloud credentials with scope %q: %w\", logging.AdminScope, err)\n\t\t}\n\t\ttokenSource = cred.TokenSource\n\t\topts = []option.ClientOption{\n\t\t\toption.WithUserAgent(userAgent),\n\t\t\toption.WithCredentials(cred),\n\t\t}\n\t}\n\n\tclient, err := logadmin.NewClient(ctx, project, opts...)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to create Cloud Logging Admin client for project %q: %w\", project, err)\n\t}\n\treturn client, tokenSource, nil\n}\n\nfunc initLogAdminConnectionWithOAuthToken(\n\tctx context.Context,\n\ttracer trace.Tracer,\n\tproject, name, userAgent, tokenString string,\n) (*logadmin.Client, error) {\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\ttoken := &oauth2.Token{\n\t\tAccessToken: string(tokenString),\n\t}\n\tts := oauth2.StaticTokenSource(token)\n\n\t// Initialize the logadmin client with tokenSource","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudloggingadmin/cloud_logging_admin.go#L386-L422","documentation":"This error wraps failures from logadmin.NewClient when creating a Cloud Logging Admin client for a specific GCP project. It is thrown by initLogAdminConnection during source initialization when the underlying Google Cloud Logging client cannot be constructed. The wrapped error (%w) carries the root cause, typically credential, option, or project-ID problems.","triggerScenarios":"Calling Initialize on a cloudloggingadmin source where logadmin.NewClient(ctx, project, opts...) returns an error — e.g. invalid credentials in opts, malformed project ID, or failure building gRPC/REST transport options.","commonSituations":"Missing or invalid Application Default Credentials (GOOGLE_APPLICATION_CREDENTIALS not set, malformed service-account JSON); wrong project ID; network/DNS failure reaching the Logging API; unsupported credential option combination.","solutions":["Check the wrapped %w cause and fix the underlying credential/project issue (usually ADC setup)","Set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account key file or run 'gcloud auth application-default login'","Verify the project ID string is correct and the Logging API (logging.googleapis.com) is enabled","Confirm network/proxy reachability to googleapis.com"],"exampleFix":"// before\nclient, err := logadmin.NewClient(ctx, project) // no creds configured\n// after\nos.Setenv(\"GOOGLE_APPLICATION_CREDENTIALS\", \"/path/to/sa.json\")\nclient, err := logadmin.NewClient(ctx, project, option.WithCredentialsFile(\"/path/to/sa.json\"))","handlingStrategy":"validation","validationCode":"if os.Getenv(\"GOOGLE_APPLICATION_CREDENTIALS\") == \"\" {\n    if _, err := os.Stat(os.Getenv(\"HOME\") + \"/.config/gcloud/application_default_credentials.json\"); err != nil {\n        return fmt.Errorf(\"no ADC available: run 'gcloud auth application-default login'\")\n    }\n}\nif project == \"\" { return fmt.Errorf(\"project ID must not be empty\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var wrapped error\n    if errors.As(err, &wrapped) {\n        log.Printf(\"logadmin client creation failed: %v\", wrapped)\n    }\n    return err\n}","preventionTips":["Validate ADC availability at startup before creating sources","Validate the project ID format (non-empty, lowercase, hyphens)","Enable the Cloud Logging API on the target project","Test connectivity to googleapis.com from the deployment environment"],"tags":["gcp","cloud-logging","authentication","go"],"backgroundTag":"google-default-credentials-not-found","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}