Skip to content

OTTL context inference is incorrect when conditions used with statement #39455

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

Closed
hisarbalik opened this issue Apr 16, 2025 · 4 comments · Fixed by #39463
Closed

OTTL context inference is incorrect when conditions used with statement #39455

hisarbalik opened this issue Apr 16, 2025 · 4 comments · Fixed by #39463
Assignees
Labels
bug Something isn't working pkg/ottl

Comments

@hisarbalik
Copy link

Component(s)

pkg/ottl

What happened?

Description

The OTTL context inference does not work when the statement is combined with conditions.

Steps to Reproduce

Run the following example in https://ottl.run :

metric_statements:
- statements:
  - set(resource.attributes["foo"], "bar")
  conditions:
  - IsMatch(metric.name, "^bar.*")
  - IsMatch(metric.name, "^foo.*")

The example above works when I add a where clause to the statement as a workaround

metric_statements:
- statements:
  - set(resource.attributes["foo"], "bar") where metric.name != nil
  conditions:
  - IsMatch(metric.name, "^bar.*")
  - IsMatch(metric.name, "^foo.*")

Expected Result

Should be no-op for the given example

Actual Result

unable to run metrics statements. Error: invalid config for "transform" processor unable to parse OTTL condition "IsMatch(name, \"^bar.*\")": error while parsing arguments for call to "IsMatch": invalid argument at position 0: missing context name for path "name", possibly valid options are: "resource.name" unable to parse OTTL condition "IsMatch(name, \"^foo.*\")": error while parsing arguments for call to "IsMatch": invalid argument at position 0: missing context name for path "name", possibly valid options are: "resource.name"

Collector version

v0.124.0

Environment information

No response

OpenTelemetry Collector configuration

Log output

Additional context

No response

@hisarbalik hisarbalik added bug Something isn't working needs triage New item requiring triage labels Apr 16, 2025
Copy link
Contributor

Pinging code owners:

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

@edmocosta
Copy link
Contributor

Thanks for reporting @hisarbalik, that is indeed a bug we need to fix. Context-inferred advanced configurations are not taking into consideration the global conditions, and it might infer the wrong context depending on the statements & conditions used.
For now, as an alternative, you can explicitly set the context value as following:

metric_statements:
- context: metric
  statements:
  - set(resource.attributes["foo"], "bar")
  conditions:
  - IsMatch(metric.name, "^bar.*")
  - IsMatch(metric.name, "^foo.*")

@edmocosta edmocosta self-assigned this Apr 16, 2025
@edmocosta edmocosta removed the needs triage New item requiring triage label Apr 16, 2025
@odubajDT
Copy link
Contributor

I can take a look at this

@edmocosta
Copy link
Contributor

I can take a look at this

Hi @odubajDT, I'm working on this issue already. Thank you very much for volunteering :)

TylerHelmuth pushed a commit that referenced this issue Apr 17, 2025
…ntext inferrer conditions (#39465)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Added a new option `ottl.WithContextInferenceConditions` to the
`ParserCollection.ParseStataments` so API users can provide extra
context inferrer's conditions and have theirs hints considered by the
default context inferrer.

Follow up:
#39463
(includes this PR changes)

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Relates to
#39455

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Unit tests
akshays-19 pushed a commit to akshays-19/opentelemetry-collector-contrib that referenced this issue Apr 23, 2025
…ntext inferrer conditions (open-telemetry#39465)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Added a new option `ottl.WithContextInferenceConditions` to the
`ParserCollection.ParseStataments` so API users can provide extra
context inferrer's conditions and have theirs hints considered by the
default context inferrer.

Follow up:
open-telemetry#39463
(includes this PR changes)

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Relates to
open-telemetry#39455

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Unit tests
Fiery-Fenix pushed a commit to Fiery-Fenix/opentelemetry-collector-contrib that referenced this issue Apr 24, 2025
…ntext inferrer conditions (open-telemetry#39465)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Added a new option `ottl.WithContextInferenceConditions` to the
`ParserCollection.ParseStataments` so API users can provide extra
context inferrer's conditions and have theirs hints considered by the
default context inferrer.

Follow up:
open-telemetry#39463
(includes this PR changes)

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Relates to
open-telemetry#39455

<!--Describe what testing was performed and which tests were added.-->
#### Testing
Unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg/ottl
Projects
None yet
3 participants