Skip to content

OTTL context inference order is incorrect for resources & scopes #39155

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
axw opened this issue Apr 4, 2025 · 2 comments · Fixed by #39307
Closed

OTTL context inference order is incorrect for resources & scopes #39155

axw opened this issue Apr 4, 2025 · 2 comments · Fixed by #39307
Assignees
Labels
bug Something isn't working pkg/ottl

Comments

@axw
Copy link
Contributor

axw commented Apr 4, 2025

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

var defaultContextInferPriority = []string{
"log",
"datapoint",
"metric",
"spanevent",
"span",
"resource",
"scope",
"instrumentation_scope",
}

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

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

github-actions bot commented Apr 4, 2025

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 @axw, that's indeed a bug we need to fix.

@edmocosta edmocosta removed the needs triage New item requiring triage label Apr 9, 2025
@edmocosta edmocosta self-assigned this Apr 9, 2025
akshays-19 pushed a commit to akshays-19/opentelemetry-collector-contrib that referenced this issue Apr 23, 2025
… `resource` (open-telemetry#39307)

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

Changed the context inferrer so the `scope` context has priority over
the `resource` context, fixing the error described on the linked issue.

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

<!--Please delete paragraphs that you did not use before submitting.-->
Fiery-Fenix pushed a commit to Fiery-Fenix/opentelemetry-collector-contrib that referenced this issue Apr 24, 2025
… `resource` (open-telemetry#39307)

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

Changed the context inferrer so the `scope` context has priority over
the `resource` context, fixing the error described on the linked issue.

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

<!--Please delete paragraphs that you did not use before submitting.-->
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
2 participants