Skip to content

Commit

Permalink
fix: name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 committed Nov 24, 2024
1 parent 2e566ce commit 0b2a301
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions collector/processors/odigosconditionalattributes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|-------------------|----------------------------------------------------------------------------|----------|
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions collector/processors/odigosconditionalattributes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
6 changes: 3 additions & 3 deletions collector/processors/odigosconditionalattributes/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions collector/processors/odigosconditionalattributes/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand All @@ -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())
}
}
}
Expand Down

0 comments on commit 0b2a301

Please sign in to comment.