Skip to content

Commit 99b511b

Browse files
committed
review
1 parent 4443006 commit 99b511b

File tree

5 files changed

+31
-53
lines changed

5 files changed

+31
-53
lines changed

instrumentation/opensearch/opensearch-java-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchResponseHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.javaagent.instrumentation.opensearch.v3_0;
77

8+
import static io.opentelemetry.javaagent.instrumentation.opensearch.v3_0.OpenSearchSingletons.instrumenter;
9+
810
import io.opentelemetry.context.Context;
911
import java.util.function.BiConsumer;
1012

@@ -20,6 +22,6 @@ public OpenSearchResponseHandler(Context context, OpenSearchRequest otelRequest)
2022
@Override
2123
public void accept(Object response, Throwable error) {
2224
// OpenSearch responses don't provide response information, so the span is closed with null.
23-
OpenSearchSingletons.instrumenter().end(context, otelRequest, null, error);
25+
instrumenter().end(context, otelRequest, null, error);
2426
}
2527
}
Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.net.URI;
2626
import java.util.concurrent.CompletableFuture;
2727
import java.util.concurrent.CountDownLatch;
28-
import java.util.concurrent.atomic.AtomicReference;
2928
import org.junit.jupiter.api.AfterAll;
3029
import org.junit.jupiter.api.BeforeAll;
3130
import org.junit.jupiter.api.Test;
@@ -39,7 +38,7 @@
3938

4039
@SuppressWarnings("deprecation") // using deprecated semconv
4140
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
42-
abstract class AbstractOpenSearchJavaTest {
41+
abstract class AbstractOpenSearchTest {
4342

4443
protected OpenSearchClient openSearchClient;
4544
protected OpenSearchAsyncClient openSearchAsyncClient;
@@ -105,33 +104,22 @@ void shouldGetStatusWithTraces() throws IOException {
105104

106105
@Test
107106
void shouldGetStatusAsyncWithTraces() throws Exception {
108-
AtomicReference<CompletableFuture<HealthResponse>> responseCompletableFuture =
109-
new AtomicReference<>();
110107
CountDownLatch countDownLatch = new CountDownLatch(1);
111108

112-
getTesting()
113-
.runWithSpan(
114-
"client",
115-
() -> {
116-
CompletableFuture<HealthResponse> future = openSearchAsyncClient.cluster().health();
117-
responseCompletableFuture.set(future);
118-
119-
future.whenComplete(
120-
(response, throwable) -> {
121-
getTesting()
122-
.runWithSpan(
123-
"callback",
124-
() -> {
125-
if (throwable != null) {
126-
throw new RuntimeException(throwable);
127-
}
128-
countDownLatch.countDown();
129-
});
130-
});
131-
});
109+
CompletableFuture<HealthResponse> responseCompletableFuture =
110+
getTesting()
111+
.runWithSpan(
112+
"client",
113+
() ->
114+
openSearchAsyncClient
115+
.cluster()
116+
.health()
117+
.whenComplete(
118+
(response, throwable) ->
119+
getTesting().runWithSpan("callback", countDownLatch::countDown)));
132120

133121
countDownLatch.await();
134-
HealthResponse healthResponse = responseCompletableFuture.get().get();
122+
HealthResponse healthResponse = responseCompletableFuture.get();
135123
assertThat(healthResponse).isNotNull();
136124

137125
getTesting()

instrumentation/opensearch/opensearch-java-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchApacheHttpClient5TransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.opensearch.client.transport.OpenSearchTransport;
2626
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;
2727

28-
class OpenSearchApacheHttpClient5TransportTest extends AbstractOpenSearchJavaTest {
28+
class OpenSearchApacheHttpClient5TransportTest extends AbstractOpenSearchTest {
2929

3030
@RegisterExtension
3131
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create();

instrumentation/opensearch/opensearch-java-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchAwsSdk2TransportTest.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.MockWebServerExtension;
3030
import java.util.concurrent.CompletableFuture;
3131
import java.util.concurrent.CountDownLatch;
32-
import java.util.concurrent.atomic.AtomicReference;
3332
import org.junit.jupiter.api.AfterAll;
3433
import org.junit.jupiter.api.BeforeAll;
3534
import org.junit.jupiter.api.BeforeEach;
@@ -51,7 +50,7 @@
5150
import software.amazon.awssdk.utils.AttributeMap;
5251

5352
@SuppressWarnings("deprecation") // using deprecated semconv
54-
class OpenSearchAwsSdk2TransportTest extends AbstractOpenSearchJavaTest {
53+
class OpenSearchAwsSdk2TransportTest extends AbstractOpenSearchTest {
5554

5655
protected static final MockWebServerExtension server = new MockWebServerExtension();
5756

@@ -152,33 +151,22 @@ protected OpenSearchAsyncClient buildOpenSearchAsyncClient() throws Exception {
152151
@Test
153152
@Override
154153
void shouldGetStatusAsyncWithTraces() throws Exception {
155-
AtomicReference<CompletableFuture<HealthResponse>> responseCompletableFuture =
156-
new AtomicReference<>();
157154
CountDownLatch countDownLatch = new CountDownLatch(1);
158155

159-
getTesting()
160-
.runWithSpan(
161-
"client",
162-
() -> {
163-
CompletableFuture<HealthResponse> future = openSearchAsyncClient.cluster().health();
164-
responseCompletableFuture.set(future);
165-
166-
future.whenComplete(
167-
(response, throwable) -> {
168-
getTesting()
169-
.runWithSpan(
170-
"callback",
171-
() -> {
172-
if (throwable != null) {
173-
throw new RuntimeException(throwable);
174-
}
175-
countDownLatch.countDown();
176-
});
177-
});
178-
});
156+
CompletableFuture<HealthResponse> responseCompletableFuture =
157+
getTesting()
158+
.runWithSpan(
159+
"client",
160+
() ->
161+
openSearchAsyncClient
162+
.cluster()
163+
.health()
164+
.whenComplete(
165+
(response, throwable) ->
166+
getTesting().runWithSpan("callback", countDownLatch::countDown)));
179167

180168
countDownLatch.await();
181-
HealthResponse healthResponse = responseCompletableFuture.get().get();
169+
HealthResponse healthResponse = responseCompletableFuture.get();
182170
assertThat(healthResponse).isNotNull();
183171

184172
getTesting()

instrumentation/opensearch/opensearch-java-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchRestClientTransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@SuppressWarnings(
3131
"deprecation") // RestClientTransport is deprecated but still the correct way for OpenSearch
3232
// Java 3.0
33-
class OpenSearchRestClientTransportTest extends AbstractOpenSearchJavaTest {
33+
class OpenSearchRestClientTransportTest extends AbstractOpenSearchTest {
3434

3535
@RegisterExtension
3636
static final AgentInstrumentationExtension testing = AgentInstrumentationExtension.create();

0 commit comments

Comments
 (0)