Skip to content

LongExemplarAssert.hasFilteredAttributesSatisfyingExactly does not enforce exact matching #8517

Description

@thswlsqls

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 @ 824334c (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions