Skip to content

Commit dbb2762

Browse files
authored
chore: rename trackLatency to trackDuration on LDGraphTracker (#1285)
1 parent 9e84239 commit dbb2762

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

packages/sdk/server-ai/__tests__/LDGraphTrackerImpl.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,25 @@ it('drops trackInvocationFailure after trackInvocationSuccess and warns', () =>
165165
});
166166

167167
// ---------------------------------------------------------------------------
168-
// trackLatency – at-most-once
168+
// trackDuration – at-most-once
169169
// ---------------------------------------------------------------------------
170170

171-
it('trackLatency sets durationMs and emits event', () => {
171+
it('trackDuration sets durationMs and emits event', () => {
172172
const tracker = makeTracker('r');
173-
tracker.trackLatency(1234);
173+
tracker.trackDuration(1234);
174174
expect(tracker.getSummary().durationMs).toBe(1234);
175175
expect(mockTrack).toHaveBeenCalledWith(
176-
'$ld:ai:graph:latency',
176+
'$ld:ai:graph:duration:total',
177177
testContext,
178178
tracker.getTrackData(),
179179
1234,
180180
);
181181
});
182182

183-
it('drops second trackLatency call and warns', () => {
183+
it('drops second trackDuration call and warns', () => {
184184
const tracker = makeTracker('r');
185-
tracker.trackLatency(100);
186-
tracker.trackLatency(200);
185+
tracker.trackDuration(100);
186+
tracker.trackDuration(200);
187187
expect(mockTrack).toHaveBeenCalledTimes(1);
188188
expect(tracker.getSummary().durationMs).toBe(100);
189189
expect(mockWarn).toHaveBeenCalled();

packages/sdk/server-ai/src/LDGraphTrackerImpl.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,20 @@ export class LDGraphTrackerImpl implements LDGraphTracker {
104104
this._ldClient.track('$ld:ai:graph:invocation_failure', this._context, this.getTrackData(), 1);
105105
}
106106

107-
trackLatency(durationMs: number): void {
107+
trackDuration(durationMs: number): void {
108108
if (this._summary.durationMs !== undefined) {
109109
this._ldClient.logger?.warn(
110-
'LDGraphTracker: trackLatency already called for this run — dropping duplicate call.',
110+
'LDGraphTracker: trackDuration already called for this run — dropping duplicate call.',
111111
);
112112
return;
113113
}
114114
this._summary.durationMs = durationMs;
115-
this._ldClient.track('$ld:ai:graph:latency', this._context, this.getTrackData(), durationMs);
115+
this._ldClient.track(
116+
'$ld:ai:graph:duration:total',
117+
this._context,
118+
this.getTrackData(),
119+
durationMs,
120+
);
116121
}
117122

118123
trackTotalTokens(tokens: LDTokenUsage): void {

packages/sdk/server-ai/src/api/graph/LDGraphTracker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { LDGraphMetricSummary, LDGraphTrackData } from './types';
1515
* try {
1616
* // ... execute graph ...
1717
* tracker.trackInvocationSuccess();
18-
* tracker.trackLatency(durationMs);
18+
* tracker.trackDuration(durationMs);
1919
* } catch {
2020
* tracker.trackInvocationFailure();
2121
* }
@@ -62,13 +62,13 @@ export interface LDGraphTracker {
6262
trackInvocationFailure(): void;
6363

6464
/**
65-
* Tracks the total latency of the graph execution in milliseconds.
66-
* Emits event `$ld:ai:graph:latency` with the duration as the metric value.
65+
* Tracks the total duration of the graph execution in milliseconds.
66+
* Emits event `$ld:ai:graph:duration:total` with the duration as the metric value.
6767
* At-most-once: subsequent calls are dropped with a warning.
6868
*
6969
* @param durationMs Duration in milliseconds.
7070
*/
71-
trackLatency(durationMs: number): void;
71+
trackDuration(durationMs: number): void;
7272

7373
/**
7474
* Tracks aggregate token usage across the entire graph invocation.

0 commit comments

Comments
 (0)