Skip to content

Commit 45c3e11

Browse files
committed
more
1 parent 4f58c8d commit 45c3e11

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/java/io/opentelemetry/instrumentation/kafkaclients/v2_6/ExceptionHandlingTest.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,54 @@
77

88
import static org.assertj.core.api.Assertions.assertThatThrownBy;
99

10-
import java.lang.reflect.InvocationHandler;
11-
import java.lang.reflect.Method;
10+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
11+
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
1212
import java.lang.reflect.Proxy;
13+
import java.time.Duration;
1314
import org.apache.kafka.clients.consumer.Consumer;
1415
import org.apache.kafka.clients.producer.Producer;
1516
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.extension.RegisterExtension;
1618

17-
class ExceptionHandlingTest extends KafkaClientBaseTest {
19+
class ExceptionHandlingTest {
20+
21+
@RegisterExtension
22+
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
1823

1924
@Test
20-
void testConsumerPropagatesException() {
21-
Consumer<?, ?> throwingConsumer =
25+
void testConsumerExceptionPropagatesToCaller() {
26+
Consumer<?, ?> consumer =
2227
(Consumer<?, ?>)
2328
Proxy.newProxyInstance(
24-
getClass().getClassLoader(),
29+
ExceptionHandlingTest.class.getClassLoader(),
2530
new Class<?>[] {Consumer.class},
26-
new InvocationHandler() {
27-
@Override
28-
public Object invoke(Object proxy, Method method, Object[] args) {
29-
throw new IllegalStateException("Test exception");
30-
}
31+
(proxy, method, args) -> {
32+
throw new IllegalStateException("can't invoke");
3133
});
32-
Consumer<?, ?> wrappedConsumer =
33-
KafkaTelemetry.create(testing.getOpenTelemetry()).wrap(throwingConsumer);
34-
assertThatThrownBy(() -> wrappedConsumer.poll(null))
34+
35+
KafkaTelemetry telemetry = KafkaTelemetry.builder(testing.getOpenTelemetry()).build();
36+
Consumer<?, ?> wrappedConsumer = telemetry.wrap(consumer);
37+
38+
assertThatThrownBy(() -> wrappedConsumer.poll(Duration.ofMillis(1)))
3539
.isInstanceOf(IllegalStateException.class)
36-
.hasMessage("Test exception");
40+
.hasMessage("can't invoke");
3741
}
3842

3943
@Test
40-
void testProducerPropagatesException() {
41-
Producer<?, ?> throwingProducer =
44+
void testProducerExceptionPropagatesToCaller() {
45+
Producer<?, ?> producer =
4246
(Producer<?, ?>)
4347
Proxy.newProxyInstance(
44-
getClass().getClassLoader(),
48+
ExceptionHandlingTest.class.getClassLoader(),
4549
new Class<?>[] {Producer.class},
46-
new InvocationHandler() {
47-
@Override
48-
public Object invoke(Object proxy, Method method, Object[] args) {
49-
throw new IllegalStateException("Test exception");
50-
}
50+
(proxy, method, args) -> {
51+
throw new IllegalStateException("can't invoke");
5152
});
52-
Producer<?, ?> wrappedProducer =
53-
KafkaTelemetry.create(testing.getOpenTelemetry()).wrap(throwingProducer);
54-
assertThatThrownBy(() -> wrappedProducer.send(null))
53+
54+
KafkaTelemetry telemetry = KafkaTelemetry.builder(testing.getOpenTelemetry()).build();
55+
Producer<?, ?> wrappedProducer = telemetry.wrap(producer);
56+
assertThatThrownBy(wrappedProducer::flush)
5557
.isInstanceOf(IllegalStateException.class)
56-
.hasMessage("Test exception");
58+
.hasMessage("can't invoke");
5759
}
5860
}

instrumentation/kafka/kafka-clients/kafka-clients-2.6/library/src/test/java/io/opentelemetry/instrumentation/kafkaclients/v2_6/WrapperSuppressReceiveSpansTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,19 @@ void assertTraces(boolean testHeaders) {
4545
.hasKind(SpanKind.PRODUCER)
4646
.hasParent(trace.getSpan(0))
4747
.hasAttributesSatisfyingExactly(sendAttributes(testHeaders)),
48-
span ->
49-
span.hasName("producer callback")
50-
.hasKind(SpanKind.INTERNAL)
51-
.hasParent(trace.getSpan(0)),
5248
span ->
5349
span.hasName(SHARED_TOPIC + " process")
5450
.hasKind(SpanKind.CONSUMER)
5551
.hasParent(trace.getSpan(1))
56-
.hasLinksSatisfying(links -> assertThat(links).isEmpty())
5752
.hasAttributesSatisfyingExactly(processAttributes(greeting, testHeaders)),
5853
span ->
5954
span.hasName("process child")
6055
.hasKind(SpanKind.INTERNAL)
61-
.hasParent(trace.getSpan(3))));
56+
.hasParent(trace.getSpan(2)),
57+
span ->
58+
span.hasName("producer callback")
59+
.hasKind(SpanKind.INTERNAL)
60+
.hasParent(trace.getSpan(0))));
6261
}
6362

6463
@SuppressWarnings("deprecation") // using deprecated semconv

0 commit comments

Comments
 (0)