From d63f6d6e6d63559208468ef28827bf5220f50eea Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Fri, 21 Mar 2025 12:16:00 +0200 Subject: [PATCH] Fix flaky @WithSpan test (#13562) --- .../test/annotation/WithSpanInstrumentationTest.java | 4 +++- .../annotations/InstrumentationWithSpanAspectTest.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java index 961dd70987..4e5d14680a 100644 --- a/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java +++ b/instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/test/java/io/opentelemetry/test/annotation/WithSpanInstrumentationTest.java @@ -6,6 +6,7 @@ package io.opentelemetry.test.annotation; import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; @@ -112,7 +113,8 @@ class WithSpanInstrumentationTest { void multipleSpansWithoutParent() { new TracedWithSpan().consumer(); - testing.waitAndAssertTraces( + testing.waitAndAssertSortedTraces( + orderByRootSpanName("TracedWithSpan.consumer", "TracedWithSpan.withoutParent"), trace -> trace.hasSpansSatisfyingExactly( span -> diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/InstrumentationWithSpanAspectTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/InstrumentationWithSpanAspectTest.java index 443bfdc5be..83b99c792f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/InstrumentationWithSpanAspectTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/annotations/InstrumentationWithSpanAspectTest.java @@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumen import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.api.trace.SpanKind.CLIENT; import static io.opentelemetry.api.trace.SpanKind.INTERNAL; +import static io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil.orderByRootSpanName; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.TracesAssert.assertThat; import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION; @@ -189,7 +190,8 @@ class InstrumentationWithSpanAspectTest { testing.runWithSpan("parent", withSpanTester::testWithoutParentSpan); // then - testing.waitAndAssertTraces( + testing.waitAndAssertSortedTraces( + orderByRootSpanName("parent", unproxiedTesterSimpleClassName + ".testWithoutParentSpan"), trace -> trace.hasSpansSatisfyingExactly(span -> span.hasName("parent").hasKind(INTERNAL)), trace -> trace.hasSpansSatisfyingExactly(