Skip to content

Commit 08b4889

Browse files
Change to do the minimum in capture_span() context
1 parent afef6f0 commit 08b4889

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

elasticapm/instrumentation/packages/asyncio/aiokafka.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ async def call(
119119
if transaction:
120120
client.end_transaction(result=OUTCOME.SUCCESS)
121121

122-
# May raise StopAsyncIteration
123-
result = await wrapped(*args, **kwargs)
122+
result = await wrapped(*args, **kwargs) # May raise StopAsyncIteration
124123
message = cast("ConsumerRecord", result)
125124

126125
if client.should_ignore_topic(message.topic):
@@ -183,26 +182,26 @@ async def _trace_get(
183182

184183
result = await wrapped(*args, **kwargs)
185184

186-
if not span or isinstance(span, DroppedSpan):
187-
return result
185+
if not span or isinstance(span, DroppedSpan):
186+
return result
188187

189-
trace_topics = [
190-
topic for topic in _extract_topics_from_get_result(result) if not client.should_ignore_topic(topic)
191-
]
188+
trace_topics = [
189+
topic for topic in _extract_topics_from_get_result(result) if not client.should_ignore_topic(topic)
190+
]
192191

193-
if not trace_topics:
194-
span.cancel()
195-
return result
192+
if not trace_topics:
193+
span.cancel()
194+
return result
196195

197-
span.name += f" from {', '.join(trace_topics)}"
198-
cls._enrich_span_context(span, *trace_topics, consumer=instance)
196+
span.name += f" from {', '.join(trace_topics)}"
197+
cls._enrich_span_context(span, *trace_topics, consumer=instance)
199198

200-
for message in _extract_messages_from_get_result(result, include_topics=trace_topics):
201-
trace_parent = _extract_trace_parent_from_message_headers(message.headers)
202-
if trace_parent:
203-
span.add_link(trace_parent)
199+
for message in _extract_messages_from_get_result(result, include_topics=trace_topics):
200+
trace_parent = _extract_trace_parent_from_message_headers(message.headers)
201+
if trace_parent:
202+
span.add_link(trace_parent)
204203

205-
return result
204+
return result
206205

207206
@classmethod
208207
async def _trace_send(
@@ -237,10 +236,10 @@ async def _trace_send(
237236

238237
result = await wrapped(*mutable_args, **kwargs)
239238

240-
if span and not isinstance(span, DroppedSpan):
241-
cls._enrich_span_context(span, topic, producer=instance)
239+
if span and not isinstance(span, DroppedSpan):
240+
cls._enrich_span_context(span, topic, producer=instance)
242241

243-
return result
242+
return result
244243

245244
@classmethod
246245
def _enrich_span_context(

0 commit comments

Comments
 (0)