Ensure configuration options that are mutually exclusive are properly validated with clear, actionable error messages. When introducing configuration fields that cannot be used together, implement validation logic that checks for conflicts and provides specific guidance to users.
Ensure configuration options that are mutually exclusive are properly validated with clear, actionable error messages. When introducing configuration fields that cannot be used together, implement validation logic that checks for conflicts and provides specific guidance to users.
Key practices:
Example implementation:
func (c *OTLPConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// ... unmarshaling logic ...
if c.PromoteAllResourceAttributes {
if len(c.PromoteResourceAttributes) > 0 {
return errors.New("'promote_all_resource_attributes' and 'promote_resource_attributes' cannot be configured simultaneously")
}
if err := validateAttributes(c.IgnoreResourceAttributes); err != nil {
return fmt.Errorf("invalid 'ignore_resource_attributes': %w", err)
}
} else {
if len(c.IgnoreResourceAttributes) > 0 {
return errors.New("'ignore_resource_attributes' cannot be configured unless 'promote_all_resource_attributes' is true")
}
}
return nil
}
This approach prevents configuration errors from causing runtime failures and helps users understand the correct configuration patterns.
Enter the URL of a public GitHub repository