grpc/grpc-go · warning

conflicting method rules for method %v found

Error message

conflicting method rules for method %v found

What it means

Returned by logger.setMethodMethodLogger when the method is already in l.config.Methods (binarylog.go:142-143). Two method-level logging rules exist for the same 'service/method' in the config string. The library does not support overriding; it treats duplicate method entries as conflicts.

Source

Thrown at internal/binarylog/binarylog.go:143

	if _, ok := l.config.Services[service]; ok {
		return fmt.Errorf("conflicting service rules for service %v found", service)
	}
	if l.config.Services == nil {
		l.config.Services = make(map[string]*MethodLoggerConfig)
	}
	l.config.Services[service] = ml
	return nil
}

// Set method logger for "service/method".
//
// New MethodLogger with same method overrides the old one.
func (l *logger) setMethodMethodLogger(method string, ml *MethodLoggerConfig) error {
	if _, ok := l.config.Blacklist[method]; ok {
		return fmt.Errorf("conflicting blacklist rules for method %v found", method)
	}
	if _, ok := l.config.Methods[method]; ok {
		return fmt.Errorf("conflicting method rules for method %v found", method)
	}
	if l.config.Methods == nil {
		l.config.Methods = make(map[string]*MethodLoggerConfig)
	}
	l.config.Methods[method] = ml
	return nil
}

// Set blacklist method for "-service/method".
func (l *logger) setBlacklist(method string) error {
	if _, ok := l.config.Blacklist[method]; ok {
		return fmt.Errorf("conflicting blacklist rules for method %v found", method)
	}
	if _, ok := l.config.Methods[method]; ok {
		return fmt.Errorf("conflicting method rules for method %v found", method)
	}
	if l.config.Blacklist == nil {
		l.config.Blacklist = make(map[string]struct{})

View on GitHub (pinned to 0c51461d27)

Solutions

  1. Remove the duplicate method entry from the config string
  2. Keep only one config per method with the desired header/message settings
  3. Deduplicate method entries before setting the env var

Example fix

# before (duplicate method rule)
export GRPC_BINARY_LOG_FILTER="Foo/Bar{m:256},Foo/Bar{m:512}"

# after (single rule)
export GRPC_BINARY_LOG_FILTER="Foo/Bar{m:512}"
Defensive patterns

Strategy: validation

Validate before calling

// Validate for duplicate method rules
func validateBinaryLogConfig(s string) error {
    if s == "" {
        return nil
    }
    seen := map[string]bool{}
    for _, part := range strings.Split(s, ",") {
        part = strings.TrimSpace(part)
        if strings.HasPrefix(part, "-") || strings.HasPrefix(part, "*") {
            continue
        }
        if brace := strings.Index(part, "{"); brace >= 0 {
            part = part[:brace]
        }
        if idx := strings.Index(part, "/"); idx >= 0 {
            method := part[idx+1:]
            if method != "*" {
                if seen[part] {
                    return fmt.Errorf("duplicate method rule for %q", part)
                }
                seen[part] = true
            }
        }
    }
    return nil
}

Prevention

When it happens

Trigger: A config string with two entries for the same method, e.g., 'Foo/Bar{m:256},Foo/Bar{m:512}'. The first sets l.config.Methods["Foo/Bar"], the second finds it already present and errors.

Common situations: Duplicate method entries when manually composing the filter string. Intending to update a method's settings but the old entry was not removed.

Related errors


AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11). Data as JSON: /api/errors/38ecb62ac5d3fb9e. Report an issue: GitHub.