Skip to content

Fix spring kafka interceptor wrappers not delegating some methods #10935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ dependencies {

implementation(project(":instrumentation:kafka:kafka-clients:kafka-clients-common:library"))

compileOnly("org.springframework.kafka:spring-kafka:2.7.0")
// compiling against 2.8.0 to use methods that are not present in 2.7
compileOnly("org.springframework.kafka:spring-kafka:2.8.0")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If bumping to v2.8.0, does the folder and package naming need to be updated too? e.g.:

  • spring-kafka-2.7/ -> spring-kafka-2.8/
  • io/opentelemetry/javaagent/instrumentation/spring/kafka/v2_7 -> io/opentelemetry/javaagent/instrumentation/spring/kafka/v2_8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That version number is based on the earliest supported version. Even if we compile agains 2.8 the instrumentation still works for 2.7 that we use to run tests.


testImplementation(project(":instrumentation:spring:spring-kafka-2.7:testing"))
testImplementation(project(":instrumentation:kafka:kafka-clients:kafka-clients-2.6:library"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.opentelemetry.instrumentation.kafka.internal.KafkaConsumerContext;
import io.opentelemetry.instrumentation.kafka.internal.KafkaConsumerContextUtil;
import io.opentelemetry.instrumentation.kafka.internal.KafkaReceiveRequest;
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;
import java.lang.ref.WeakReference;
import javax.annotation.Nullable;
import org.apache.kafka.clients.consumer.Consumer;
Expand Down Expand Up @@ -94,4 +95,20 @@ private void end(ConsumerRecords<K, V> records, @Nullable Throwable error) {
lastProcessed.set(new WeakReference<>(records));
}
}

@NoMuzzle // method was added in 2.8.0
@Override
public void setupThreadState(Consumer<?, ?> consumer) {
if (decorated != null) {
decorated.setupThreadState(consumer);
}
}

@NoMuzzle // method was added in 2.8.0
@Override
public void clearThreadState(Consumer<?, ?> consumer) {
if (decorated != null) {
decorated.clearThreadState(consumer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,28 @@ private void end(ConsumerRecord<K, V> record, @Nullable Throwable error) {
processInstrumenter.end(state.context(), request, null, error);
}
}

@NoMuzzle // method was added in 2.8.0
@Override
public void afterRecord(ConsumerRecord<K, V> record, Consumer<K, V> consumer) {
if (decorated != null) {
decorated.afterRecord(record, consumer);
}
}

@NoMuzzle // method was added in 2.8.0
@Override
public void setupThreadState(Consumer<?, ?> consumer) {
if (decorated != null) {
decorated.setupThreadState(consumer);
}
}

@NoMuzzle // method was added in 2.8.0
@Override
public void clearThreadState(Consumer<?, ?> consumer) {
if (decorated != null) {
decorated.clearThreadState(consumer);
}
}
}
Loading