Overview
Local mode enables you to use Observatory without creating an account or providing an API key. All telemetry data is processed locally and displayed in a real-time widget in your browser. This is perfect for:- Development and testing
- Prototyping AI agents
- Debugging without cloud dependencies
- Working offline
Local mode requires Next.js and the
@contextcompany/widget package to visualize data in your browser.How It Works
When you enable local mode:- WebSocket Server: Observatory starts a local WebSocket server on an available port (tries ports 8081, 3001, 3002, etc.)
- Local Exporter: The
LocalSpanExportercollects OpenTelemetry spans and stores them in memory - Widget Connection: The browser widget connects to the WebSocket server to receive real-time updates
- Data Store: All runs, steps, and tool calls are organized by trace ID in a local data store
Local mode uses a
SimpleSpanProcessor for immediate processing rather than batching spans. This provides instant feedback during development.Setup
Configure instrumentation
Create or update your
instrumentation.ts file in the root of your Next.js project:instrumentation.ts
Configuration Options
Register Options
TheregisterOTelTCC function accepts these options:
Widget Options
If you’re manually initializing the widget (not using the auto script):WebSocket Server
Observatory automatically starts a WebSocket server for local communication:- Port Selection: Tries preferred ports (8081, 3001, 3002, 3003, 3004, 3005, 8000, 8001, 8080)
- Fallback: Uses an ephemeral port if all preferred ports are taken
- Auto-Discovery: The widget automatically scans these ports to find the server
Debug Mode
Enable debug logging to see WebSocket connection details:Data Storage
Local mode stores data in memory using theLocalSpanExporter:
Data Structure
Data Lifecycle
- Collection: Spans are collected as they complete
- Organization: Organized by trace ID (one trace per agent run)
- Persistence: Data persists in memory until server restart
- Reset: Use
tccLocalExporter.reset()to clear the data store
Data is only stored in memory and is lost when you restart your development server.
Anonymous Telemetry
Local mode collects anonymous usage metrics to help improve Observatory:- Agent run completion events
- Step and tool call events
- Widget interaction events
- No personally identifiable information is collected
local_mode_startagent_run_end(with status code and duration)step_end(with status code and duration)tool_call_end(with status code and duration)widget_expand_event
Troubleshooting
Widget Not Appearing
- Check that instrumentation is enabled in
next.config.ts - Verify the script tag is in your layout
- Look for WebSocket errors in the browser console
- Enable debug mode to see connection attempts
Port Conflicts
If all preferred ports are taken:Connection Refused
Ensure your Next.js app is running in Node.js runtime:HMR Issues
Local mode uses a singleton pattern to prevent multiple exporters during Hot Module Replacement:Next Steps
Widget
Learn how to use the real-time visualization widget
OpenTelemetry
Understand the OpenTelemetry integration
