Overview
The Observatory widget provides a real-time, in-browser visualization of your AI agent’s execution. It displays runs, steps, and tool calls as they happen, making it easy to debug and monitor your agent during development. The widget is built with Preact and uses Shadow DOM for style isolation, ensuring it won’t conflict with your application’s styles.The widget is designed for local development and requires local mode to be enabled.
Installation
How It Works
The widget architecture consists of several key components:Shadow DOM Isolation
The widget uses Shadow DOM to prevent style conflicts:WebSocket Connection
The widget automatically discovers and connects to the local WebSocket server:- Port Scanning: Scans preferred ports (8081, 3001, 3002, etc.)
- Connection: Connects to the first available server
- Initial State: Receives the current data store on connection
- Real-time Updates: Subscribes to new runs, steps, and tool calls
State Management
The widget uses Preact signals for reactive state:Usage
Basic Setup
With the auto-init script, the widget appears automatically in development:app/layout.tsx
Manual Control
For more control, use the programmatic API:Conditional Loading
Only load the widget in specific environments:Customization
Debug Mode
Enable debug logging to see widget internals:- WebSocket connection attempts
- Port scanning results
- Data synchronization events
Position and Size
The widget is draggable and can be docked to screen edges:- Drag: Click and drag the widget to reposition
- Snap to corner: Release near a corner to snap
- Dock to edge: Drag to screen edge to dock
- Expand/Collapse: Click to toggle the detailed view
Widget State
The widget state is persisted in localStorage:Features
Run Viewer
The widget displays:- Runs List: All agent runs with status and duration
- Steps: Individual steps within each run
- Tool Calls: Tool invocations with inputs and outputs
- Failures: Quick access to failed runs
Real-time Updates
New data appears instantly as your agent executes:Failure Notifications
The widget highlights when failures occur:- Visual indicator: Red background on widget icon
- Badge: Failure count badge
- Quick access: Click to jump to failures list
Data Inspection
Expanded view shows detailed information:- Metadata: Trace ID, span ID, parent relationships
- Attributes: All span attributes and metadata
- Events: Span events with timestamps
- Status: Success/error status with codes
- Timing: Duration and timestamps
API Reference
initWidget(options)
Initialize the widget programmatically.cleanup()
Remove the widget from the DOM.Global API
When using the auto script, a global API is available:WebSocket Protocol
The widget communicates with the local server using WebSocket:Server → Client Messages
Initial StoreClient → Server Messages
Anonymous EventsTroubleshooting
Widget Not Appearing
Check WebSocket Connection
Open browser console and look for:If you see an error, ensure local mode is enabled in instrumentation.
Widget Stuck Loading
- Ensure your Next.js app is running with instrumentation enabled
- Check that local mode is active:
registerOTelTCC({ local: true }) - Verify no firewall is blocking localhost WebSocket connections
Style Conflicts
The widget uses Shadow DOM to prevent style conflicts, but if you experience issues:- Check for global styles affecting Shadow DOM (rare)
- Ensure you’re using a modern browser with Shadow DOM support
- Check for
!importantrules that might leak into Shadow DOM
Performance Issues
If the widget impacts performance:- Limit the number of concurrent runs displayed
- Use the cleanup function when navigating away
- Consider disabling in production environments
Best Practices
Only use in development
Only use in development
Always gate the widget behind environment checks:
Clean up properly
Clean up properly
If initializing manually, always cleanup:
Use debug mode during setup
Use debug mode during setup
Enable debug mode when first setting up to diagnose connection issues:
Next Steps
Local Mode
Learn how to set up local-first observability
OpenTelemetry
Understand the OpenTelemetry integration
