From fa15ed54c1e4e3a23990674b61661a6f31012b29 Mon Sep 17 00:00:00 2001 From: Abram Date: Wed, 27 Nov 2024 10:00:34 +0100 Subject: [PATCH] refactor (sdk:web): compute latency/duration in sdk properly and update use of it in the playground --- agenta-cli/agenta/sdk/tracing/inline.py | 11 +++++++---- .../src/components/Playground/Views/TestView.tsx | 4 +--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/agenta-cli/agenta/sdk/tracing/inline.py b/agenta-cli/agenta/sdk/tracing/inline.py index 69b90fb7a9..d8309db99c 100644 --- a/agenta-cli/agenta/sdk/tracing/inline.py +++ b/agenta-cli/agenta/sdk/tracing/inline.py @@ -41,7 +41,6 @@ class LifecycleDTO(BaseModel): class TimeDTO(BaseModel): start: datetime end: datetime - span: int class StatusCode(Enum): @@ -846,12 +845,9 @@ def parse_from_otel_span_dto( else None ) - duration = (otel_span_dto.end_time - otel_span_dto.start_time).total_seconds() - time = TimeDTO( start=otel_span_dto.start_time, end=otel_span_dto.end_time, - span=round(duration * 1_000_000), # microseconds ) status = StatusDTO( @@ -863,6 +859,13 @@ def parse_from_otel_span_dto( data, metrics, meta, tags, refs = _parse_from_attributes(otel_span_dto) + duration = (otel_span_dto.end_time - otel_span_dto.start_time).total_seconds() + + if metrics is None: + metrics = dict() + + metrics["acc.duration.total"] = round(duration * 1_000, 3) # milliseconds + root_id = str(tree_id) if refs is not None: root_id = refs.get("scenario.id", root_id) diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index 2da370ae79..5c725cb15c 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -623,9 +623,7 @@ const App: React.FC = ({ const firstTraceNode = tree.nodes[0] newDataList[index] = { cost: firstTraceNode?.metrics?.acc?.costs?.total ?? null, - latency: firstTraceNode?.time?.span - ? firstTraceNode.time.span / 1_000_000 - : null, + latency: firstTraceNode?.metrics?.acc?.duration?.total / 1000 ?? null, usage: firstTraceNode?.metrics?.acc?.tokens?.total ?? null, } }