4141 is_streaming ,
4242 set_event_completion ,
4343 StreamWrapper ,
44+ set_span_attributes ,
4445)
4546from openai ._types import NOT_GIVEN
4647
@@ -67,8 +68,7 @@ def traced_method(wrapped, instance, args, kwargs):
6768 kind = SpanKind .CLIENT .value ,
6869 context = set_span_in_context (trace .get_current_span ()),
6970 ) as span :
70- for field , value in attributes .model_dump (by_alias = True ).items ():
71- set_span_attribute (span , field , value )
71+ set_span_attributes (span , attributes )
7272 try :
7373 # Attempt to call the original method
7474 result = wrapped (* args , ** kwargs )
@@ -131,8 +131,7 @@ async def traced_method(wrapped, instance, args, kwargs):
131131 kind = SpanKind .CLIENT .value ,
132132 context = set_span_in_context (trace .get_current_span ()),
133133 ) as span :
134- for field , value in attributes .model_dump (by_alias = True ).items ():
135- set_span_attribute (span , field , value )
134+ set_span_attributes (span , attributes )
136135 try :
137136 # Attempt to call the original method
138137 result = await wrapped (* args , ** kwargs )
@@ -197,9 +196,7 @@ def traced_method(wrapped, instance, args, kwargs):
197196 kind = SpanKind .CLIENT .value ,
198197 context = set_span_in_context (trace .get_current_span ()),
199198 ) as span :
200- for field , value in attributes .model_dump (by_alias = True ).items ():
201- if value is not None :
202- span .set_attribute (field , value )
199+ set_span_attributes (span , attributes )
203200 try :
204201 # Attempt to call the original method
205202 result = wrapped (* args , ** kwargs )
@@ -463,8 +460,7 @@ def traced_method(wrapped, instance, args, kwargs):
463460 context = set_span_in_context (trace .get_current_span ()),
464461 ) as span :
465462
466- for field , value in attributes .model_dump (by_alias = True ).items ():
467- set_span_attribute (span , field , value )
463+ set_span_attributes (span , attributes )
468464 try :
469465 # Attempt to call the original method
470466 result = wrapped (* args , ** kwargs )
@@ -521,8 +517,7 @@ async def traced_method(wrapped, instance, args, kwargs):
521517 context = set_span_in_context (trace .get_current_span ()),
522518 ) as span :
523519
524- for field , value in attributes .model_dump (by_alias = True ).items ():
525- set_span_attribute (span , field , value )
520+ set_span_attributes (span , attributes )
526521 try :
527522 # Attempt to call the original method
528523 result = await wrapped (* args , ** kwargs )
0 commit comments