{"record":{"id":"7bf004dbdefd3c4a","repo":"grpc/grpc-go","slug":"cannot-have-a-leading-slash","errorCode":null,"errorMessage":"cannot have a leading slash","messagePattern":"cannot have a leading slash","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gcp/observability/config.go","lineNumber":61,"sourceCode":"\t// Step 2: Check default credential\n\tcredentials, err := google.FindDefaultCredentials(ctx, gcplogging.WriteScope)\n\tif err != nil {\n\t\tlogger.Infof(\"Failed to locate Google Default Credential: %v\", err)\n\t\treturn \"\"\n\t}\n\tif credentials.ProjectID == \"\" {\n\t\tlogger.Infof(\"Failed to find project ID in default credential: %v\", err)\n\t\treturn \"\"\n\t}\n\tlogger.Infof(\"Found project ID from Google Default Credential: %v\", credentials.ProjectID)\n\treturn credentials.ProjectID\n}\n\n// validateMethodString validates whether the string passed in is a valid\n// pattern.\nfunc validateMethodString(method string) error {\n\tif strings.HasPrefix(method, \"/\") {\n\t\treturn errors.New(\"cannot have a leading slash\")\n\t}\n\tserviceMethod := strings.Split(method, \"/\")\n\tif len(serviceMethod) != 2 {\n\t\treturn errors.New(\"/ must come in between service and method, only one /\")\n\t}\n\tif serviceMethod[1] == \"\" {\n\t\treturn errors.New(\"method name must be non empty\")\n\t}\n\tif serviceMethod[0] == \"*\" {\n\t\treturn errors.New(\"cannot have service wildcard * i.e. (*/m)\")\n\t}\n\treturn nil\n}\n\nfunc validateLogEventMethod(methods []string, exclude bool) error {\n\tfor _, method := range methods {\n\t\tif method == \"*\" {\n\t\t\tif exclude {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/gcp/observability/config.go#L43-L79","documentation":"Returned by validateMethodString in the observability package when a method pattern string starts with '/'. Method patterns in the observability config use the form service/method WITHOUT a leading slash (unlike the full gRPC method path which includes one). The leading slash is reserved for the runtime method identifier, not for config patterns.","triggerScenarios":"Setting a method entry in the observability CloudLogging config (clientRPCEvents.methods or serverRPCEvents.methods) to a value like /foo.Bar/Baz instead of foo.Bar/Baz. The config is parsed from GRPC_GCP_OBSERVABILITY_CONFIG env var or the config file.","commonSituations":"Developers copy the method name from gRPC server logs or reflection output (which include the leading /) into the observability config. The inconsistency between the gRPC method path format (/pkg.Svc/Method) and the config pattern format (pkg.Svc/Method) is the root cause.","solutions":["Remove the leading slash from method patterns in the observability config: use foo.Bar/Baz, not /foo.Bar/Baz.","When generating config programmatically, strip the leading / from grpc method full names before inserting them."],"exampleFix":"// before (GRPC_GCP_OBSERVABILITY_CONFIG)\n{\"cloud_logging\":{\"client_rpc_events\":[{\"methods\":[\"/foo.Bar/Baz\"]}]}}\n// after\n{\"cloud_logging\":{\"client_rpc_events\":[{\"methods\":[\"foo.Bar/Baz\"]}]}}","handlingStrategy":"validation","validationCode":"// Strip leading slash before inserting into observability config:\nmethod := strings.TrimPrefix(fullMethodName, \"/\")\nif strings.HasPrefix(method, \"/\") {\n    return fmt.Errorf(\"method pattern must not have a leading slash: %s\", method)\n}","typeGuard":"func isValidMethodPattern(m string) bool {\n    return !strings.HasPrefix(m, \"/\") && strings.Contains(m, \"/\")\n}","tryCatchPattern":null,"preventionTips":["Use service/method format (no leading slash) in observability config.","Strip the leading '/' when converting gRPC method names to config patterns.","Validate config before applying it."],"tags":["go","grpc","observability","config","validation"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}