Description
Component(s)
pkg/ottl
What happened?
Description
The OTTL context inference order appears to be incorrect, which leads to the "resource" context being incorrectly picked instead of "scope".
I'm assuming this is due to "resource" coming before "scope" in
opentelemetry-collector-contrib/pkg/ottl/context_inferrer.go
Lines 17 to 26 in b8c2f0b
Steps to Reproduce
Run this in https://ottl.run:
log_statements:
- set(scope.name, "foo") where resource.attributes["foo"] != nil
Expected Result
Should be a no-op on the example input.
Actual Result
Results in an error:
unable to run logs statements. Error: invalid config for "transform" processor unable to parse OTTL statement "set(scope.name, "foo") where resource.attributes["foo"] != nil": error while parsing arguments for call to "set": invalid argument at position 0: context "scope" from path "scope.name" is not valid, it must be replaced by one of: "resource"
Also if you look at the execution logs, you can see that "resource" was inferred where it should have been "scope":
2025-04-04T17:29:13.206+0800 DEBUG [email protected]/context_inferrer.go:85 Inferring context from statements {"candidates": ["resource", "scope", "log"], "priority": {"datapoint":1,"instrumentation_scope":7,"log":0,"metric":2,"resource":5,"scope":6,"span":4,"spanevent":3}, "statements": ["set(scope.name, "foo") where resource.attributes["foo"] != nil"]}
2025-04-04T17:29:13.207+0800 DEBUG [email protected]/context_inferrer.go:147 Validating selected context candidate: "resource"
2025-04-04T17:29:13.207+0800 DEBUG [email protected]/context_inferrer.go:93 Inferred context: "resource"
Collector version
v0.123.0
Environment information
Environment
N/A
OpenTelemetry Collector configuration
Log output
Additional context
No response