diff --git a/collector/processors/odigosconditionalattributes/README.md b/collector/processors/odigosconditionalattributes/README.md index bdeace2912..da47801ade 100644 --- a/collector/processors/odigosconditionalattributes/README.md +++ b/collector/processors/odigosconditionalattributes/README.md @@ -19,18 +19,18 @@ This processor is ideal for enriching spans with categorized or contextual infor | Field | Description | Required | Default | |------------------|-------------------------------------------------|----------|-----------| -| `global_default` | The value assigned when no rules match. | Yes | - | +| `global_default` | The value assigned when no rules match to any value specified in some of the rules. | Yes | - | ## Rule Options | Field | Description | Required | |----------------------|---------------------------------------------------------------------------|----------| | `attribute_to_check` | The attribute in the span to evaluate. | Yes | -| `values` | A map of conditions to a list of actions for processing. | Yes | +| `new_attribute_value_configurations` | A map of potential values to a list of actions to execute when `attribute_to_check` equals value. | Yes | ## Value Map Options -Each key in the `values` map corresponds to a potential value of `attribute_to_check`. The associated value is a list of `Value` objects, each specifying how to process the span. +Each key in the `new_attribute_value_configurations` map corresponds to a potential value of `attribute_to_check`. The associated value is a list of `Value` objects, each specifying how to process the span. | Field | Description | Required | |-------------------|----------------------------------------------------------------------------|----------| @@ -41,11 +41,11 @@ Each key in the `values` map corresponds to a potential value of `attribute_to_c # How It Works 1. The processor checks the value of `attribute_to_check` for each span. -2. It matches the value against the keys in `values`. -3. For each match, it iterates through the list of `Value` objects: +2. It matches the value against the keys in `new_attribute_value_configurations`. +3. For each match, it iterates through the list of `new_attribute_value_configurations` objects: - Assigns a static value (`value`) to the `new_attribute`. - Copies a value from another attribute (`from_attribute`) to the `new_attribute`. -4. If no match is found, assigns the `global_default` to all `new_attribute`s specified by the rule. +4. If no match is found, assigns the `global_default` to all `new_attribute`s specified by some of the rule. # Example Configuration ```yaml @@ -54,7 +54,7 @@ processors: global_default: "Unknown" rules: - attribute_to_check: "instrumentation_scope.name" - values: + new_attribute_value_configurations: "opentelemetry.instrumentation.flask": - new_attribute: "odigos.category" value: "flask" @@ -66,7 +66,7 @@ processors: - new_attribute: "odigos.sub_category" value: "baz" - attribute_to_check: "net.host.name" - values: + new_attribute_value_configurations: "coupon": - new_attribute: "odigos.sub_category" from_attribute: "http.scheme" diff --git a/collector/processors/odigosconditionalattributes/config.go b/collector/processors/odigosconditionalattributes/config.go index 26ec00bdff..e948f9059c 100644 --- a/collector/processors/odigosconditionalattributes/config.go +++ b/collector/processors/odigosconditionalattributes/config.go @@ -6,18 +6,18 @@ import ( type Config struct { Rules []ConditionalRule `mapstructure:"rules,omitempty"` - GlobalDefault string `mapstructure:"global_default,omitempty"` + GlobalDefault string `mapstructure:"global_default"` } var _ component.Config = (*Config)(nil) type ConditionalRule struct { - AttributeToCheck string `mapstructure:"attribute_to_check"` - Values map[string][]Value `mapstructure:"values"` + AttributeToCheck string `mapstructure:"field_to_check"` + NewAttributeValueConfigurations map[string][]NewAttributeValueConfiguration `mapstructure:"new_field_value_configurations"` } -type Value struct { - Value string `mapstructure:"value,omitempty"` - FromAttribute string `mapstructure:"from_attribute,omitempty"` - NewAttribute string `mapstructure:"new_attribute,omitempty"` +type NewAttributeValueConfiguration struct { + Value string `mapstructure:"value"` + FromAttribute string `mapstructure:"from_field,omitempty"` + NewAttributeName string `mapstructure:"new_field,omitempty"` } diff --git a/collector/processors/odigosconditionalattributes/factory.go b/collector/processors/odigosconditionalattributes/factory.go index 4407b97db4..ff2cebf0b4 100644 --- a/collector/processors/odigosconditionalattributes/factory.go +++ b/collector/processors/odigosconditionalattributes/factory.go @@ -44,10 +44,10 @@ func createTracesProcessor( func calculateUniqueNewAttributes(config *Config) map[string]struct{} { uniqueNewAttributes := make(map[string]struct{}) for _, rule := range config.Rules { - for _, value := range rule.Values { + for _, value := range rule.NewAttributeValueConfigurations { for _, v := range value { - if v.NewAttribute != "" { - uniqueNewAttributes[v.NewAttribute] = struct{}{} + if v.NewAttributeName != "" { + uniqueNewAttributes[v.NewAttributeName] = struct{}{} } } } diff --git a/collector/processors/odigosconditionalattributes/processor.go b/collector/processors/odigosconditionalattributes/processor.go index e08499c419..dfb467ade3 100644 --- a/collector/processors/odigosconditionalattributes/processor.go +++ b/collector/processors/odigosconditionalattributes/processor.go @@ -67,26 +67,26 @@ func (p *conditionalAttributesProcessor) addAttributes(spanAttributes pcommon.Ma } // Check if the value matches a configured value in the rule. - if valueConfig, exists := rule.Values[attrStr]; exists { + if valueConfig, exists := rule.NewAttributeValueConfigurations[attrStr]; exists { for _, configAction := range valueConfig { // Add a static value as a new attribute if defined. if configAction.Value != "" { - if _, exists := spanAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, configAction.Value) - } else if _, exists := scopeAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, configAction.Value) - } else if _, exists := resourceAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, configAction.Value) + if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, configAction.Value) + } else if _, exists := scopeAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, configAction.Value) + } else if _, exists := resourceAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, configAction.Value) } } else if configAction.FromAttribute != "" { // Copy a value from another attribute if specified. if fromAttrValue, ok := spanAttributes.Get(configAction.FromAttribute); ok { - if _, exists := spanAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, fromAttrValue.AsString()) - } else if _, exists := scopeAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, fromAttrValue.AsString()) - } else if _, exists := resourceAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, fromAttrValue.AsString()) + if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) + } else if _, exists := scopeAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) + } else if _, exists := resourceAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) } } } @@ -101,18 +101,18 @@ func (p *conditionalAttributesProcessor) handleScopeNameConditionalAttribute( rule ConditionalRule, scopeName string, ) { - if valueConfigActions, exists := rule.Values[scopeName]; exists { + if valueConfigActions, exists := rule.NewAttributeValueConfigurations[scopeName]; exists { for _, configAction := range valueConfigActions { if configAction.Value != "" { // Add static value if not already present - if _, exists := spanAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, configAction.Value) + if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, configAction.Value) } } else if configAction.FromAttribute != "" { // Copy value from another attribute if defined if fromAttrValue, ok := spanAttributes.Get(configAction.FromAttribute); ok { - if _, exists := spanAttributes.Get(configAction.NewAttribute); !exists { - spanAttributes.PutStr(configAction.NewAttribute, fromAttrValue.AsString()) + if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { + spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) } } }