grpc/grpc-go · error

cannot have exclude and a '*' wildcard

Error message

cannot have exclude and a '*' wildcard

What it means

Returned by validateLogEventMethod (gcp/observability/config.go:80) when a methods entry equals exactly "*" AND the exclude flag on that RPC-events block is true. The "*" wildcard selects all methods; using it with exclude:true would mean 'exclude everything' which is nonsensical for logging, so the config rejects it. The check at line 78 short-circuits: a bare "*" is only valid when exclude is false.

Source

Thrown at gcp/observability/config.go:80

	}
	serviceMethod := strings.Split(method, "/")
	if len(serviceMethod) != 2 {
		return errors.New("/ must come in between service and method, only one /")
	}
	if serviceMethod[1] == "" {
		return errors.New("method name must be non empty")
	}
	if serviceMethod[0] == "*" {
		return errors.New("cannot have service wildcard * i.e. (*/m)")
	}
	return nil
}

func validateLogEventMethod(methods []string, exclude bool) error {
	for _, method := range methods {
		if method == "*" {
			if exclude {
				return errors.New("cannot have exclude and a '*' wildcard")
			}
			continue
		}
		if err := validateMethodString(method); err != nil {
			return fmt.Errorf("invalid method string: %v, err: %v", method, err)
		}
	}
	return nil
}

func validateLoggingEvents(config *config) error {
	if config.CloudLogging == nil {
		return nil
	}
	for _, clientRPCEvent := range config.CloudLogging.ClientRPCEvents {
		if err := validateLogEventMethod(clientRPCEvent.Methods, clientRPCEvent.Exclude); err != nil {
			return fmt.Errorf("error in clientRPCEvent method: %v", err)
		}

View on GitHub (pinned to 03255a9237)

Solutions

  1. Either set exclude:false with "*" (log everything), or keep exclude:true but list specific methods to exclude.
  2. To express 'log everything except a few', use one inclusive block with "*" (exclude:false) and a separate mechanism, or list the methods you want with exclude semantics.
  3. Re-read the config docs: '*' is not allowed when exclude is true.

Example fix

// before
{"client_rpc_events":[{"methods":["*"],"exclude":true}]} // err

// after (log everything)
{"client_rpc_events":[{"methods":["*"]}]}
// or exclude specific methods:
{"client_rpc_events":[{"methods":["foo.Bar/Noisy"],"exclude":true}]}
Defensive patterns

Strategy: validation

Validate before calling

for _, m := range methods {
    if m == "*" && exclude {
        return errors.New("'*' wildcard is not allowed when exclude is true")
    }
}

Try / catch

if _, err := unmarshalAndVerifyConfig(raw); err != nil { log.Fatalf("observability: %v", err) }

Prevention

When it happens

Trigger: An observability config block like {"methods":["*"],"exclude":true} in either client_rpc_events or server_rpc_events. Surfaces during unmarshalAndVerifyConfig while parsing GRPC_GCP_OBSERVABILITY_CONFIG(_FILE).

Common situations: Wanting 'log nothing except X' and incorrectly modeling it as exclude:true with a wildcard; copy-pasting an exclude block and adding a wildcard; misunderstanding that exclude works on the listed method set, not as a global toggle.

Related errors


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