Skip to content

Add normalized metric assertion utilities - #20788

Closed
trask with Copilot wants to merge 2 commits into
mainfrom
copilot/pull-test-utilities
Closed

trask with Copilot wants to merge 2 commits into
mainfrom
copilot/pull-test-utilities

Conversation

Copilot AI commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Normalize captured metric collections before shared assertions: aggregate DELTA sums and histograms, and use the latest snapshot for gauges, summaries, and cumulative data. Preserve metric identity and collection boundaries across library, agent, and smoke-test runners.

  • Assertions: Add typed helpers for metric data types and exhaustive matching by metric identity.
  • Shared utilities: Adapt messaging, database, and HTTP metric assertions.
testing.waitAndAssertMetricsExactly(
    "my.instrumentation",
    longSum(
        metric -> metric.hasName("requests"),
        point -> point.hasValue(3).hasAttributes(attributes)));

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-21 02:35 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.

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test utilities for better coverage Add normalized metric assertion utilities Oct 21, 2026
Copilot AI requested a review from trask October 21, 2026 03:11
@trask
trask requested a balanced review from Copilot October 21, 2026 03:15

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

Normalization can reject valid histograms, discard independent snapshots, and merge distinct metric identities.

3 open issues
What changed in this PR

Adds normalized metric assertions to shared testing infrastructure across library, agent, and smoke-test runners.

Changes:

  • Aggregates DELTA metrics and selects latest snapshot data.
  • Adds typed helpers and exhaustive metric-identity matching.
  • Updates shared assertions and adds normalization tests.
File Description
testing-common/​src/​test/​java/​io/​opentelemetry/​instrumentation/​testing/​util/​MetricAssertionsTest.java Tests typed assertion helpers.
testing-common/​src/​test/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​MetricCollectionTest.java Tests library collection behavior.
testing-common/​src/​test/​java/​io/​opentelemetry/​instrumentation/​testing/​internal/​MetricDataAggregatorTest.java Tests aggregation and snapshot selection.
testing-common/​src/​test/​java/​io/​opentelemetry/​instrumentation/​testing/​InstrumentationTestRunnerMetricsTest.java Tests exhaustive identity matching.
testing-common/​src/​main/​java/​io/​opentelemetry/​javaagent/​testing/​common/​AgentTestingExporterAccess.java Exposes separate agent metric collections.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​util/​MetricAssertions.java Adds typed metric assertions.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​LibraryTestRunner.java Captures library collection boundaries.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​MessagingMetricsAssertions.java Adopts normalized messaging assertions.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​InstrumentationExtension.java Exposes exhaustive metric assertions.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​http/​AbstractHttpServerTest.java Uses the histogram helper.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​http/​AbstractHttpClientTest.java Uses the histogram helper.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​db/​DbConnectionPoolMetricsAssertions.java Adopts typed pool metric assertions.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​junit/​db/​DbClientMetricsTestUtil.java Adopts the histogram helper.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​internal/​MetricDataAggregator.java Implements metric normalization.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​internal/​CollectionCapturingMetricExporter.java Stores exports as separate collections.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​InstrumentationTestRunner.java Normalizes metrics before assertions.
testing-common/​src/​main/​java/​io/​opentelemetry/​instrumentation/​testing/​AgentTestRunner.java Exposes agent collections.
testing-common/​integration-tests/​src/​test/​java/​instrumentation/​MetricCollectionTest.java Tests agent collection behavior.
smoke-tests/​src/​main/​java/​io/​opentelemetry/​smoketest/​TelemetryRetriever.java Preserves metric request boundaries.
smoke-tests/​src/​main/​java/​io/​opentelemetry/​smoketest/​SmokeTestRunner.java Exposes retrieved collections.
smoke-tests-otel-starter/​spring-smoke-testing/​src/​main/​java/​io/​opentelemetry/​spring/​smoketest/​SpringSmokeTestRunner.java Captures starter metric collections.

Review effort: Balanced

Comment on lines +52 to +54
metrics
.computeIfAbsent(new MetricIdentity(metric), unused -> new ArrayList<>())
.add(new MetricSnapshot(collectionIndex, metric));
Comment on lines +514 to +515
ExponentialHistogramBuckets positive = buckets(positiveBuckets);
ExponentialHistogramBuckets negative = buckets(negativeBuckets);
Comment on lines +100 to +101
private static boolean isLatestSnapshot(List<MetricSnapshot> snapshots, int latestCollection) {
return snapshots.get(snapshots.size() - 1).collectionIndex == latestCollection;
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