66package io .opentelemetry .instrumentation .testing ;
77
88import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
9+ import static org .awaitility .Awaitility .await ;
910
1011import io .opentelemetry .api .OpenTelemetry ;
11- import io .opentelemetry .instrumentation .testing .internal .AwaitUtil ;
1212import io .opentelemetry .instrumentation .testing .util .TelemetryDataUtil ;
1313import io .opentelemetry .instrumentation .testing .util .ThrowingRunnable ;
1414import io .opentelemetry .instrumentation .testing .util .ThrowingSupplier ;
2929import java .util .stream .Collectors ;
3030import javax .annotation .Nullable ;
3131import org .assertj .core .api .ListAssert ;
32+ import org .awaitility .core .ConditionTimeoutException ;
3233
3334/**
3435 * This interface defines a common set of operations for interaction with OpenTelemetry SDK and
@@ -117,8 +118,25 @@ private <T extends Consumer<TraceAssert>> void waitAndAssertTraces(
117118 List <T > assertionsList = new ArrayList <>();
118119 assertions .forEach (assertionsList ::add );
119120
120- AwaitUtil .awaitUntilAsserted (
121- () -> doAssertTraces (traceComparator , assertionsList , verifyScopeVersion ));
121+ try {
122+ await ()
123+ .untilAsserted (() -> doAssertTraces (traceComparator , assertionsList , verifyScopeVersion ));
124+ } catch (Throwable t ) {
125+ // awaitility is doing a jmx call that is not implemented in GraalVM:
126+ // call:
127+ // https://github.com/awaitility/awaitility/blob/fbe16add874b4260dd240108304d5c0be84eabc8/awaitility/src/main/java/org/awaitility/core/ConditionAwaiter.java#L157
128+ // see https://github.com/oracle/graal/issues/6101 (spring boot graal native image)
129+ if (t .getClass ().getName ().equals ("com.oracle.svm.core.jdk.UnsupportedFeatureError" )
130+ || t instanceof ConditionTimeoutException ) {
131+ // Don't throw this failure since the stack is the awaitility thread, causing confusion.
132+ // Instead, just assert one more time on the test thread, which will fail with a better
133+ // stack trace.
134+ // TODO: There is probably a better way to do this.
135+ doAssertTraces (traceComparator , assertionsList , verifyScopeVersion );
136+ } else {
137+ throw t ;
138+ }
139+ }
122140 }
123141
124142 private <T extends Consumer <TraceAssert >> void doAssertTraces (
@@ -141,35 +159,31 @@ private <T extends Consumer<TraceAssert>> void doAssertTraces(
141159 */
142160 public final void waitAndAssertMetrics (
143161 String instrumentationName , String metricName , Consumer <ListAssert <MetricData >> assertion ) {
144-
145- AwaitUtil .awaitUntilAsserted (
146- () ->
147- assertion .accept (
148- assertThat (getExportedMetrics ())
149- .describedAs (
150- "Metrics for instrumentation %s and metric name %s" ,
151- instrumentationName , metricName )
152- .filteredOn (
153- data ->
154- data .getInstrumentationScopeInfo ().getName ().equals (instrumentationName )
155- && data .getName ().equals (metricName ))));
162+ await ()
163+ .untilAsserted (
164+ () ->
165+ assertion .accept (
166+ assertThat (getExportedMetrics ())
167+ .filteredOn (
168+ data ->
169+ data .getInstrumentationScopeInfo ()
170+ .getName ()
171+ .equals (instrumentationName )
172+ && data .getName ().equals (metricName ))));
156173 }
157174
158175 @ SafeVarargs
159176 public final void waitAndAssertMetrics (
160177 String instrumentationName , Consumer <MetricAssert >... assertions ) {
161- AwaitUtil .awaitUntilAsserted (
162- () -> {
163- Collection <MetricData > metrics = instrumentationMetrics (instrumentationName );
164- assertThat (metrics ).isNotEmpty ();
165- for (int i = 0 ; i < assertions .length ; i ++) {
166- int index = i ;
167- assertThat (metrics )
168- .describedAs (
169- "Metrics for instrumentation %s and assertion %d" , instrumentationName , index )
170- .anySatisfy (metric -> assertions [index ].accept (assertThat (metric )));
171- }
172- });
178+ await ()
179+ .untilAsserted (
180+ () -> {
181+ Collection <MetricData > metrics = instrumentationMetrics (instrumentationName );
182+ assertThat (metrics ).isNotEmpty ();
183+ for (Consumer <MetricAssert > assertion : assertions ) {
184+ assertThat (metrics ).anySatisfy (metric -> assertion .accept (assertThat (metric )));
185+ }
186+ });
173187 }
174188
175189 private List <MetricData > instrumentationMetrics (String instrumentationName ) {
0 commit comments