opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

LongExemplarAssert.hasFilteredAttributesSatisfyingExactly does not enforce exact matching

Open thswlsqls opened this issue 5 months ago • 0 comments

Describe the bug

LongExemplarAssert.hasFilteredAttributesSatisfyingExactly(AttributeAssertion...) does not enforce exact attribute matching. It accepts an exemplar that has extra filtered attributes beyond those asserted, so a test using it can pass when it should fail.

Steps to reproduce

Assert a long exemplar that has multiple filtered attributes, but pass only a subset to hasFilteredAttributesSatisfyingExactly:

OpenTelemetryAssertions.assertThat(longGaugeMetric)
    .hasLongGaugeSatisfying(gauge -> gauge.hasPointsSatisfying(point ->
        point.hasExemplarsSatisfying(exemplar ->
            // exemplar has several filtered attributes; only one is asserted
            exemplar.hasFilteredAttributesSatisfyingExactly(equalTo(stringKey("bear"), "mya")))));

What did you expect to see?

An AssertionError, because the exemplar has filtered attributes that were not asserted. DoubleExemplarAssert.hasFilteredAttributesSatisfyingExactly (the sibling) behaves this way.

What did you see instead?

The assertion passes. The varargs overload delegates to hasFilteredAttributesSatisfying (AssertUtil.assertAttributes, a containsAll check) instead of the exact helper (assertAttributesExactly, containsExactlyInAnyOrder). See LongExemplarAssert.java line 128; DoubleExemplarAssert.java line 129 is correct.

What version and what artifacts are you using? Artifacts: opentelemetry-sdk-testing Version: main @ 824334c55 (present since 1.21.0)

Environment Compiler: Temurin 21 OS: N/A

Additional context The Iterable overload in the same class is correct; only the varargs overload misroutes.

thswlsqls avatar Jun 22 '26 08:06 thswlsqls