Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async def run(self, input: Any) -> AgentGraphResult:
# Graph-level metrics
if tracker:
tracker.track_path(handler.path)
tracker.track_latency(duration)
tracker.track_duration(duration)
tracker.track_invocation_success()
tracker.track_total_tokens(sum_token_usage_from_messages(messages))

Expand All @@ -325,7 +325,7 @@ async def run(self, input: Any) -> AgentGraphResult:
log.warning(f'LangGraphAgentGraphRunner run failed: {exc}')
duration = (time.perf_counter_ns() - start_ns) // 1_000_000
if tracker:
tracker.track_latency(duration)
tracker.track_duration(duration)
tracker.track_invocation_failure()
return AgentGraphResult(
output='',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def test_langgraph_runner_run_tracks_failure_on_exception():

assert result.metrics.success is False
tracker.track_invocation_failure.assert_called_once()
tracker.track_latency.assert_called_once()
tracker.track_duration.assert_called_once()


@pytest.mark.asyncio
Expand Down Expand Up @@ -148,4 +148,4 @@ async def test_langgraph_runner_run_success():
assert result.metrics.success is True
tracker.track_path.assert_called_once_with([])
tracker.track_invocation_success.assert_called_once()
tracker.track_latency.assert_called_once()
tracker.track_duration.assert_called_once()
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def test_tracks_node_and_graph_tokens_on_success():
ev = _events(mock_ld_client)
assert ev['$ld:ai:graph:total_tokens'][0][1] == 15
assert ev['$ld:ai:graph:invocation_success'][0][1] == 1
assert '$ld:ai:graph:latency' in ev
assert '$ld:ai:graph:duration:total' in ev
assert '$ld:ai:graph:path' in ev


Expand Down Expand Up @@ -428,7 +428,7 @@ async def test_tracks_failure_and_latency_on_model_error():

ev = _events(mock_ld_client)
assert '$ld:ai:graph:invocation_failure' in ev
assert '$ld:ai:graph:latency' in ev
assert '$ld:ai:graph:duration:total' in ev
assert '$ld:ai:graph:invocation_success' not in ev


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def run(self, input: Any) -> AgentGraphResult:

if tracker:
tracker.track_path(path)
tracker.track_latency(duration)
tracker.track_duration(duration)
tracker.track_invocation_success()
token_usage = get_ai_usage_from_response(result)
if token_usage is not None:
Expand All @@ -110,7 +110,7 @@ async def run(self, input: Any) -> AgentGraphResult:
log.warning(f'OpenAIAgentGraphRunner run failed: {exc}')
duration = (time.perf_counter_ns() - start_ns) // 1_000_000
if tracker:
tracker.track_latency(duration)
tracker.track_duration(duration)
tracker.track_invocation_failure()
return AgentGraphResult(
output='',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def test_openai_agent_graph_runner_run_tracks_invocation_failure_on_except

assert result.metrics.success is False
tracker.track_invocation_failure.assert_called_once()
tracker.track_latency.assert_called_once()
tracker.track_duration.assert_called_once()


@pytest.mark.asyncio
Expand Down Expand Up @@ -134,7 +134,7 @@ async def test_openai_agent_graph_runner_run_success():
assert result.metrics.success is True
tracker.track_invocation_success.assert_called_once()
tracker.track_path.assert_called_once()
tracker.track_latency.assert_called_once()
tracker.track_duration.assert_called_once()

root_tracker = graph.get_node('root-agent').get_config().tracker
root_tracker.track_duration.assert_called_once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async def test_tracks_graph_invocation_success_and_latency():

ev = _events(mock_ld_client)
assert ev['$ld:ai:graph:invocation_success'][0][1] == 1
assert '$ld:ai:graph:latency' in ev
assert '$ld:ai:graph:duration:total' in ev
assert '$ld:ai:graph:path' in ev


Expand Down Expand Up @@ -404,7 +404,7 @@ async def test_tracks_failure_and_latency_on_runner_error():

ev = _events(mock_ld_client)
assert '$ld:ai:graph:invocation_failure' in ev
assert '$ld:ai:graph:latency' in ev
assert '$ld:ai:graph:duration:total' in ev
assert '$ld:ai:graph:invocation_success' not in ev


Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/server-ai/src/ldai/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,14 @@ def track_invocation_failure(self) -> None:
1,
)

def track_latency(self, duration: int) -> None:
def track_duration(self, duration: int) -> None:
"""
Track the total latency of graph execution.
Track the total duration of graph execution.

:param duration: Duration in milliseconds.
"""
self._ld_client.track(
"$ld:ai:graph:latency",
"$ld:ai:graph:duration:total",
self._context,
self.__get_track_data(),
duration,
Expand Down
Loading