0
Phase 11

OpenTelemetry

~2 min read

Concept & How It Works

    Why Does It Exist?

    Agent stacks mix frameworks, models, and custom services. OTel lets you trace the entire request path in one system instead of siloed vendor dashboards.

    Real-World Analogy

    OpenTelemetry is USB-C for observability — one plug on your code, many monitors on the other end.
    Loading diagram...

    Visual Workflows

    What is OpenTelemetry?

    Loading diagram...

    Example

    Scenario

    OTel trace spans: API gateway → agent orchestrator → OpenAI chat (1.2s) → Postgres tool (80ms) → response, all linked by trace_id.

    Solution

    In Agent Evaluation & Observability, apply OpenTelemetry to this scenario: OTel trace spans: API gateway → agent orchestrator → OpenAI chat (1. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to OpenTelemetry (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where OpenTelemetry happens in the code.

    OpenTelemetry
    1from opentelemetry import trace  # import dependencies2from opentelemetry.sdk.trace import TracerProvider  # import dependencies3from opentelemetry.sdk.trace.export import BatchSpanProcessor  # import dependencies4from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter  # import dependencies5
    6provider = TracerProvider()7provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))8trace.set_tracer_provider(provider)

    Commands to Remember

    Commands to Remember

    • pip install langsmith # trace and evaluate LLM runs
    • pip install arize-phoenix # open-source LLM observability
    • pip install opentelemetry-api opentelemetry-sdk # distributed tracing

    Common Mistakes

    • Treating OpenTelemetry as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for opentelemetry

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • OpenTelemetry
    • OTLP
    • Span
    • GenAI Semconv