Let’s Get Certified
Module 11 / 13 · Operating, monitoring, and securing ML and AI solutions

Trace latency, drift and repeated calls back to their cause

A service sends more tokens per request while user traffic stays flat.

Trace latency, drift and repeated calls back to their cause

A service sends more tokens per request while user traffic stays flat. An average across endpoints cannot reveal a repeated tool call within a single session. Correlate requests, model invocations, retrieval spans and outcome labels before assigning a cause.

At 3:14:03 the instructor explains a rise in token use through repeated tool calls. Inspect the trace for each session before attributing the increase to response length.

Work through the decision

Requests doubled their token use while the model version and price stayed fixed. What would distinguish a looping tool from an overly long answer?

Check your reasoning

Inspect per-session tool spans and input/output tokens per invocation. Several near-identical retrieval spans implicate orchestration; one normal call with a long completion points toward output behavior.

MLA-C02 recording · 3:14:03

Continue in the recording · 2:38:07 · 2:44:22.

Decisions and tradeoffs

Per-session tool trace
Group calls by session and inspect repeated tool names, argument changes, durations and exit conditions.
Data drift monitoring
Compare current feature distributions with a reference baseline, then seek labels to determine the effect on quality.
Delayed-label quality metric
Join ground truth to prior predictions using stable identifiers and the right observation window.
Stage-level workflow alarms
Track error rate and latency by preprocessing, retrieval, model invocation and postprocessing to localize failures.
Controlled online A/B test
Randomly allocate comparable traffic and evaluate a prespecified outcome with sufficient observations.
Grounded response evaluation
Sample model outputs with their supplied contexts and assess whether claims are supported.
Tail latency by operation
Percentiles broken down by stage reveal slow requests hidden by an unchanged mean.

Practice each guide skill

The numbers below follow the AWS task and skill identifiers.

  1. Connect production observations to CloudWatch and periodic evaluations; compare quality and drift with the reference period.
  2. Break a workflow into ingest, retrieval, model and output spans, then locate the first stage breaching its error or latency target.
  3. Compare feature histograms with baseline and collect fresh labels before concluding that predictive quality has declined.
  4. Serve comparable randomized cohorts and evaluate the predetermined outcome after enough observations have accumulated.
  5. Trace a conversation across model and tool spans. Count repeated calls, record timeouts and bound retries.
  6. Sample FM outputs against explicit criteria and compare them by model, prompt version, task and time period.

Official objectives for this lesson

Follow request traces back to the failing stage

These synthetic traces contain retrieved document IDs, the required source and whether the answer was faithful. Count repeated calls and attribute failures before changing the model. Run with Python 3 and its standard library.

traces = [
    ("a", ["search"], ["book"], "book", True, 110),
    ("b", ["search", "search", "search"], ["menu"], "book", False, 610),
    ("c", ["search"], ["book"], "book", False, 160),
]
total = 0
for session, calls, docs, expected, faithful, tokens in traces:
    total += tokens
    stage = "retrieval" if expected not in docs else "ok" if faithful else "generation"
    repeats = len(calls) - len(set(calls))
    print(session, stage, "repeat calls:", repeats)
print("observed tokens:", total)
Check the result
a ok repeat calls: 0
b retrieval repeat calls: 2
c generation repeat calls: 0
observed tokens: 880

In this fixture the desired source is known. Trace b spends the most tokens while missing it; trace c receives the source but fails grounding. Repeated calls warrant inspecting tool inputs. Apply workload limits for enforcement and billing alerts for notification.

Related lesson · Trace a delay to the responsible stage

Knowledge check

Trace latency, drift and repeated calls back to their cause quiz

Answer 3 questions. Check each answer for an explanation.

Worked example · Trace latency, drift and repeated calls back to their cause