Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcinsiennicki95 opened this issue Dec 3, 2024 · 5 comments · May be fixed by #36719
Open

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

marcinsiennicki95 opened this issue Dec 3, 2024 · 5 comments · May be fixed by #36719
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed pkg/ottl priority:p2 Medium

Comments

@marcinsiennicki95
Copy link

marcinsiennicki95 commented Dec 3, 2024

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

@marcinsiennicki95 marcinsiennicki95 added enhancement New feature or request needs triage New item requiring triage labels Dec 3, 2024
@github-actions github-actions bot added the processor/transform Transform processor label Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth TylerHelmuth changed the title [processor/transform] feat: Add possibility to create new kvp based on other attribute value [pkg/ottl] Allow indexing maps and slices with dynamic values Dec 4, 2024
@TylerHelmuth TylerHelmuth added help wanted Extra attention is needed priority:p2 Medium pkg/ottl and removed processor/transform Transform processor needs triage New item requiring triage labels Dec 4, 2024
Copy link
Contributor

github-actions bot commented Dec 4, 2024

Pinging code owners for pkg/ottl: @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley. See Adding Labels via Comments if you do not have permissions to add labels yourself. For example, comment '/label priority:p2 -needs-triaged' to set the priority and remove the needs-triaged label.

@TylerHelmuth
Copy link
Member

Dynamic indexing in OTTL is definitely a language feature we’d like.

@odubajDT
Copy link
Contributor

odubajDT commented Dec 5, 2024

I would like to take a look at this if possible

@odubajDT
Copy link
Contributor

Hello! The PR should be ready, please have a look #36719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed pkg/ottl priority:p2 Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants