Skip to content

Commit f602e19

Browse files
authored
Fix InstrumentedRecordInterceptor closing the trace too early (#11471)
1 parent ed351da commit f602e19

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

instrumentation/spring/spring-kafka-2.7/library/src/main/java/io/opentelemetry/instrumentation/spring/kafka/v2_7/InstrumentedBatchInterceptor.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ private static Context getParentContext(ConsumerRecords<?, ?> records) {
7171

7272
@Override
7373
public void success(ConsumerRecords<K, V> records, Consumer<K, V> consumer) {
74-
end(records, null);
75-
if (decorated != null) {
76-
decorated.success(records, consumer);
74+
try {
75+
if (decorated != null) {
76+
decorated.success(records, consumer);
77+
}
78+
} finally {
79+
end(records, null);
7780
}
7881
}
7982

8083
@Override
8184
public void failure(ConsumerRecords<K, V> records, Exception exception, Consumer<K, V> consumer) {
82-
end(records, exception);
83-
if (decorated != null) {
84-
decorated.failure(records, exception, consumer);
85+
try {
86+
if (decorated != null) {
87+
decorated.failure(records, exception, consumer);
88+
}
89+
} finally {
90+
end(records, exception);
8591
}
8692
}
8793

instrumentation/spring/spring-kafka-2.7/library/src/main/java/io/opentelemetry/instrumentation/spring/kafka/v2_7/InstrumentedRecordInterceptor.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@ private static Context getParentContext(ConsumerRecord<?, ?> record) {
6969

7070
@Override
7171
public void success(ConsumerRecord<K, V> record, Consumer<K, V> consumer) {
72-
end(record, null);
73-
if (decorated != null) {
74-
decorated.success(record, consumer);
72+
try {
73+
if (decorated != null) {
74+
decorated.success(record, consumer);
75+
}
76+
} finally {
77+
end(record, null);
7578
}
7679
}
7780

7881
@Override
7982
public void failure(ConsumerRecord<K, V> record, Exception exception, Consumer<K, V> consumer) {
80-
end(record, exception);
81-
if (decorated != null) {
82-
decorated.failure(record, exception, consumer);
83+
try {
84+
if (decorated != null) {
85+
decorated.failure(record, exception, consumer);
86+
}
87+
} finally {
88+
end(record, exception);
8389
}
8490
}
8591

0 commit comments

Comments
 (0)