@@ -99,11 +99,12 @@ void testMetrics_successfulEcho_grpc() throws Exception {
9999 try (EchoClient client =
100100 TestClientInitializer .createGrpcEchoClientOpentelemetry (tracerFactory )) {
101101
102- EchoResponse echo = client .echo (EchoRequest .newBuilder ().setContent ("metrics-test" ).build ());
103- System .out .println (echo .getContent ());
104- System .out .println ("in test:" + Thread .currentThread ().getName ());
102+ client .echo (EchoRequest .newBuilder ().setContent ("metrics-test" ).build ());
105103
106- // Slight delay to ensure the background callback completes its OpenTelemetry recording.
104+ // The end of an operation is tracked in a separate thread.
105+ // Add a small sleep to make sure the tracking is completed.
106+ // This is implemented by adding a TraceFinisher to ApiFuture as a callback in TracedUnaryCallable,
107+ // which could be executed in a different thread.
107108 Thread .sleep (100 );
108109 Collection <MetricData > metrics = metricReader .collectAllMetrics ();
109110 assertThat (metrics ).isNotEmpty ();
@@ -186,6 +187,7 @@ public void sendMessage(ReqT message) {}
186187 UnavailableException .class ,
187188 () -> client .echo (EchoRequest .newBuilder ().setContent ("metrics-test" ).build ()));
188189
190+ Thread .sleep (100 );
189191 Collection <MetricData > metrics = metricReader .collectAllMetrics ();
190192 assertThat (metrics ).isNotEmpty ();
191193
@@ -217,6 +219,7 @@ void testMetrics_successfulEcho_httpjson() throws Exception {
217219
218220 client .echo (EchoRequest .newBuilder ().setContent ("metrics-test" ).build ());
219221
222+ Thread .sleep (100 );
220223 Collection <MetricData > metrics = metricReader .collectAllMetrics ();
221224 assertThat (metrics ).isNotEmpty ();
222225
@@ -228,8 +231,6 @@ void testMetrics_successfulEcho_httpjson() throws Exception {
228231
229232 assertThat (durationMetric .getInstrumentationScopeInfo ().getName ())
230233 .isEqualTo (SHOWCASE_ARTIFACT );
231- assertThat (durationMetric .getInstrumentationScopeInfo ().getVersion ())
232- .isEqualTo (com .google .api .gax .core .GaxProperties .getLibraryVersion (EchoClient .class ));
233234
234235 io .opentelemetry .api .common .Attributes attributes =
235236 durationMetric .getHistogramData ().getPoints ().iterator ().next ().getAttributes ();
@@ -354,6 +355,7 @@ public String getHeaderValue(int index) {
354355 UnavailableException .class ,
355356 () -> client .echo (EchoRequest .newBuilder ().setContent ("metrics-test" ).build ()));
356357
358+ Thread .sleep (100 );
357359 Collection <MetricData > metrics = metricReader .collectAllMetrics ();
358360 assertThat (metrics ).isNotEmpty ();
359361
0 commit comments