Mitigate against another kafka leak (#6021)

This commit is contained in:
Trask Stalnaker 2022-05-13 10:22:47 -07:00 committed by GitHub
parent dd5e30defd
commit 1df75378a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -53,10 +53,13 @@ public class TracingIterator<K, V> implements Iterator<ConsumerRecord<K, V>> {
// in case they didn't call hasNext()...
closeScopeAndEndSpan();
// it's important not to suppress consumer span creation here using Instrumenter.shouldStart()
// because this instrumentation can leak the context and so there may be a leaked consumer span
// in the context, in which case it's important to overwrite the leaked span instead of
// suppressing the correct span
// (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1947)
ConsumerRecord<K, V> next = delegateIterator.next();
if (next != null
&& consumerProcessInstrumenter().shouldStart(parentContext, next)
&& KafkaClientsConsumerProcessTracing.wrappingEnabled()) {
if (next != null && KafkaClientsConsumerProcessTracing.wrappingEnabled()) {
currentRequest = next;
currentContext = consumerProcessInstrumenter().start(parentContext, currentRequest);
currentScope = currentContext.makeCurrent();