Leanpub Header

Skip to main content

AI Agent Observability

AI Agent Observability in TypeScript with Genkit, LangChain, and OpenTelemetry: What Happens Under the Hood and Why It Matters

AI Agent Observability
This book is 100% completeUpdated 25 Nov 2026

See inside your TypeScript AI agents from the first local trace to production operations: debug tool loops, cut hidden token bills, evaluate trajectories, and monitor live traffic with Firebase Genkit, LangChain/LangSmith, Progress Observability Platform, and OpenTelemetry.

Minimum price

$9.99

$19.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
264
Pages
Discussion Forum
About

About

About the Book

Your TypeScript agent worked in five minutes on localhost. Then real customers started talking to it, and the hard questions arrived. Why did it call the same database tool four times? Why did your token bill triple overnight? Why did changing one line in the system prompt silently break VIP refund eligibility while every HTTP endpoint still returned 200 OK?

console.log cannot debug probabilistic software. When an agent loops through models, tools, and memory at runtime, you need to see every turn, span, and dollar spent.

In AI Agent Observability, you follow Laura and her engineering team at TechStore as they take an AI customer support agent from a fragile local script to a production system. Every concept is backed by 36 runnable, strict-TypeScript examples (Node.js 22.15+, gemini-3-flash-preview, npm run typecheck verified) organized across four complementary observability tools:

  • Firebase Genkit: Build typed flows (defineFlow), tools (defineTool), custom spans (ai.run), and RAG retrievers, inspect every execution locally in the Genkit Developer UI (localhost:4000), and monitor latency percentiles (P95/P99) in production with Genkit Monitoring.
  • LangChain v1 & LangSmith: Trace ReAct loops with createAgent, traceable, and RunTree, manage Golden Datasets and side-by-side CI/CD experiments, filter production runs with FQL, run human Annotation Queues, and enforce piiMiddleware, createAnonymizer, and humanInTheLoopMiddleware.
  • Progress Observability Platform: Instrument agents with @progress/observability for enterprise telemetry, real-time FinOps USD Cost Analytics, business attribute propagation, and automated LLM-as-a-Judge evaluation tasks.
  • OpenTelemetry (gen_ai.* Semantic Conventions): Emit vendor-neutral spans across frameworks, tune BatchSpanProcessor backpressure in production, propagate W3C traceparent and baggage across HTTP subagents and MCP servers, and track streaming TTFT, TPOT, semantic caches, and circuit breakers.

What you will learn

  • Read the full anatomy of an agent trace across spans, runs, child steps, reasoning tokens, and multi-turn threads.
  • Stop the token snowball effect with lean Zod tools, prompt caching prefixes, and hard ReAct loop limits.
  • Move past manual prompt tweaking with Golden Datasets, deterministic evaluators, calibrated LLM-as-a-Judge checks, trajectory tests, and CI/CD regression gates.
  • Catch silent production failures using user feedback tokens (user_thumb), reference-free online evaluators, P95 latency and cost burn alerts, and four-layer PII redaction.
  • Scale distributed agents with W3C context propagation across MCP servers, SSE streaming observability without false 500 alerts on client aborts, tenant-isolated semantic caching, guardrails, and circuit breakers.
  • Configure AGENTS.md, .cursorrules, CLAUDE.md, and GEMINI.md plus MCP servers so your AI coding assistant generates observable, bounded, privacy-safe agents from day one.

Companion TypeScript repository (genkit/, langchain/, and otel/): https://github.com/danywalls/ai-agent-observability-code

Downloadable 20-point production checklist and assistant rule templates: https://danywalls.com/book#resources

Author

About the Author

Dany Paredes

Software Engineer based in Barcelona, Google Developer Expert (GDE) in Angular, and Progress Champion. Author of AI Agent Observability, with 230+ technical articles and 30+ talks on TypeScript, frontend architecture, and production AI systems.

Translations

Translations

Contents

Table of Contents

  • Chapter 0: Before You Start: The Pieces on the Map and Environment Setup
  • Part I: Foundations and Observable Architecture
    • Chapter 1: Coding Agents Building Agents... and It Worked. Now What?
    • Chapter 2: What an Agent Really Is: Model, Messages, Tools, Memory, and Loop
    • Chapter 3: Why Your Usual Logs Aren't Enough: From Flat Logs to Traces and Spans
    • Chapter 4: Tokens, Latency, and Cost: The Bill Nobody Explained to You
  • Part II: The Instrumentation Pillars
    • Chapter 5: Your First Trace with Genkit: Your Agent's "DevTools"
    • Chapter 6: Your First Trace with LangChain + LangSmith
    • Chapter 7: Anatomy of a Trace: Run Types, Metadata, Tags, and Threads
    • Chapter 8: Progress Observability Platform: Traces, FinOps Costs, and LLM-as-a-Judge
    • Chapter 9: OpenTelemetry Without Fear: The Standard Under All Three
  • Part III: Evaluation and Quality
    • Chapter 10: "It Seems to Work" Is Not a Metric: Datasets
    • Chapter 11: Evaluators: Code, LLM-as-a-Judge, and Their Traps
    • Chapter 12: Experiments: Changing the Prompt or Model Without Breaking Anything
    • Chapter 13: Evaluating Agents, Not Only Answers: Trajectory and Loops
    • Chapter 14: User Feedback and Human Annotation Queues
    • Chapter 15: Finding the Needle: Filtering Production Traces for Errors, Latency, and Bad Answers
  • Part IV: Production Operations and Scale
    • Chapter 16: Online Evaluation and Automations
    • Chapter 17: Genkit Monitoring, Dashboards, and Alerts
    • Chapter 18: Privacy and Security: What NOT to Store in Your Traces
    • Chapter 19: Production Architecture and Choosing Your Stack
    • Chapter 20: How to Ask Your AI Assistant for an Observable Agent from Day 1
  • Part V: Advanced Production Patterns
    • Chapter 21: Multi-Agent and MCP Observability
    • Chapter 22: Streaming and Real-Time Observability
    • Chapter 23: Semantic Caching, Guardrails, and Circuit Breakers
  • Appendices A, B, C, and D (Bilingual Glossary, 20-Point Production Checklist, Repository Guide, and Four Pillars Cheat Sheet)

Get the free Community Edition

You can get the free Community Edition in PDF or EPUB just by sharing your name and email address with the author.

 

Also by the Author

Also by the Author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub