Skip to content

[pkg/ottl] Support string to boolean conversion. #44770

@danelson

Description

@danelson

Component(s)

pkg/ottl

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

Original discussion in https://cloud-native.slack.com/archives/C01N6P7KR6W/p1764961932853649.

I would like to be able to convert some boolean like strings to booleans. Something that improves the following

transform/string_to_boolean:
  log_statements:
    - statements:
      - set(log.attributes["my.attribute"], true) where ToLowerCase(log.attributes["my.attribute"]) == "true"
      - set(log.attributes["my.attribute"], false) where ToLowerCase(log.attributes["my.attribute"]) == "false"

Describe the solution you'd like

A function such as ParseBool which takes inspiration from ParseInt. It could work on non string objects as well. The syntax could look like

transform/boolean:
  log_statements:
    - statements:
      - set(log.attributes(["my.attribute"]), ParseBool(log.attributes["my.attribute"])

for my string specific case I would expect something like

transform/boolean:
  log_statements:
    - statements:
      - set(log.attributes(["my.attribute"]), ParseBool(log.attributes["my.attribute"]) where IsString(log.attributes["my.attribute"])

Describe alternatives you've considered

No response

Additional context

If this is something the maintainers feel like supporting I can contribute a PR

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions