@@ -1862,8 +1862,14 @@ def create_trace_span(self, seq_group: SequenceGroup) -> None:
18621862                context = trace_context ,
18631863                start_time = arrival_time_nano_seconds ) as  seq_span :
18641864            metrics  =  seq_group .metrics 
1865-             ttft  =  metrics .first_token_time  -  metrics .arrival_time 
1866-             e2e_time  =  metrics .finished_time  -  metrics .arrival_time 
1865+ 
1866+             # Handle potential None values for cancelled/aborted requests 
1867+             ttft  =  (metrics .first_token_time  -  metrics .arrival_time 
1868+                     if  metrics .first_token_time  is  not None  else  None )
1869+ 
1870+             e2e_time  =  (metrics .finished_time  -  metrics .arrival_time 
1871+                         if  metrics .finished_time  is  not None  else  None )
1872+ 
18671873            seq_span .set_attribute (SpanAttributes .GEN_AI_RESPONSE_MODEL ,
18681874                                   self .model_config .model )
18691875            seq_span .set_attribute (SpanAttributes .GEN_AI_REQUEST_ID ,
@@ -1886,11 +1892,18 @@ def create_trace_span(self, seq_group: SequenceGroup) -> None:
18861892                    seq .get_output_len ()
18871893                    for  seq  in  seq_group .get_finished_seqs ()
18881894                ]))
1889-             seq_span .set_attribute (SpanAttributes .GEN_AI_LATENCY_TIME_IN_QUEUE ,
1890-                                    metrics .time_in_queue )
1891-             seq_span .set_attribute (
1892-                 SpanAttributes .GEN_AI_LATENCY_TIME_TO_FIRST_TOKEN , ttft )
1893-             seq_span .set_attribute (SpanAttributes .GEN_AI_LATENCY_E2E , e2e_time )
1895+ 
1896+             # Only set timing attributes if the values are available 
1897+             if  metrics .time_in_queue  is  not None :
1898+                 seq_span .set_attribute (
1899+                     SpanAttributes .GEN_AI_LATENCY_TIME_IN_QUEUE ,
1900+                     metrics .time_in_queue )
1901+             if  ttft  is  not None :
1902+                 seq_span .set_attribute (
1903+                     SpanAttributes .GEN_AI_LATENCY_TIME_TO_FIRST_TOKEN , ttft )
1904+             if  e2e_time  is  not None :
1905+                 seq_span .set_attribute (SpanAttributes .GEN_AI_LATENCY_E2E ,
1906+                                        e2e_time )
18941907            if  metrics .scheduler_time  is  not None :
18951908                seq_span .set_attribute (
18961909                    SpanAttributes .GEN_AI_LATENCY_TIME_IN_SCHEDULER ,
0 commit comments