learning-it by example

#35 AI agents and MCP 5.1 min

Trace Every Agent Step with OpenTelemetry in Python

Which step of my agent failed, and which was slow? One trace showed both, with the time each step took.

1. In OpenTelemetry tracing, what is a span?
2. In the OpenTelemetry refund-agent demo (a staged slow step and a staged failure), which step was slowest and which step failed?
3. When the email tool fails in the traced agent, what does its except block do?
4. What does the OpenTelemetry refund-agent demo say its tracing result does not show?
5. Why must the tracer provider be registered before the first span is made?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Make the slow step quick

    Copy the code folder first. In agent.py change time.sleep(0.4) in work_out_refund to time.sleep(0.02). Predict which step the report names as slowest now, and roughly how long the agent.run line shows. The OpenTelemetry packages need to be installed as in the video to run it, so this is a prediction task.

    A hint

    The lookup step sleeps for 0.05 seconds, which is now longer than the refund step.

  2. Forget to set the error status

    In send_email in agent.py delete the span.set_status line but keep span.record_exception. Predict the failed steps line, the exception events line, and the status printed next to tool.send_email.

    A hint

    The video says a trace would look healthy if the failure were not recorded on the span. Compare the status and the failed steps line with the original run.

  3. Add a fourth tool

    In agent.py add a function archive(pounds) that opens a span named tool.archive and sleeps for 0.1 seconds, and call it in run() after send_email. Predict the number on the last report line, and where the new span appears in the printed list.

    A hint

    The report prints the parent first, then its children in the order they started.

  4. Choose safe attributes

    Look at the attributes set in agent.py: order.id, refund.pounds and email.sent. Write down two more details of a refund that you would add to a span, and one that you would never add. Use the mistakes list in the video to explain why.

    A hint

    The video says to put inputs that matter as attributes, and never secrets or personal data.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

The slow step and the failure are staged with a sleep and a raised error. No model call, no collector, no sampling and no network. One trace in one process, timed on Windows, where very short spans are only roughly timed.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos