Skip to content

Commit bfc5ec3

Browse files
[release/v1.33.x] Fix InstrumentedRecordInterceptor closing the trace too early (#11592)
Co-authored-by: Ben <[email protected]>
1 parent 5d310b3 commit bfc5ec3

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
@@ -56,17 +56,23 @@ private static Context getParentContext(ConsumerRecords<?, ?> records) {
5656

5757
@Override
5858
public void success(ConsumerRecords<K, V> records, Consumer<K, V> consumer) {
59-
end(records, null);
60-
if (decorated != null) {
61-
decorated.success(records, consumer);
59+
try {
60+
if (decorated != null) {
61+
decorated.success(records, consumer);
62+
}
63+
} finally {
64+
end(records, null);
6265
}
6366
}
6467

6568
@Override
6669
public void failure(ConsumerRecords<K, V> records, Exception exception, Consumer<K, V> consumer) {
67-
end(records, exception);
68-
if (decorated != null) {
69-
decorated.failure(records, exception, consumer);
70+
try {
71+
if (decorated != null) {
72+
decorated.failure(records, exception, consumer);
73+
}
74+
} finally {
75+
end(records, exception);
7076
}
7177
}
7278

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)