[observability] Fix missing e2e/decode/inference latency span attributes (#37789)
This commit is contained in:
@@ -2494,11 +2494,12 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
|
||||
state.time_stats.set_first_token_time()
|
||||
|
||||
if state.finished:
|
||||
if state.time_stats.trace_ctx.tracing_enable:
|
||||
state.time_stats.trace_ctx.trace_set_root_attrs(
|
||||
self.convert_to_span_attrs(state, recv_obj, i)
|
||||
)
|
||||
state.time_stats.set_finished_time()
|
||||
span_attrs = (
|
||||
self.convert_to_span_attrs(state, recv_obj, i)
|
||||
if state.time_stats.trace_ctx.tracing_enable
|
||||
else None
|
||||
)
|
||||
state.time_stats.set_finished_time(span_attrs=span_attrs)
|
||||
meta_info["e2e_latency"] = state.time_stats.get_e2e_latency()
|
||||
|
||||
if get_spec().speculative_algorithm:
|
||||
@@ -3658,8 +3659,8 @@ class TokenizerManager(TokenizerControlMixin, TokenizerManagerScoreMixin):
|
||||
[finish_reason]
|
||||
)
|
||||
|
||||
# Latency attributes
|
||||
span_attrs.update(state.time_stats.convert_to_gen_ai_span_attrs())
|
||||
# Latency attributes are added by set_finished_time(), which stamps
|
||||
# finished_time before deriving them.
|
||||
|
||||
return span_attrs
|
||||
|
||||
|
||||
@@ -415,12 +415,18 @@ class APIServerReqTimeStats(ReqTimeStatsBase):
|
||||
convert_time_to_realtime_ns(ts),
|
||||
)
|
||||
|
||||
def set_finished_time(self, ts=None):
|
||||
def set_finished_time(self, ts=None, span_attrs=None):
|
||||
ts = ts or time.perf_counter()
|
||||
self.finished_time = ts
|
||||
|
||||
if self.trace_ctx.tracing_enable:
|
||||
self.trace_ctx.trace_req_finish(convert_time_to_realtime_ns(ts))
|
||||
# The latency attrs are derived from finished_time and the root span is
|
||||
# closed below, so they must be merged in here rather than by the caller.
|
||||
attrs = dict(span_attrs) if span_attrs else {}
|
||||
attrs.update(self.convert_to_gen_ai_span_attrs())
|
||||
self.trace_ctx.trace_req_finish(
|
||||
convert_time_to_realtime_ns(ts), attrs=attrs
|
||||
)
|
||||
|
||||
def set_first_token_time(self, ts=None):
|
||||
ts = ts or time.perf_counter()
|
||||
|
||||
Reference in New Issue
Block a user