Skip to content

Add exhaustive metric assertions and flatten histogram tests - #20741

Closed
trask with Copilot wants to merge 14 commits into
mainfrom
copilot/implement-histogram-points-helper
Closed

trask with Copilot wants to merge 14 commits into
mainfrom
copilot/implement-histogram-points-helper

Conversation

Copilot AI commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Add scope-level exhaustive metric assertions and a histogram helper that keeps metadata and point callbacks at the same nesting level.

import static io.opentelemetry.instrumentation.testing.util.MetricAssertions.histogram;

// Expect exactly these metrics under INSTRUMENTATION_NAME.
testing.waitAndAssertMetricsExactly(
    INSTRUMENTATION_NAME,
    histogram(
        metric -> metric.hasName("messaging.process.duration").hasUnit("s"),
        point -> point.hasCount(1)));

Scope is the only filter. Each expected callback matches a distinct metric, exactly in any order; missing or extra metrics fail. Ordinary metric callbacks also support sums and gauges, and histogram(...) matches points exactly in any order.

Migrate tests whose existing expectations cover the complete scope output, retaining their metadata and point assertions. This intentionally strengthens previously existential collection checks. Callers with partial scope expectations keep their original assertions. No production telemetry changes.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-21 02:50 UTC

Move out of draft to request review.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI changed the title [WIP] Add MetricAssertions.hasHistogramPointsSatisfyingExactly helper Add composable histogram point assertions and adopt across tests Oct 19, 2026
Copilot AI requested a review from trask October 19, 2026 23:57
@trask
trask requested a balanced review from Copilot October 20, 2026 00:02

Copilot AI 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.

🟢 Approval recommended

No unresolved issues were identified that would block approval.

No open issues 🎉

What changed in this PR

Adds composable histogram assertions to shared test infrastructure, reducing nesting while preserving existing expectations.

Changes:

  • Adds an SDK-delegating histogram-point assertion helper.
  • Covers unordered matching, cardinality, empty histograms, and assertion failures.
  • Adopts the helper across tests without changing production telemetry.
File Description
testing-common/​src/​test/​java/​io/​opentelemetry/​instrumentation/​testing/​util/​MetricAssertionsTest.java Updated as part of this pull request.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​util/​MetricAssertions.java Updated as part of this pull request.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​http/​AbstractHttpServerTest.java Updated as part of this pull request.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​http/​AbstractHttpClientTest.java Updated as part of this pull request.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​db/​DbConnectionPoolMetricsAssertions.java Updated as part of this pull request.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​db/​DbClientMetricsTestUtil.java Updated as part of this pull request.
instrumentation/​thrift-0.13/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​thrift/​v0_13/​AbstractThriftTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-webflux/​spring-webflux-5.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​webflux/​v5_0/​client/​SpringWebfluxClientInstrumentationTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-rabbit-1.0/​javaagent/​src/​version20Test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​rabbit/​v1_0/​SpringRabbit20DirectMessageListenerContainerTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-rabbit-1.0/​javaagent/​src/​version11Test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​rabbit/​v1_0/​SpringRabbit11SimpleMessageListenerContainerTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-pulsar-1.0/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​spring/​pulsar/​v1_0/​AbstractSpringPulsarTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-integration-4.1/​testing/​src/​main/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​integration/​v4_1/​SpringIntegrationTestHelper.java Updated as part of this pull request.
instrumentation/​spring/​spring-integration-4.1/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​integration/​v4_1/​MessageProducerSupportInstrumentationTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-ai-1.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​ai/​v1_0/​ChatModelTest.java Updated as part of this pull request.
instrumentation/​spring/​spring-ai-1.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​spring/​ai/​v1_0/​AbstractOpenAiChatModelTest.java Updated as part of this pull request.
instrumentation/​sofa-rpc-5.4/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​sofarpc/​v5_4/​AbstractSofaRpcTraceChainTest.java Updated as part of this pull request.
instrumentation/​sofa-rpc-5.4/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​sofarpc/​v5_4/​AbstractSofaRpcTest.java Updated as part of this pull request.
instrumentation/​runtime-telemetry/​library/​src/​testJava21/​java/​io/​opentelemetry/​instrumentation/​runtimetelemetry/​JfrVirtualThreadPinnedTest.java Updated as part of this pull request.
instrumentation/​runtime-telemetry/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​runtimetelemetry/​RuntimeTelemetryDefaultsTest.java Updated as part of this pull request.
instrumentation/​runtime-telemetry/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​runtimetelemetry/​internal/​GarbageCollectorTest.java Updated as part of this pull request.
instrumentation/​runtime-telemetry/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​runtimetelemetry/​JmxRuntimeMetricsTest.java Updated as part of this pull request.
instrumentation/​rocketmq/​rocketmq-client-5.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​instrumentation/​rocketmqclient/​v5_0/​RocketMqSimpleConsumerTest.java Updated as part of this pull request.
instrumentation/​rocketmq/​rocketmq-client-5.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​instrumentation/​rocketmqclient/​v5_0/​AbstractRocketMqClientTest.java Updated as part of this pull request.
instrumentation/​rocketmq/​rocketmq-client-5.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​instrumentation/​rocketmqclient/​v5_0/​AbstractRocketMqClientSuppressReceiveSpanTest.java Updated as part of this pull request.
instrumentation/​rocketmq/​rocketmq-client-4.8/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​rocketmqclient/​v4_8/​RocketMqMetricsTest.java Updated as part of this pull request.
instrumentation/​ratpack/​ratpack-1.4/​javaagent/​src/​version17Test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​ratpack/​v1_4/​httpclient/​client/​RatpackHttpClientTest.java Updated as part of this pull request.
instrumentation/​pulsar/​pulsar-2.8/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​pulsar/​v2_8/​PulsarClientTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.65/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_65/​incubator/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.37/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_37/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.37/​javaagent/​src/​oldAndNewIncubatorTest/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_37/​incubator/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.37/​javaagent/​src/​incubatorTest/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_37/​incubator/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.32/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_32/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.32/​javaagent/​src/​incubatorTest/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_32/​incubator/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.31/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_31/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​opentelemetry-api/​opentelemetry-api-1.10/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​opentelemetryapi/​v1_10/​metrics/​MeterTest.java Updated as part of this pull request.
instrumentation/​openai/​openai-java-1.1/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​openai/​v1_1/​AbstractEmbeddingsTest.java Updated as part of this pull request.
instrumentation/​openai/​openai-java-1.1/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​openai/​v1_1/​AbstractChatTest.java Updated as part of this pull request.
instrumentation/​openai/​openai-java-1.1/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​openai/​v1_1/​ChatTest.java Updated as part of this pull request.
instrumentation/​nats/​nats-2.17/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​nats/​v2_17/​AbstractNatsTest.java Updated as part of this pull request.
instrumentation/​mongo/​mongo-4.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​mongo/​v4_0/​MongoConfiguredTargetTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractTimerTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractTimerMillisecondsTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractTimerHistogramGaugesTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractPrometheusModeTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractNamingConventionTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractDistributionSummaryTest.java Updated as part of this pull request.
instrumentation/​micrometer/​micrometer-1.5/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​micrometer/​v1_5/​AbstractDistributionSummaryHistogramGaugesTest.java Updated as part of this pull request.
instrumentation/​lettuce/​lettuce-5.1/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​lettuce/​v5_1/​AbstractLettuceClientTest.java Updated as part of this pull request.
instrumentation/​lettuce/​lettuce-5.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​lettuce/​v5_0/​LettuceReactiveClientTest.java Updated as part of this pull request.
instrumentation/​kubernetes-client-7.0/​javaagent/​src/​version20Test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​kubernetesclient/​v7_0/​KubernetesClientVer20Test.java Updated as part of this pull request.
instrumentation/​kubernetes-client-7.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​kubernetesclient/​v7_0/​KubernetesClientTest.java Updated as part of this pull request.
instrumentation/​jedis/​jedis-4.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jedis/​v4_0/​Jedis40ClientTest.java Updated as part of this pull request.
instrumentation/​jedis/​jedis-3.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jedis/​v3_0/​ShardedJedis30ClientTest.java Updated as part of this pull request.
instrumentation/​jedis/​jedis-2.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​jedis/​v2_0/​ShardedJedisClientTest.java Updated as part of this pull request.
instrumentation/​jdbc/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​jdbc/​datasource/​JdbcTelemetryTest.java Updated as part of this pull request.
instrumentation/​javalin/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​javalin/​AbstractJavalinTest.java Updated as part of this pull request.
instrumentation/​iceberg-1.8/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​iceberg/​v1_8/​AbstractIcebergTest.java Updated as part of this pull request.
instrumentation/​grpc-1.6/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​grpc/​v1_6/​AbstractGrpcTest.java Updated as part of this pull request.
instrumentation/​grpc-1.6/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​grpc/​v1_6/​AbstractGrpcStreamingTest.java Updated as part of this pull request.
instrumentation/​failsafe-3.0/​library/​src/​test/​java/​io/​opentelemetry/​instrumentation/​failsafe/​v3_0/​FailsafeTelemetryTest.java Updated as part of this pull request.
instrumentation/​dropwizard/​dropwizard-metrics-4.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​dropwizardmetrics/​v4_0/​DropwizardMetricsTest.java Updated as part of this pull request.
instrumentation/​clickhouse/​clickhouse-client-v2-0.8/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​clickhouse/​clientv2/​v0_8/​ClickHouseClientV2Test.java Updated as part of this pull request.
instrumentation/​clickhouse/​clickhouse-client-v1-0.5/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​clickhouse/​clientv1/​v0_5/​ClickHouseClientV1Test.java Updated as part of this pull request.
instrumentation/​cassandra/​cassandra-4.4/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​cassandra/​v4_4/​CassandraTest.java Updated as part of this pull request.
instrumentation/​cassandra/​cassandra-4.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​cassandra/​v4_0/​CassandraTest.java Updated as part of this pull request.
instrumentation/​camel-2.20/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​camel/​v2_20/​CamelMessagingMetricsAssertions.java Updated as part of this pull request.
instrumentation/​aws-sdk/​aws-sdk-2.2/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​awssdk/​v2_2/​SqsMetricsAssertions.java Updated as part of this pull request.
instrumentation/​aws-sdk/​aws-sdk-1.11/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​awssdk/​v1_11/​SqsMetricsAssertions.java Updated as part of this pull request.
instrumentation/​aws-lambda/​aws-lambda-events-2.2/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​awslambdaevents/​v2_2/​AwsLambdaSqsMetricsAssertions.java Updated as part of this pull request.
instrumentation/​avaje-jex-3.0/​javaagent/​src/​test/​java/​io/​opentelemetry/​javaagent/​instrumentation/​avaje/​jex/​v3_0/​JexTest.java Updated as part of this pull request.
instrumentation/​apache-dubbo-2.7/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​apachedubbo/​v2_7/​AbstractDubboTraceChainTest.java Updated as part of this pull request.
instrumentation/​apache-dubbo-2.7/​testing/​src/​main/​java/​io/​opentelemetry/​instrumentation/​apachedubbo/​v2_7/​AbstractDubboTest.java Updated as part of this pull request.

Review effort: Balanced

Copilot AI requested a review from trask October 20, 2026 03:48
@trask trask changed the title Add composable histogram point assertions and adopt across tests Flatten histogram assertions across tests Oct 20, 2026
Copilot AI requested a review from trask October 20, 2026 22:59

Copilot AI 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.

🔵 Needs a closer look

The broad migration introduces complete-scope expectations across many instrumentation suites that warrant final human confirmation.

1 open issue

Review effort: Balanced

Copilot AI and others added 14 commits October 20, 2026 18:57
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
Co-authored-by: trask <218610+trask@users.noreply.github.com>
@trask
trask force-pushed the copilot/implement-histogram-points-helper branch from 20bd24b to 72bfb64 Compare October 21, 2026 02:04
@opentelemetry-pr-dashboard
opentelemetry-pr-dashboard Bot requested a balanced review from Copilot October 21, 2026 02:04

Copilot AI 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.

🟡 Changes recommended

The new observable gauge tests leave callbacks registered, retaining state and emitting metrics during subsequent tests.

2 open issues

Review effort: Balanced

Comment on lines +21 to +36
testing
.getOpenTelemetry()
.getMeter("test-exhaustive-metric-pre-read")
.gaugeBuilder("repeated.gauge")
.ofLongs()
.buildWithCallback(measurement -> measurement.record(1));

testing.metrics();

testing.waitAndAssertMetricsExactly(
"test-exhaustive-metric-pre-read",
metric ->
metric
.hasName("repeated.gauge")
.hasLongGaugeSatisfying(
gauge -> gauge.hasPointsSatisfying(point -> point.hasValue(1))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants