Skip to content

Commit

Permalink
fix: put better names to yaml fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 committed Nov 24, 2024
1 parent 0b2a301 commit bf2122b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions collector/processors/odigosconditionalattributes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,35 @@ 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
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"
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions collector/processors/odigosconditionalattributes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
12 changes: 6 additions & 6 deletions collector/processors/odigosconditionalattributes/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit bf2122b

Please sign in to comment.