@@ -178,18 +178,16 @@ async def _do_execute(self, func, instance, args, kwargs):
178178 except IndexError :
179179 name = ""
180180
181+ # Hydrate attributes before span creation to enable filtering
182+ span_attributes = _hydrate_span_from_args (
183+ instance ,
184+ args [0 ],
185+ args [1 :] if self .capture_parameters else None ,
186+ )
187+
181188 with self ._tracer .start_as_current_span (
182- name , kind = SpanKind .CLIENT
189+ name , kind = SpanKind .CLIENT , attributes = span_attributes
183190 ) as span :
184- if span .is_recording ():
185- span_attributes = _hydrate_span_from_args (
186- instance ,
187- args [0 ],
188- args [1 :] if self .capture_parameters else None ,
189- )
190- for attribute , value in span_attributes .items ():
191- span .set_attribute (attribute , value )
192-
193191 try :
194192 result = await func (* args , ** kwargs )
195193 except Exception as exc : # pylint: disable=W0703
@@ -217,20 +215,19 @@ async def _do_cursor_execute(self, func, instance, args, kwargs):
217215 except IndexError :
218216 name = ""
219217
218+ # Hydrate attributes before span creation to enable filtering
219+ span_attributes = _hydrate_span_from_args (
220+ instance ._connection ,
221+ instance ._query ,
222+ instance ._args if self .capture_parameters else None ,
223+ )
224+
220225 stop = False
221226 with self ._tracer .start_as_current_span (
222227 f"CURSOR: { name } " ,
223228 kind = SpanKind .CLIENT ,
229+ attributes = span_attributes ,
224230 ) as span :
225- if span .is_recording ():
226- span_attributes = _hydrate_span_from_args (
227- instance ._connection ,
228- instance ._query ,
229- instance ._args if self .capture_parameters else None ,
230- )
231- for attribute , value in span_attributes .items ():
232- span .set_attribute (attribute , value )
233-
234231 try :
235232 result = await func (* args , ** kwargs )
236233 except StopAsyncIteration :
0 commit comments