@@ -208,7 +208,6 @@ def __init__(
208
208
consume_hook : HookT = dummy_callback ,
209
209
):
210
210
super ().__init__ (wrapped )
211
- self ._self_active_span : Optional [Span ] = None
212
211
self ._self_active_token = None
213
212
self ._self_tracer = tracer
214
213
self ._self_consume_hook = consume_hook
@@ -221,11 +220,12 @@ def popleft(self, *args, **kwargs):
221
220
context .detach (self ._self_active_token )
222
221
except Exception as inst_exception : # pylint: disable=W0703
223
222
_LOG .exception (inst_exception )
223
+
224
224
evt = self .__wrapped__ .popleft (* args , ** kwargs )
225
+
225
226
try :
226
- # If a new message was received, create a span and set as active
227
+ # If a new message was received, create a span and set as active context
227
228
if type (evt ) is _ConsumerDeliveryEvt :
228
- # start span
229
229
method = evt .method
230
230
properties = evt .properties
231
231
if not properties :
@@ -238,7 +238,7 @@ def popleft(self, *args, **kwargs):
238
238
if not ctx :
239
239
ctx = context .get_current ()
240
240
message_ctx_token = context .attach (ctx )
241
- self . _self_active_span = _get_span (
241
+ span = _get_span (
242
242
self ._self_tracer ,
243
243
None ,
244
244
properties ,
@@ -251,12 +251,10 @@ def popleft(self, *args, **kwargs):
251
251
)
252
252
context .detach (message_ctx_token )
253
253
self ._self_active_token = context .attach (
254
- trace .set_span_in_context (self . _self_active_span )
254
+ trace .set_span_in_context (span )
255
255
)
256
256
try :
257
- self ._self_consume_hook (
258
- self ._self_active_span , evt .body , properties
259
- )
257
+ self ._self_consume_hook (span , evt .body , properties )
260
258
except Exception as hook_exception : # pylint: disable=W0703
261
259
_LOG .exception (hook_exception )
262
260
0 commit comments