Skip to content

Make pcommon value comparable - #49214

Merged
TylerHelmuth merged 13 commits into
open-telemetry:mainfrom
alexcams:make-pcommon-Value-comparable
Aug 5, 2026
Merged

Make pcommon value comparable#49214
TylerHelmuth merged 13 commits into
open-telemetry:mainfrom
alexcams:make-pcommon-Value-comparable

Conversation

@alexcams

Copy link
Copy Markdown
Contributor

Description

Adds support for comparing pcommon.Value in the OTTL ValueComparator. Previously, pcommon.Value was not handled, comparisons involving attribute values (which are pcommon.Value at runtime) would fall through to Go's == operator, failing for inequality operators (<, <=, >=, >).

  • comparePValues(a, b pcommon.Value) handles Value-vs-Value with a same-type fast path (typed accessors, zero allocations)
  • comparePValue(a pcommon.Value, b any) handles Value-vs-raw-type by extracting the typed value and delegating to existing compareXXX functions
  • Swap pre-check in compare() — when b is a pcommon.Value but a is not, swaps operands with reverseOp so all unwrapping lives in one place

OTTL expressions like attributes["status_code"] > 200 or attributes["a"] >= attributes["b"] now work correctly with all comparison operators on all value types (int, float, string, bool, bytes, map, slice, empty).

Link to tracking issue

Resolves #49170

Testing

Added propper test cases covering many different scenarios.

Documentation

Documentation added to this PR at LANGUAGE.md file.

@alexcams

Copy link
Copy Markdown
Contributor Author

/rerun

@edmocosta edmocosta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @alexcams!

Comment thread pkg/ottl/compare.go Outdated
Comment thread pkg/ottl/compare.go Outdated
Comment thread pkg/ottl/LANGUAGE.md Outdated
@alexcams

alexcams commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@edmocosta I've addressed all comments abobe. Thanks for the review :)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Jul 13, 2026

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-08-05 19:13 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@alexcams
alexcams requested a review from edmocosta July 14, 2026 08:27
Comment thread pkg/ottl/compare.go
Comment thread pkg/ottl/compare_test.go
@alexcams
alexcams requested a review from edmocosta July 16, 2026 07:47
Comment thread pkg/ottl/compare.go
@alexcams
alexcams requested a review from edmocosta July 17, 2026 08:16
@alexcams
alexcams force-pushed the make-pcommon-Value-comparable branch from f3caa82 to 243a0e7 Compare July 17, 2026 09:07

@edmocosta edmocosta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @TylerHelmuth @evan-bradley could you please take a look and share your thoughts? Thanks!

@TylerHelmuth
TylerHelmuth merged commit a90fb97 into open-telemetry:main Aug 5, 2026
160 checks passed
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.

[pkg/ottl] Make pcommon.Value comparable

5 participants