Skip to content

[pkg/ottl] Allow indexing maps and slices with dynamic values #36644

Closed
@marcinsiennicki95

Description

@marcinsiennicki95

Component(s)

processor/transform

Is your feature request related to a problem? Please describe.

I want to set a new key-value pair attribute using the value of another attribute

Option 1

transform/combine_scope_type_and_scope_value:
  error_mode: ignore
  log_statements:
    - context: log
      statements:
        - 'set(attributes[attributes["scope.type"]], attributes["scope.value"]) where attributes["scope.type"] != nil and attributes["scope.value"] != nil' 

Option 2

transform/combine_scope_type_and_scope_value:
  error_mode: ignore
  log_statements:
    - context: log
      statements:
        - 'set(${attributes["scope.type"]}, attributes["scope.value"]) where attributes["scope.type"] != nil and attributes["scope.value"] != nil'

When I use option 1 got error
2024/12/02 14:53:40 collector server run finished with error: invalid configuration: processors::transform/combine_scope_type_and_scope_value: unable to parse OTTL statement "set(attributes[attributes[\"scope.type\"]], attributes[\"scope.value\"]) where attributes[\"scope.type\"] != nil and attributes[\"scope.value\"] != nil": statement has invalid syntax: 1:15: unexpected token "[" (expected ")" Key*)

Alternative is

  transform:
    error_mode: ignore
    log_transformations:
       - context: log
         condition:
         - attributes["scope.type"] != nil and attributes["scope.value"] != nil'
         statements:
          - set_attributes:
              - key: '${attributes["scope.type"]}'
                value: '${attributes["scope.value"]}'

But I also have error

Error: failed to get config: cannot resolve the configuration: environment variable "scope.value" has invalid name: must match regex ^[a-zA-Z_][a-zA-Z0-9_]*$
2024/12/02 17:42:16 collector server run finished with error: failed to get config: cannot resolve the configuration: environment variable "scope.value" has invalid name: must match regex ^[a-zA-Z_][a-zA-Z0-9_]*$

The final effect should be
scope.type = enviroment
scope.value = dev

And addition new key-value which will be combination of scope.type and scope.value
enviroment = dev

Describe the solution you'd like

See up

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions