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 ;
10
9
11
10
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 ;
33
32
34
33
/**
35
34
* This interface defines a common set of operations for interaction with OpenTelemetry SDK and
@@ -118,25 +117,8 @@ private <T extends Consumer<TraceAssert>> void waitAndAssertTraces(
118
117
List <T > assertionsList = new ArrayList <>();
119
118
assertions .forEach (assertionsList ::add );
120
119
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
- }
120
+ AwaitUtil .awaitUntilAsserted (
121
+ () -> doAssertTraces (traceComparator , assertionsList , verifyScopeVersion ));
140
122
}
141
123
142
124
private <T extends Consumer <TraceAssert >> void doAssertTraces (
@@ -159,31 +141,35 @@ private <T extends Consumer<TraceAssert>> void doAssertTraces(
159
141
*/
160
142
public final void waitAndAssertMetrics (
161
143
String instrumentationName , String metricName , Consumer <ListAssert <MetricData >> assertion ) {
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 ))));
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 ))));
173
156
}
174
157
175
158
@ SafeVarargs
176
159
public final void waitAndAssertMetrics (
177
160
String instrumentationName , Consumer <MetricAssert >... assertions ) {
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
- });
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
+ });
187
173
}
188
174
189
175
private List <MetricData > instrumentationMetrics (String instrumentationName ) {
0 commit comments