Skip to content

Commit 2efad25

Browse files
committed
refactor: Clarify already-tracked warnings as skips with remedy
Reword the at-most-once warning messages emitted by LDAIConfigTracker and AIGraphTracker. Each warning now states which method is being skipped, what state was already recorded, and tells the caller to invoke create_tracker on the AI Config (or agent graph) to start a new run. This mirrors the doc clarifications recently landed in the Go SDK (launchdarkly/go-server-sdk #363).
1 parent 20df94b commit 2efad25

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

packages/sdk/server-ai/src/ldai/tracker.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ def track_duration(self, duration: int) -> None:
224224
:param duration: Duration in milliseconds.
225225
"""
226226
if self._summary.duration_ms is not None:
227-
log.warning("Duration has already been tracked for this execution. %s", self.__get_track_data())
227+
log.warning(
228+
"Skipping track_duration: duration already recorded on this tracker. "
229+
"Call create_tracker on the AI Config for a new run. %s",
230+
self.__get_track_data(),
231+
)
228232
return
229233
self._summary._duration_ms = duration
230234
self._ld_client.track(
@@ -239,7 +243,8 @@ def track_time_to_first_token(self, time_to_first_token: int) -> None:
239243
"""
240244
if self._summary.time_to_first_token is not None:
241245
log.warning(
242-
"Time to first token has already been tracked for this execution. %s",
246+
"Skipping track_time_to_first_token: time-to-first-token already recorded on this tracker. "
247+
"Call create_tracker on the AI Config for a new run. %s",
243248
self.__get_track_data(),
244249
)
245250
return
@@ -393,7 +398,11 @@ def track_feedback(self, feedback: Dict[str, FeedbackKind]) -> None:
393398
:param feedback: Dictionary containing feedback kind.
394399
"""
395400
if self._summary.feedback is not None:
396-
log.warning("Feedback has already been tracked for this execution. %s", self.__get_track_data())
401+
log.warning(
402+
"Skipping track_feedback: feedback already recorded on this tracker. "
403+
"Call create_tracker on the AI Config for a new run. %s",
404+
self.__get_track_data(),
405+
)
397406
return
398407
self._summary._feedback = feedback
399408
if feedback["kind"] == FeedbackKind.Positive:
@@ -430,7 +439,11 @@ def track_success(self) -> None:
430439
Track a successful AI generation.
431440
"""
432441
if self._summary.success is not None:
433-
log.warning("Success has already been tracked for this execution. %s", self.__get_track_data())
442+
log.warning(
443+
"Skipping track_success: success/error already recorded on this tracker. "
444+
"Call create_tracker on the AI Config for a new run. %s",
445+
self.__get_track_data(),
446+
)
434447
return
435448
self._summary._success = True
436449
self._ld_client.track(
@@ -442,7 +455,11 @@ def track_error(self) -> None:
442455
Track an unsuccessful AI generation attempt.
443456
"""
444457
if self._summary.success is not None:
445-
log.warning("Success has already been tracked for this execution. %s", self.__get_track_data())
458+
log.warning(
459+
"Skipping track_error: success/error already recorded on this tracker. "
460+
"Call create_tracker on the AI Config for a new run. %s",
461+
self.__get_track_data(),
462+
)
446463
return
447464
self._summary._success = False
448465
self._ld_client.track(
@@ -478,7 +495,11 @@ def track_tokens(self, tokens: TokenUsage) -> None:
478495
:param tokens: Token usage data from either custom, OpenAI, or Bedrock sources.
479496
"""
480497
if self._summary.tokens is not None:
481-
log.warning("Tokens have already been tracked for this execution. %s", self.__get_track_data())
498+
log.warning(
499+
"Skipping track_tokens: token usage already recorded on this tracker. "
500+
"Call create_tracker on the AI Config for a new run. %s",
501+
self.__get_track_data(),
502+
)
482503
return
483504
self._summary._tokens = tokens
484505
td = self.__get_track_data()
@@ -608,8 +629,10 @@ def track_invocation_success(self) -> None:
608629
"""
609630
if self._summary.success is not None:
610631
log.warning(
611-
"Invocation status has already been tracked for this graph execution. %s",
612-
self.__get_track_data())
632+
"Skipping track_invocation_success: invocation result already recorded on this graph tracker. "
633+
"Call create_tracker on the agent graph for a new run. %s",
634+
self.__get_track_data(),
635+
)
613636
return
614637
self._summary.success = True
615638
self._ld_client.track(
@@ -625,8 +648,10 @@ def track_invocation_failure(self) -> None:
625648
"""
626649
if self._summary.success is not None:
627650
log.warning(
628-
"Invocation status has already been tracked for this graph execution. %s",
629-
self.__get_track_data())
651+
"Skipping track_invocation_failure: invocation result already recorded on this graph tracker. "
652+
"Call create_tracker on the agent graph for a new run. %s",
653+
self.__get_track_data(),
654+
)
630655
return
631656
self._summary.success = False
632657
self._ld_client.track(
@@ -643,7 +668,11 @@ def track_duration(self, duration: int) -> None:
643668
:param duration: Duration in milliseconds.
644669
"""
645670
if self._summary.duration_ms is not None:
646-
log.warning("Duration has already been tracked for this graph execution. %s", self.__get_track_data())
671+
log.warning(
672+
"Skipping track_duration: duration already recorded on this graph tracker. "
673+
"Call create_tracker on the agent graph for a new run. %s",
674+
self.__get_track_data(),
675+
)
647676
return
648677
self._summary.duration_ms = duration
649678
self._ld_client.track(
@@ -662,7 +691,11 @@ def track_total_tokens(self, tokens: Optional[TokenUsage] = None) -> None:
662691
if tokens is None or tokens.total <= 0:
663692
return
664693
if self._summary.tokens is not None:
665-
log.warning("Token usage has already been tracked for this graph execution. %s", self.__get_track_data())
694+
log.warning(
695+
"Skipping track_total_tokens: tokens already recorded on this graph tracker. "
696+
"Call create_tracker on the agent graph for a new run. %s",
697+
self.__get_track_data(),
698+
)
666699
return
667700
self._summary.tokens = tokens
668701
self._ld_client.track(

0 commit comments

Comments
 (0)