diff --git a/collector/processors/odigosconditionalattributes/README.md b/collector/processors/odigosconditionalattributes/README.md index da47801ade..1dbe945f77 100644 --- a/collector/processors/odigosconditionalattributes/README.md +++ b/collector/processors/odigosconditionalattributes/README.md @@ -25,27 +25,27 @@ This processor is ideal for enriching spans with categorized or contextual infor | Field | Description | Required | |----------------------|---------------------------------------------------------------------------|----------| -| `attribute_to_check` | The attribute in the span to evaluate. | Yes | -| `new_attribute_value_configurations` | A map of potential values to a list of actions to execute when `attribute_to_check` equals value. | Yes | +| `field_to_check` | The attribute in the span to evaluate. | Yes | +| `new_attribute_value_configurations` | A map of potential values to a list of actions to execute when `field_to_check` equals value. | Yes | ## Value Map Options -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. +Each key in the `new_attribute_value_configurations` map corresponds to a potential value of `field_to_check`. The associated value is a list of `NewAttributeValueConfiguration` objects, each specifying how to process the span. | Field | Description | Required | |-------------------|----------------------------------------------------------------------------|----------| | `new_attribute` | The name of the new attribute to add to the span. | Yes | | `value` | A static string value to assign to the `new_attribute`. | No | -| `from_attribute` | The attribute whose value will be copied to the `new_attribute`. | No | +| `from_field` | The field [attribute/instrumentation_scope.name] whose value will be copied to the `new_attribute`. | No | # How It Works -1. The processor checks the value of `attribute_to_check` for each span. +1. The processor checks the value of `field_to_check` for each span. 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 some of the rule. + - Copies a value from another field (`from_field`) to the `new_attribute`. +4. If no match is found, the global_default value will be assigned to all new_attributes defined across any of the rules. # Example Configuration ```yaml @@ -53,7 +53,7 @@ processors: odigosconditionalattributes: global_default: "Unknown" rules: - - attribute_to_check: "instrumentation_scope.name" + - field_to_check: "instrumentation_scope.name" new_attribute_value_configurations: "opentelemetry.instrumentation.flask": - new_attribute: "odigos.category" @@ -65,11 +65,11 @@ processors: value: "tomcat" - new_attribute: "odigos.sub_category" value: "baz" - - attribute_to_check: "net.host.name" + - field_to_check: "net.host.name" new_attribute_value_configurations: "coupon": - new_attribute: "odigos.sub_category" - from_attribute: "http.scheme" + from_field: "http.scheme" ``` # Outputs diff --git a/collector/processors/odigosconditionalattributes/config.go b/collector/processors/odigosconditionalattributes/config.go index e948f9059c..4d80986385 100644 --- a/collector/processors/odigosconditionalattributes/config.go +++ b/collector/processors/odigosconditionalattributes/config.go @@ -12,12 +12,12 @@ type Config struct { var _ component.Config = (*Config)(nil) type ConditionalRule struct { - AttributeToCheck string `mapstructure:"field_to_check"` - NewAttributeValueConfigurations map[string][]NewAttributeValueConfiguration `mapstructure:"new_field_value_configurations"` + FieldToCheck string `mapstructure:"field_to_check"` + NewAttributeValueConfigurations map[string][]NewAttributeValueConfiguration `mapstructure:"new_attribute_value_configurations"` } type NewAttributeValueConfiguration struct { Value string `mapstructure:"value"` - FromAttribute string `mapstructure:"from_field,omitempty"` - NewAttributeName string `mapstructure:"new_field,omitempty"` + FromField string `mapstructure:"from_field,omitempty"` + NewAttributeName string `mapstructure:"new_attribute,omitempty"` } diff --git a/collector/processors/odigosconditionalattributes/processor.go b/collector/processors/odigosconditionalattributes/processor.go index dfb467ade3..637e66c05e 100644 --- a/collector/processors/odigosconditionalattributes/processor.go +++ b/collector/processors/odigosconditionalattributes/processor.go @@ -51,7 +51,7 @@ func (p *conditionalAttributesProcessor) addAttributes(spanAttributes pcommon.Ma scopeName string, scopeAttributes pcommon.Map, resourceAttributes pcommon.Map) { // Handle cases where rule checks for scope_name ['instrumentation_scope.name']. - if rule.AttributeToCheck == OTTLScopeNameKey { + if rule.FieldToCheck == OTTLScopeNameKey { p.handleScopeNameConditionalAttribute(spanAttributes, rule, scopeName) return } @@ -60,7 +60,7 @@ func (p *conditionalAttributesProcessor) addAttributes(spanAttributes pcommon.Ma attributeSets := []pcommon.Map{spanAttributes, scopeAttributes, resourceAttributes} for _, attrs := range attributeSets { - if attrValue, ok := attrs.Get(rule.AttributeToCheck); ok { + if attrValue, ok := attrs.Get(rule.FieldToCheck); ok { attrStr = attrValue.AsString() break } @@ -79,8 +79,8 @@ func (p *conditionalAttributesProcessor) addAttributes(spanAttributes pcommon.Ma } 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 { + } else if configAction.FromField != "" { // Copy a value from another attribute if specified. + if fromAttrValue, ok := spanAttributes.Get(configAction.FromField); ok { if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) } else if _, exists := scopeAttributes.Get(configAction.NewAttributeName); !exists { @@ -108,9 +108,9 @@ func (p *conditionalAttributesProcessor) handleScopeNameConditionalAttribute( if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { spanAttributes.PutStr(configAction.NewAttributeName, configAction.Value) } - } else if configAction.FromAttribute != "" { + } else if configAction.FromField != "" { // Copy value from another attribute if defined - if fromAttrValue, ok := spanAttributes.Get(configAction.FromAttribute); ok { + if fromAttrValue, ok := spanAttributes.Get(configAction.FromField); ok { if _, exists := spanAttributes.Get(configAction.NewAttributeName); !exists { spanAttributes.PutStr(configAction.NewAttributeName, fromAttrValue.AsString()) }