6
6
package io .opentelemetry .instrumentation .testing ;
7
7
8
8
import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
9
+ import static org .awaitility .Awaitility .await ;
9
10
10
11
import io .opentelemetry .api .OpenTelemetry ;
11
- import io .opentelemetry .instrumentation .testing .internal .AwaitUtil ;
12
12
import io .opentelemetry .instrumentation .testing .util .TelemetryDataUtil ;
13
13
import io .opentelemetry .instrumentation .testing .util .ThrowingRunnable ;
14
14
import io .opentelemetry .instrumentation .testing .util .ThrowingSupplier ;
29
29
import java .util .stream .Collectors ;
30
30
import javax .annotation .Nullable ;
31
31
import org .assertj .core .api .ListAssert ;
32
+ import org .awaitility .core .ConditionTimeoutException ;
32
33
33
34
/**
34
35
* 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(
117
118
List <T > assertionsList = new ArrayList <>();
118
119
assertions .forEach (assertionsList ::add );
119
120
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
+ }
122
140
}
123
141
124
142
private <T extends Consumer <TraceAssert >> void doAssertTraces (
@@ -141,35 +159,31 @@ private <T extends Consumer<TraceAssert>> void doAssertTraces(
141
159
*/
142
160
public final void waitAndAssertMetrics (
143
161
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 ))));
156
173
}
157
174
158
175
@ SafeVarargs
159
176
public final void waitAndAssertMetrics (
160
177
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
+ });
173
187
}
174
188
175
189
private List <MetricData > instrumentationMetrics (String instrumentationName ) {
0 commit comments