|
26 | 26 | import java.util.List; |
27 | 27 | import java.util.ListIterator; |
28 | 28 | import net.bytebuddy.asm.Advice; |
| 29 | +import net.bytebuddy.asm.Advice.AssignReturned; |
29 | 30 | import net.bytebuddy.description.type.TypeDescription; |
30 | 31 | import net.bytebuddy.matcher.ElementMatcher; |
31 | 32 | import org.apache.kafka.clients.consumer.ConsumerRecord; |
@@ -73,83 +74,76 @@ public void transform(TypeTransformer transformer) { |
73 | 74 | @SuppressWarnings("unused") |
74 | 75 | public static class IterableAdvice { |
75 | 76 |
|
76 | | - @SuppressWarnings("unchecked") |
| 77 | + @AssignReturned.ToReturned |
77 | 78 | @Advice.OnMethodExit(suppress = Throwable.class) |
78 | | - public static <K, V> void wrap( |
| 79 | + public static <K, V> Iterable<ConsumerRecord<K, V>> wrap( |
79 | 80 | @Advice.This ConsumerRecords<?, ?> records, |
80 | | - @Advice.Return(readOnly = false) Iterable<ConsumerRecord<K, V>> iterable) { |
| 81 | + @Advice.Return Iterable<ConsumerRecord<K, V>> iterable) { |
81 | 82 |
|
82 | 83 | // it's important not to suppress consumer span creation here because this instrumentation can |
83 | 84 | // leak the context and so there may be a leaked consumer span in the context, in which |
84 | 85 | // case it's important to overwrite the leaked span instead of suppressing the correct span |
85 | 86 | // (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1947) |
86 | 87 | KafkaConsumerContext consumerContext = KafkaConsumerContextUtil.get(records); |
87 | | - iterable = |
88 | | - TracingIterable.wrap( |
89 | | - iterable, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
| 88 | + return TracingIterable.wrap( |
| 89 | + iterable, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
90 | 90 | } |
91 | 91 | } |
92 | 92 |
|
93 | 93 | @SuppressWarnings("unused") |
94 | 94 | public static class ListAdvice { |
95 | 95 |
|
96 | | - @SuppressWarnings("unchecked") |
| 96 | + @AssignReturned.ToReturned |
97 | 97 | @Advice.OnMethodExit(suppress = Throwable.class) |
98 | | - public static <K, V> void wrap( |
| 98 | + public static <K, V> List<ConsumerRecord<K, V>> wrap( |
99 | 99 | @Advice.This ConsumerRecords<?, ?> records, |
100 | | - @Advice.Return(readOnly = false) List<ConsumerRecord<K, V>> list) { |
| 100 | + @Advice.Return List<ConsumerRecord<K, V>> list) { |
101 | 101 |
|
102 | 102 | // it's important not to suppress consumer span creation here because this instrumentation can |
103 | 103 | // leak the context and so there may be a leaked consumer span in the context, in which |
104 | 104 | // case it's important to overwrite the leaked span instead of suppressing the correct span |
105 | 105 | // (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1947) |
106 | 106 | KafkaConsumerContext consumerContext = KafkaConsumerContextUtil.get(records); |
107 | | - list = |
108 | | - TracingList.wrap( |
109 | | - list, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
| 107 | + return TracingList.wrap( |
| 108 | + list, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
110 | 109 | } |
111 | 110 | } |
112 | 111 |
|
113 | 112 | @SuppressWarnings("unused") |
114 | 113 | public static class IteratorAdvice { |
115 | 114 |
|
116 | | - @SuppressWarnings("unchecked") |
| 115 | + @AssignReturned.ToReturned |
117 | 116 | @Advice.OnMethodExit(suppress = Throwable.class) |
118 | | - public static <K, V> void wrap( |
| 117 | + public static <K, V> Iterator<ConsumerRecord<K, V>> wrap( |
119 | 118 | @Advice.This ConsumerRecords<?, ?> records, |
120 | | - @Advice.Return(readOnly = false) Iterator<ConsumerRecord<K, V>> iterator) { |
| 119 | + @Advice.Return Iterator<ConsumerRecord<K, V>> iterator) { |
121 | 120 |
|
122 | 121 | // it's important not to suppress consumer span creation here because this instrumentation can |
123 | 122 | // leak the context and so there may be a leaked consumer span in the context, in which |
124 | 123 | // case it's important to overwrite the leaked span instead of suppressing the correct span |
125 | 124 | // (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1947) |
126 | 125 | KafkaConsumerContext consumerContext = KafkaConsumerContextUtil.get(records); |
127 | | - iterator = |
128 | | - TracingIterator.wrap( |
129 | | - iterator, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
| 126 | + return TracingIterator.wrap( |
| 127 | + iterator, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
130 | 128 | } |
131 | 129 | } |
132 | 130 |
|
133 | 131 | @SuppressWarnings("unused") |
134 | 132 | public static class ListIteratorAdvice { |
135 | 133 |
|
136 | | - @SuppressWarnings("unchecked") |
| 134 | + @AssignReturned.ToReturned |
137 | 135 | @Advice.OnMethodExit(suppress = Throwable.class) |
138 | | - public static <K, V> void wrap( |
| 136 | + public static <K, V> ListIterator<ConsumerRecord<K, V>> wrap( |
139 | 137 | @Advice.This ConsumerRecords<?, ?> records, |
140 | | - @Advice.Return(readOnly = false) ListIterator<ConsumerRecord<K, V>> listIterator) { |
| 138 | + @Advice.Return ListIterator<ConsumerRecord<K, V>> listIterator) { |
141 | 139 |
|
142 | 140 | // it's important not to suppress consumer span creation here because this instrumentation can |
143 | 141 | // leak the context and so there may be a leaked consumer span in the context, in which |
144 | 142 | // case it's important to overwrite the leaked span instead of suppressing the correct span |
145 | 143 | // (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1947) |
146 | 144 | KafkaConsumerContext consumerContext = KafkaConsumerContextUtil.get(records); |
147 | | - listIterator = |
148 | | - TracingListIterator.wrap( |
149 | | - listIterator, |
150 | | - consumerProcessInstrumenter(), |
151 | | - wrappingEnabledSupplier(), |
152 | | - consumerContext); |
| 145 | + return TracingListIterator.wrap( |
| 146 | + listIterator, consumerProcessInstrumenter(), wrappingEnabledSupplier(), consumerContext); |
153 | 147 | } |
154 | 148 | } |
155 | 149 | } |
0 commit comments