Skip to content

[pkg/ottl] Add the When OTTL converter#49356

Open
edmocosta wants to merge 7 commits into
open-telemetry:mainfrom
edmocosta:add-when-function
Open

[pkg/ottl] Add the When OTTL converter#49356
edmocosta wants to merge 7 commits into
open-telemetry:mainfrom
edmocosta:add-when-function

Conversation

@edmocosta

Copy link
Copy Markdown
Contributor

Description

Added the When OTTL converter for selecting a value based on a lambda condition.
This function takes no arguments, and is meant to be used as a helper-function to supply ternary operator-like support to other lambda function or value operation that requires evaluating a condition, so it's more flexible and does not require multiple statements for reaching the same results, a few examples:

set(log.attributes["env"], When(
  () => resource.attributes["deployment.environment"] == "prod",
  "production",
  "non-production"
)) where resource.attributes["service.name"] == "foo"
set(log.attributes["exported"], When(
  () => IsMap(log.body),
  Filter(log.attributes, (k, _) => HasPrefix(k, "http.")),
  log.body
)) where resource.attributes["service.name"] == "foo"
set(log.attributes["tier"], When(
  () => Any(log.attributes["tags"], (_, v) => v == "admin"),
  "privileged",
  "standard"
))

Testing

Unit and E2E

Documentation

Updated README.md

Authorship

  • I, a human, wrote this pull request description myself.

@edmocosta edmocosta marked this pull request as ready for review June 29, 2026 14:29
Comment thread pkg/ottl/e2e/e2e_test.go Outdated
edmocosta and others added 2 commits June 30, 2026 17:55
Co-authored-by: Israel Blancas <iblancasa@gmail.com>
@edmocosta

Copy link
Copy Markdown
Contributor Author

Please do not merge it yet, we need to adapt it to #49421 (breaking change) first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants