Skip to content

Improve error when "null" is used instead of "nil" in OTTL: invalid path expression [{null []}] #29871

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
ringerc opened this issue Dec 13, 2023 · 9 comments

Comments

@ringerc
Copy link

ringerc commented Dec 13, 2023

Component(s)

pkg/ottl

Describe the issue you're reporting

When an OTTL expression uses the term null instead of the intended nil, the resulting error is not especially helpful, e.g.:

    Error: processors::transform/afterdiscovery: unable to parse OTTL statement "set(attributes[\"keep\"], resource.attributes[\"keep\"]) where resource.attributes[\"keep\"] != null": invalid path expression [{null []}]

The user should've written != nil but the error could definitely help the user out.

Same would make sense to do for NULL, NUL and nul.

@ringerc ringerc added the needs triage New item requiring triage label Dec 13, 2023
Copy link
Contributor

Pinging code owners:

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

@evan-bradley evan-bradley added enhancement New feature or request priority:p3 Lowest and removed needs triage New item requiring triage labels Dec 14, 2023
@evan-bradley
Copy link
Contributor

I agree that error isn't the best, I would be okay with catching null-variations and printing a message that nudges users in the right direction. At a minimum we should be printing a clearer error message for invalid paths to help explain where the user should look to fix the error.

Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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

@TylerHelmuth
Copy link
Member

It would be a weird case, but technically a context someone creates could use null as a valid path name, so I don't think we want to do any special handling of null as it will exclude that keyword as a valid path. Claiming keywords like nil in the language seems ok, but claiming keywords to exclude them from use feels less good.

We can improve the error message tho - I've opened a PR.

@evan-bradley
Copy link
Contributor

Claiming keywords like nil in the language seems ok, but claiming keywords to exclude them from use feels less good.

In my opinion, the language should own concepts like null values. Having a keyword called nil and a path called null feels like we're entering the realm of null and undefined in JavaScript where the terms start to lose their meaning. Take the following statement for example, which I think would be bad UX if a context ever introduced it:

set(attributes["test"], "value") where null == nil

All that said, I think even just improving the error message is a win here.

@TylerHelmuth
Copy link
Member

I agree that set(attributes["test"], "value") where null == nil is weird, and we'd never introduce null as a path in pkg/ottl/contexts, but I'm not convinced yet we should limit a user's ability to use null as a path in their own custom context should they choose to.

@evan-bradley
Copy link
Contributor

I agree that we should keep OTTL's keywords to a minimum (I would count even catching null as having it as a keyword), but I think the number of cases where the compiler can help new users figure out which term represents null values in OTTL will be dramatically higher than the number of cases where a custom context will want to use null as a path. There's also a handful of other terms that could be used that aren't as common as null value keywords: "empty", "void", "nothing", etc.

I think the best argument I could give is that if we add it before beta, it won't be a breaking change to later remove the excluded synonyms if someone says they want null as a path in their context. Statements in all contexts would still fail parsing, but would just have a different error messages.

@github-actions github-actions bot removed the Stale label Feb 14, 2024
evan-bradley added a commit that referenced this issue Feb 23, 2024
**Description:**
Improve OTTL context error messages when an unknown path is used.

The new error message will look like:

```
Error: invalid configuration: processors::transform: unable to parse OTTL statement "set(attributes[\"test\"], trace_id.hex)": error while parsing arguments for call to "set": invalid argument at position 1: trace_id.hex is not a valid path for the Span context - review https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspan to see all valid paths
```

**Link to tracking Issue:** <Issue number if applicable>

Related to
#29871
Closes
#29922

**Testing:** <Describe what testing was performed and which tests were
added.>

Unit tests

---------

Co-authored-by: Evan Bradley <[email protected]>
XinRanZhAWS pushed a commit to XinRanZhAWS/opentelemetry-collector-contrib that referenced this issue Mar 13, 2024
**Description:**
Improve OTTL context error messages when an unknown path is used.

The new error message will look like:

```
Error: invalid configuration: processors::transform: unable to parse OTTL statement "set(attributes[\"test\"], trace_id.hex)": error while parsing arguments for call to "set": invalid argument at position 1: trace_id.hex is not a valid path for the Span context - review https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl/contexts/ottlspan to see all valid paths
```

**Link to tracking Issue:** <Issue number if applicable>

Related to
open-telemetry#29871
Closes
open-telemetry#29922

**Testing:** <Describe what testing was performed and which tests were
added.>

Unit tests

---------

Co-authored-by: Evan Bradley <[email protected]>
Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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

@github-actions github-actions bot added the Stale label Apr 15, 2024
Copy link
Contributor

This issue has been closed as inactive because it has been stale for 120 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants