Telemetry & Observability Pipeline
Relevant source files
The following files were used as context for generating this wiki page:
The Telemetry & Observability Pipeline provides comprehensive tracking and analysis of AI activity, token usage, and costs across the Speakeasy organization. It captures every tool call, permission change, and access event to ensure full visibility into agent behavior and system performance. The pipeline records granular data including full transcripts, tool effectiveness, and cost telemetry to enable deep-dive analysis of expensive sessions and budget management.
Sources: README.md:33-35, README.md:40-42, CONTRIBUTING.md:104-106
Core Architecture and Data Storage
The observability stack uses a foundation of OpenTelemetry (OTEL) for instrumentation and ClickHouse for high-volume telemetry storage.
ClickHouse Integration
ClickHouse acts as the primary analytical database for telemetry data, including agent session transcripts and cost metrics. Developers use the Squirrel query builder exclusively for ClickHouse queries within the telemetry package. The local development environment facilitates seeding ClickHouse with sample data, such as ~180 agent sessions with full transcripts, to simulate a realistic working environment.
Sources: README.md:42, REVIEW.md:204-207, CONTRIBUTING.md:104-108
OpenTelemetry (OTEL) Foundation
The pipeline uses OpenTelemetry providers for tracing and metrics. Testing environments utilize specific providers like testenv.NewMeterProvider(t) and testenv.NewTracerProvider(t) rather than discarding telemetry data.
Sources: REVIEW.md:94-96, README.md:42
Telemetry Data Flow
This diagram illustrates the flow of events from an agent interaction through the observability pipeline to final storage and analysis.
The diagram shows how agent sessions are instrumented via OpenTelemetry, routed based on data type, and persisted in ClickHouse for consumption by the dashboard and MCP tools.
Sources: README.md:40-42, REVIEW.md:204-207, CONTRIBUTING.md:104-108
Observability Dimensions and Attributes
The pipeline categorizes telemetry using specific dimensions and attributes to distinguish between different sources and targets of AI activity.
Source Dimensions
To analyze adoption and usage, the system tracks complementary dimensions:
gram.hook.source: Identifies the agent or client that invoked the platform (caller).gram.tool_call.source: Identifies the downstream Model Context Protocol (MCP) server that handled the call (callee).
Custom Attributes
SDK users attach arbitrary key-value attributes to logs. These are prefixed with @ (e.g., @user, @tenant.id) to distinguish them from standard system attributes.
Sources: server/internal/assistants/managed_assistant_instructions.txt:27-28, server/internal/assistants/managed_assistant_instructions.txt:30-33
| Attribute Type | Format | Example | Description |
|---|---|---|---|
| System Attribute | Bare string | status_code | Standard metrics generated by the platform. |
| Custom Attribute | @ prefix | @session.id | User-defined metadata attached via SDK. |
| Hook Source | Dimension | gram.hook.source | Used for tracking client adoption. |
| Tool Call Source | Dimension | gram.tool_call.source | Used for per-MCP server usage analysis. |
Sources: server/internal/assistants/managed_assistant_instructions.txt:27-33
Logging Conventions and Utilities
The system enforces strict logging standards to ensure traces and errors are easily searchable and context-aware.
Structured Logging
All logs must use the slog package with context-aware methods like InfoContext and ErrorContext. Errors are included using attr.SlogError(err) to maintain consistency across the codebase.
Observability-Aware Cleanup
The pipeline utilizes specific deferred cleanup helpers to manage errors during resource closing:
o11y.LogDefer(ctx, logger, ...): Used when a failure to close a resource (like a database connection) must be recorded.o11y.NoLogDefer(...): Used when errors are inconsequential, such as response body closes or transaction rollbacks.
Sources: REVIEW.md:67-75, REVIEW.md:85-88
Watchdog and Risk Monitoring
Watchdog acts as a real-time inspection layer within the telemetry pipeline, scanning chat messages and agent actions for security risks.
Findings and Alerts
Watchdog categorizes findings into detector families:
- gitleaks: Detects secrets like API keys and tokens.
- presidio: Identifies PII such as emails or SSNs.
- prompt_injection: Detects LLM injection attempts.
- shadow_mcp: Identifies calls to unapproved MCP servers.
Data Redaction and Fingerprinting
For security, sensitive matches (e.g., secrets) are replaced with match_redacted, an opaque token containing a length and SHA256-prefix fingerprint. This allows the system to dedupe leak counts across chats without exposing the raw secret.
Sources: server/internal/assistants/managed_assistant_instructions.txt:36-41, server/internal/assistants/managed_assistant_instructions.txt:43-45, server/internal/plugins/platform_mcp_skills/summarize-critical-watchdog-findings/SKILL.md:44-48
This diagram demonstrates the real-time scanning process where Watchdog intercepts content, redacts sensitive findings, and logs fingerprints to telemetry storage.
Sources: server/internal/assistants/managed_assistant_instructions.txt:36-45
Summary of Monitoring Capabilities
The Telemetry & Observability Pipeline enables both operational and security-focused monitoring. It provides the data necessary for budget management by tracking costs per session and tool effectiveness. Simultaneously, it maintains a secure environment by integrating Watchdog findings directly into the observability flow, ensuring that every sensitive event is logged, searchable, and actionable without compromising confidential data.
Sources: README.md:33-42, server/internal/assistants/managed_assistant_instructions.txt:43-45