Skip to content

Add fluent metric point assertions - #8994

Merged
jack-berg merged 1 commit into
open-telemetry:mainfrom
trask:trask-fluent-metric-point-assertions
Nov 3, 2026
Merged

jack-berg merged 1 commit into
open-telemetry:mainfrom
trask:trask-fluent-metric-point-assertions

Conversation

@trask

@trask trask commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Add fluent typed-point assertions to MetricAssert. For the common Java instrumentation pattern below, removing the intermediate histogram callback saves eight spaces of indentation throughout the point assertions.

Before:

testing.waitAndAssertMetrics(
    "io.opentelemetry.spring-webflux-5.0",
    metric ->
        metric
            .hasName("http.client.request.duration")
            .hasHistogramSatisfying(
                histogram ->
                    histogram.hasPointsSatisfying(
                        point ->
                            point.hasAttributesSatisfyingExactly(
                                equalTo(HTTP_REQUEST_METHOD, "GET"),
                                equalTo(HTTP_RESPONSE_STATUS_CODE, 200),
                                equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
                                equalTo(SERVER_ADDRESS, uri.getHost()),
                                equalTo(SERVER_PORT, uri.getPort())))));

After:

testing.waitAndAssertMetrics(
    "io.opentelemetry.spring-webflux-5.0",
    metric ->
        metric
            .hasName("http.client.request.duration")
            .hasHistogramPointsSatisfying(
                point ->
                    point.hasAttributesSatisfyingExactly(
                        equalTo(HTTP_REQUEST_METHOD, "GET"),
                        equalTo(HTTP_RESPONSE_STATUS_CODE, 200),
                        equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
                        equalTo(SERVER_ADDRESS, uri.getHost()),
                        equalTo(SERVER_PORT, uri.getPort()))));

The shortcuts cover all seven metric types, accept varargs or iterable point assertions, and return MetricAssert for continued chaining.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@trask
trask requested a balanced review from Copilot November 1, 2026 03:11
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-11-03 22:03 UTC

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

@otelbot otelbot Bot added the api-change Changes to public API surface area label Nov 1, 2026
@otelbot

otelbot Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ API changes detected — additional maintainer review required

@jack-berg @jkwatson

This PR modifies the public API surface area of the following module(s):

  • opentelemetry-sdk-testing

Please review the changes in docs/apidiffs/current_vs_latest/ carefully before approving.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the new fluent metric assertion shortcuts.

No open issues 🎉

What changed in this PR

Adds fluent, typed point assertions directly to MetricAssert, reducing nested callbacks while preserving existing type-level assertions and matching behavior.

Changes:

  • Adds varargs and iterable shortcuts for all seven metric types, returning MetricAssert for continued chaining.
  • Tests chaining, any-order and exact matching, mismatched points, and null and wrong-type failures.
  • Updates the API compatibility report with the new overloads.
File Description
sdk/​testing/​src/​test/​java/​io/​opentelemetry/​sdk/​testing/​assertj/​MetricAssertionsTest.java Tests the shortcuts and their success and failure behavior.
sdk/​testing/​src/​main/​java/​io/​opentelemetry/​sdk/​testing/​assertj/​MetricAssert.java Adds 14 fluent overloads delegating to existing typed assertions.
docs/​apidiffs/​current_vs_latest/​opentelemetry-sdk-testing.txt Records the new public assertion methods.

Review effort: Balanced

@trask
trask marked this pull request as ready for review November 1, 2026 03:19
@trask
trask requested a review from a team as a code owner November 1, 2026 03:19
@codecov

codecov Bot commented Nov 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.38%. Comparing base (dc3019e) to head (e84f018).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8994      +/-   ##
============================================
+ Coverage     90.36%   90.38%   +0.02%     
- Complexity    10995    11012      +17     
============================================
  Files          1020     1020              
  Lines         30096    30112      +16     
  Branches       3929     3929              
============================================
+ Hits          27197    27218      +21     
+ Misses         1942     1937       -5     
  Partials        957      957              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jack-berg jack-berg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. Tried out the new APIs locally on some metric tests and the assertions become flatter and more readable.

@jack-berg
jack-berg merged commit a369088 into open-telemetry:main Nov 3, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-change Changes to public API surface area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants