@@ -30,7 +30,7 @@ def _get_span_start_time_ns(span: Optional[Span]) -> Optional[int]:
3030
3131
3232def _calculate_duration_seconds (
33- span : Optional [Span ], invocation : Optional [ LLMInvocation ] = None
33+ span : Optional [Span ], invocation : LLMInvocation
3434) -> Optional [float ]:
3535 """Calculate duration in seconds from a start time to now.
3636
@@ -41,13 +41,8 @@ def _calculate_duration_seconds(
4141 Returns None if no usable start time is available.
4242 """
4343 # Prefer an explicit monotonic start on the invocation (seconds)
44- if invocation is not None and getattr (
45- invocation , "monotonic_start_s" , None
46- ):
47- start_s = invocation .monotonic_start_s
48- if isinstance (start_s , (int , float )):
49- elapsed_s = max (timeit .default_timer () - float (start_s ), 0.0 )
50- return elapsed_s
44+ if invocation .monotonic_start_s is not None :
45+ return max (timeit .default_timer () - invocation .monotonic_start_s , 0.0 )
5146
5247 # Fall back to span start_time (wall clock epoch ns)
5348 start_time_ns = _get_span_start_time_ns (span )
@@ -118,10 +113,9 @@ def record(
118113 and isinstance (duration_seconds , Number )
119114 and duration_seconds >= 0
120115 ):
121- duration_attributes : Dict [str , AttributeValue ] = dict (attributes )
122116 self ._duration_histogram .record (
123117 duration_seconds ,
124- attributes = duration_attributes ,
118+ attributes = attributes ,
125119 context = span_context ,
126120 )
127121
0 commit comments