Skip to main content

Module 26: Advanced Observability & Enterprise AgentOps

Enterprise Observability & OpenTelemetry (Light) Enterprise Observability & OpenTelemetry (Dark)

Theory​

Why AgentOps & Advanced Observability Matter​

🧭 Completing the Callback & Plugin Triad (Modules 25 β†’ 25.5 β†’ 26): In Module 25, you learned the six node-level lifecycle callbacks; in Module 25.5, you elevated them into App-level BasePlugin guardrails for Responsible AI safety. Here in Module 26, we apply that exact same BasePlugin architectureβ€”paired with OpenTelemetryβ€”to gain deep operational visibility across your entire agent fleet!

In production, agents are non-deterministic, distributed software systems. They execute multi-step reasoning, query external tools, spawn sub-agents, and mutate conversational state across asynchronous sessions.

Without robust AgentOps telemetry, diagnosing why an agent failed, tracking token usage spikes, measuring tool latencies, or detecting cascading exceptions becomes nearly impossible.

The Google ADK provides a multi-tiered observability architecture:

  1. Local-First In-Process Plugins (BasePlugin): Lightweight, zero-dependency interceptors for local debugging, alerting, and metrics collection.
  2. Native OpenTelemetry (OTel): Standardized distributed tracing that exports performance data and spans directly to Google Cloud Trace and Cloud Monitoring.
  3. Long-Term Analytics (BigQuery + Looker Studio): Event streaming to BigQuery for historical analytics, cost governance, and business KPI visualization.

The Four Pillars of Agent Telemetry​

A production-grade AgentOps strategy is built on four core pillars:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ FOUR PILLARS OF AGENT TELEMETRY β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. TRACES β”‚ 2. METRICS β”‚ 3. LOGS β”‚ 4. EVENTS β”‚
β”‚ β€’ End-to-end β”‚ β€’ Token Counts β”‚ β€’ Structured β”‚ β€’ State deltas β”‚
β”‚ request span β”‚ β€’ Tool Latency β”‚ JSON payload β”‚ β€’ Tool inputs/ β”‚
β”‚ β€’ Node lineage β”‚ β€’ Error rates β”‚ β€’ Turn context β”‚ outputs β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Four Pillars of Agent Telemetry (Light) Four Pillars of Agent Telemetry (Dark) Figure: The four pillars of agent telemetryβ€”Traces, Metrics, Logs, and Eventsβ€”unified across distributed agent execution graphs.


The ADK Plugin Architecture for Telemetry & Error Recovery​

Building on the BasePlugin pattern from Module 25.5 (where plugins intercepted before_model_callback and on_event_callback to block unsafe content), observability plugins use hooks like on_tool_error_callback and on_event_callback to record operational metrics, fire alerts, and gracefully recover from tool exceptions across every agent in App(plugins=[...]) without cluttering prompt instructions or tool code.

from google.adk.plugins import BasePlugin
from google.adk.events import Event

class TurnMetricsPlugin(BasePlugin):
"""Observes tool errors and turn lifecycles."""

async def on_tool_error_callback(self, *, tool, tool_args, tool_context, error):
print(f"⚠️ [AgentOps Alert] Tool {tool.name} failed: {error}")
# Recover gracefully without crashing the turn
return {"status": "error", "message": str(error)}

async def on_event_callback(self, *, event: Event, **kwargs):
if event.is_final_response():
print(f"Turn completed successfully for agent: {event.author}")

Enterprise Cloud Architecture: OpenTelemetry to Looker Studio​

In enterprise Google Cloud environments, ADK integrates natively with OpenTelemetry to pipe telemetry through the entire Google Cloud data stack:

Low-Level SDK Hook vs. Enterprise agents-cli Telemetry​

In standalone ADK Python scripts (like Lab 26), you can wire Cloud Trace and Cloud Monitoring exporters directly via ADK's low-level get_gcp_exporters() helper:

from google.auth.exceptions import DefaultCredentialsError
from google.adk.telemetry.google_cloud import get_gcp_exporters
from google.adk.telemetry.setup import maybe_set_otel_providers

# Standalone SDK script pattern (gracefully skipped when running with GOOGLE_API_KEY only)
try:
otel_hooks = get_gcp_exporters(
enable_cloud_tracing=True,
enable_cloud_metrics=True,
)
maybe_set_otel_providers(otel_hooks_to_setup=[otel_hooks])
except DefaultCredentialsError:
print("ℹ️ Running locally without GCP ADC; skipping Cloud Trace export.")

🏒 Production Architecture Note (Part 6 β€” Module 30.4): You do not need to hand-write get_gcp_exporters() boilerplate in production services scaffolded with google-agents-cli. As you will build in Module 30.4 (Cloud Telemetry, BigQuery Analytics & Cost Control), scaffolded FastAPI entrypoints automatically configure get_fast_api_app(..., otel_to_cloud=True), Terraform-managed two-tier privacy-preserving GCS/BigQuery prompt-response logging (OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=NO_CONTENT), and opt-in BigQueryAgentAnalyticsPlugin (--bq-analytics).


Key Takeaways​

  • Separation of Concerns: Business logic stays in Agent(instruction=...) and tools; operational monitoring stays in BasePlugin and OpenTelemetry hooks.
  • Local-First Debugging: You can build and verify complete alerting and error recovery plugins locally in seconds without cloud credentials.
  • Enterprise Ready: ADK spans (invocation β†’ agent_run β†’ call_llm / execute_tool) stream directly to Cloud Trace and BigQueryβ€”either via get_gcp_exporters() in standalone scripts or zero-boilerplate otel_to_cloud=True + --bq-analytics in Module 30.4.

🧠 Interactive Knowledge Check​

🎯 Knowledge CheckSelect Best Answer

What happens inside an ADK BasePlugin when on_tool_error_callback returns a recovery dictionary like {'status': 'error', 'message': '...'} instead of None?

1. What happens if a tool raises an unhandled exception and no plugin handles on_tool_error_callback?

The exception propagates up the call stack, halting the agent runner and failing the user's turn. Returning a recovery dictionary from on_tool_error_callback allows the agent to inform the LLM of the error and attempt recovery.

2. Why is event.is_final_response() crucial for tracking turn completion?

An agent may emit multiple intermediate events (e.g. tool calls, thinking steps, thoughts). is_final_response() indicates that the model has finished its entire turn and delivered the final response to the user.

3. What is the key advantage of streaming agent logs to BigQuery for Looker Studio?

It allows business leaders and SRE teams to analyze long-term agent trends: token consumption, cost per user, tool success rates, and user drop-off over thousands of historical sessions.


Closing Out Part 4: Ready for External Protocols & UIs (Part 5)​

This closes out Part 4: Production Readiness! Over Modules 22 through 26, you equipped your agents with persistent sessions and memory (SessionService & MemoryService), versioned binary/text artifacts (ArtifactService), golden-trajectory evaluation (adk eval), lifecycle callbacks (Module 25), fail-closed RAI safety plugins (Module 25.5), and OpenTelemetry AgentOps observability (Module 26).

Next, in Part 5: Ecosystem Protocols & Multimodal Interfaces, you will connect these hardened, observable agents to external tool servers, remote agent fleets, and live user interfacesβ€”starting in Module 27 with the Model Context Protocol (MCP)!

πŸ“–

26: Observability & Cloud Trace(Theory & Overview)

Part 4: Production Readiness β€’ Module 26

Overall Course Progress:
0%(0/98)
Next Step: Challenge Lab πŸ§ͺ β†’