Module 26: Advanced Observability & Enterprise AgentOps

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-levelBasePluginguardrails for Responsible AI safety. Here in Module 26, we apply that exact sameBasePluginarchitectureβ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:
- Local-First In-Process Plugins (
BasePlugin): Lightweight, zero-dependency interceptors for local debugging, alerting, and metrics collection. - Native OpenTelemetry (OTel): Standardized distributed tracing that exports performance data and spans directly to Google Cloud Trace and Cloud Monitoring.
- 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 β
βββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ
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 withgoogle-agents-cli. As you will build in Module 30.4 (Cloud Telemetry, BigQuery Analytics & Cost Control), scaffolded FastAPI entrypoints automatically configureget_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-inBigQueryAgentAnalyticsPlugin(--bq-analytics).
Key Takeawaysβ
- Separation of Concerns: Business logic stays in
Agent(instruction=...)and tools; operational monitoring stays inBasePluginand 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 viaget_gcp_exporters()in standalone scripts or zero-boilerplateotel_to_cloud=True+--bq-analyticsin Module 30.4.
π§ Interactive Knowledge Checkβ
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)!