-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for reactor-kafka 1.3+ (#8529)
- Loading branch information
Mateusz Rzeszutek
authored
May 24, 2023
1 parent
ac343b2
commit b6c612a
Showing
10 changed files
with
336 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...elemetry/javaagent/instrumentation/reactor/kafka/v1_0/ConsumerHandlerInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.reactor.kafka.v1_0; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.returns; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import reactor.core.publisher.Flux; | ||
|
||
// handles versions 1.3.+ | ||
public class ConsumerHandlerInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("reactor.kafka.receiver.internals.ConsumerHandler"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("receive").and(returns(named("reactor.core.publisher.Flux"))), | ||
this.getClass().getName() + "$ReceiveAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class ReceiveAdvice { | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void onExit(@Advice.Return(readOnly = false) Flux<?> flux) { | ||
if (!(flux instanceof TracingDisablingKafkaFlux)) { | ||
flux = new TracingDisablingKafkaFlux<>(flux); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...io/opentelemetry/javaagent/instrumentation/reactor/kafka/v1_0/KafkaReceiver133Access.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.reactor.kafka.v1_0; | ||
|
||
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
import reactor.core.publisher.Flux; | ||
import reactor.kafka.receiver.KafkaReceiver; | ||
import reactor.kafka.receiver.ReceiverRecord; | ||
import reactor.kafka.sender.TransactionManager; | ||
|
||
final class KafkaReceiver133Access { | ||
|
||
@NoMuzzle | ||
static <K, V> Flux<ReceiverRecord<K, V>> receive(KafkaReceiver<K, V> receiver, Integer prefetch) { | ||
return receiver.receive(prefetch); | ||
} | ||
|
||
@NoMuzzle | ||
static <K, V> Flux<Flux<ConsumerRecord<K, V>>> receiveAutoAck( | ||
KafkaReceiver<K, V> receiver, Integer prefetch) { | ||
return receiver.receiveAutoAck(prefetch); | ||
} | ||
|
||
@NoMuzzle | ||
static <K, V> Flux<ConsumerRecord<K, V>> receiveAtmostOnce( | ||
KafkaReceiver<K, V> receiver, Integer prefetch) { | ||
return receiver.receiveAtmostOnce(prefetch); | ||
} | ||
|
||
@NoMuzzle | ||
static <K, V> Flux<Flux<ConsumerRecord<K, V>>> receiveExactlyOnce( | ||
KafkaReceiver<K, V> receiver, TransactionManager transactionManager, Integer prefetch) { | ||
return receiver.receiveExactlyOnce(transactionManager, prefetch); | ||
} | ||
|
||
private KafkaReceiver133Access() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...etry/javaagent/instrumentation/reactor/kafka/v1_0/ReactorKafka133InstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.reactor.kafka.v1_0; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ReactorKafka133InstrumentationTest extends AbstractReactorKafkaTest { | ||
|
||
@Test | ||
void testReceive() { | ||
testSingleRecordProcess(recordConsumer -> receiver.receive(1).subscribe(recordConsumer)); | ||
} | ||
|
||
@Test | ||
void testReceiveAutoAck() { | ||
testSingleRecordProcess( | ||
recordConsumer -> | ||
receiver.receiveAutoAck(1).subscribe(records -> records.subscribe(recordConsumer))); | ||
} | ||
|
||
@Test | ||
void testReceiveAtMostOnce() { | ||
testSingleRecordProcess( | ||
recordConsumer -> receiver.receiveAtmostOnce(1).subscribe(recordConsumer)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
instrumentation/reactor/reactor-kafka-1.0/testing/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
} | ||
|
||
dependencies { | ||
api(project(":testing-common")) | ||
|
||
compileOnly("io.projectreactor.kafka:reactor-kafka:1.0.0.RELEASE") | ||
implementation("org.testcontainers:kafka") | ||
} |
Oops, something went wrong.