Skip to content

Commit

Permalink
refactor (sdk:web): compute latency/duration in sdk properly and upda…
Browse files Browse the repository at this point in the history
…te use of it in the playground
  • Loading branch information
aybruhm committed Nov 27, 2024
1 parent 2de3761 commit fa15ed5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 7 additions & 4 deletions agenta-cli/agenta/sdk/tracing/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class LifecycleDTO(BaseModel):
class TimeDTO(BaseModel):
start: datetime
end: datetime
span: int


class StatusCode(Enum):
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions agenta-web/src/components/Playground/Views/TestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,7 @@ const App: React.FC<TestViewProps> = ({
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,
}
}
Expand Down

0 comments on commit fa15ed5

Please sign in to comment.