@@ -61,8 +61,14 @@ def traced_method(wrapped, instance, args, kwargs):
6161 if config and len (config ) > 0 :
6262 span_attributes ["dspy.optimizer.config" ] = json .dumps (config )
6363
64+ # passed operation name
65+ opname = operation_name
66+ if extra_attributes is not None and "langtrace.span.name" in extra_attributes :
67+ # append the operation name to the span name
68+ opname = f"{ operation_name } -{ extra_attributes ['langtrace.span.name' ]} "
69+
6470 attributes = FrameworkSpanAttributes (** span_attributes )
65- with tracer .start_as_current_span (operation_name , kind = SpanKind .CLIENT ) as span :
71+ with tracer .start_as_current_span (opname , kind = SpanKind .CLIENT ) as span :
6672 _set_input_attributes (span , kwargs , attributes )
6773
6874 try :
@@ -100,6 +106,12 @@ def traced_method(wrapped, instance, args, kwargs):
100106 ** (extra_attributes if extra_attributes is not None else {}),
101107 }
102108
109+ # passed operation name
110+ opname = operation_name
111+ if extra_attributes is not None and "langtrace.span.name" in extra_attributes :
112+ # append the operation name to the span name
113+ opname = f"{ operation_name } -{ extra_attributes ['langtrace.span.name' ]} "
114+
103115 if instance .__class__ .__name__ :
104116 span_attributes ["dspy.signature.name" ] = instance .__class__ .__name__
105117 span_attributes ["dspy.signature" ] = str (instance )
@@ -108,7 +120,7 @@ def traced_method(wrapped, instance, args, kwargs):
108120 span_attributes ["dspy.signature.args" ] = str (kwargs )
109121
110122 attributes = FrameworkSpanAttributes (** span_attributes )
111- with tracer .start_as_current_span (operation_name , kind = SpanKind .CLIENT ) as span :
123+ with tracer .start_as_current_span (opname , kind = SpanKind .CLIENT ) as span :
112124 _set_input_attributes (span , kwargs , attributes )
113125
114126 try :
@@ -147,6 +159,12 @@ def traced_method(wrapped, instance, args, kwargs):
147159 ** (extra_attributes if extra_attributes is not None else {}),
148160 }
149161
162+ # passed operation name
163+ opname = operation_name
164+ if extra_attributes is not None and "langtrace.span.name" in extra_attributes :
165+ # append the operation name to the span name
166+ opname = f"{ operation_name } -{ extra_attributes ['langtrace.span.name' ]} "
167+
150168 if hasattr (instance , "devset" ):
151169 span_attributes ["dspy.evaluate.devset" ] = str (getattr (instance , "devset" ))
152170 if hasattr (instance , "trainset" ):
@@ -175,7 +193,7 @@ def traced_method(wrapped, instance, args, kwargs):
175193 span_attributes ["dspy.evaluate.args" ] = str (args )
176194
177195 attributes = FrameworkSpanAttributes (** span_attributes )
178- with tracer .start_as_current_span (operation_name , kind = SpanKind .CLIENT ) as span :
196+ with tracer .start_as_current_span (opname , kind = SpanKind .CLIENT ) as span :
179197 _set_input_attributes (span , kwargs , attributes )
180198
181199 try :
0 commit comments