Fix flaky @WithSpan test (#13562)

This commit is contained in:
Lauri Tulmin 2025-03-21 12:16:00 +02:00 committed by GitHub
parent 5dfd0068c5
commit d63f6d6e6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -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 ->

View File

@ -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(