Skip to content

Add Sentry structured logging and custom metrics#5

Open
alea-a wants to merge 2 commits intocodyde:mainfrom
alea-a:feat/sentry-observability
Open

Add Sentry structured logging and custom metrics#5
alea-a wants to merge 2 commits intocodyde:mainfrom
alea-a:feat/sentry-observability

Conversation

@alea-a
Copy link

@alea-a alea-a commented Feb 11, 2026

Summary

This PR enhances the SentryOS application with comprehensive observability by adding Sentry structured logging and custom metrics throughout the codebase.

Changes

New Files

  • src/lib/sentry-utils.ts - Centralized utility module with helper functions for logging, metrics, breadcrumbs, and a Timer class for performance measurements

Enhanced Files

  • WindowManager - Instrumented all window lifecycle events (open, close, minimize, maximize, restore, focus)
  • Chat Component - Added session tracking, message logging, tool execution metrics, and stream performance tracking
  • Chat API Route - Added request tracking, streaming metrics, and enhanced error context
  • Desktop Component - Added logging for icon clicks and app launches
  • SentryTest Component - Enhanced with structured logging, breadcrumbs, and metrics
  • Sentry Test API - Added request tracking and enhanced error context

Features Implemented

📝 Structured Logging

  • Using Sentry.logger with appropriate log levels (debug, info, warning, error)
  • Contextual information attached to all logs
  • Replaced console.log/error with structured logging

📊 Custom Metrics

  • Counters: Window operations, chat messages, tool executions, desktop interactions
  • Distributions: API duration, stream duration, tool execution time
  • Gauges: Window count, active chat sessions

🍞 Breadcrumbs

  • User journey tracking across all interactions
  • Window management actions
  • Chat message flow
  • Desktop icon clicks

🎯 Enhanced Error Context

  • Custom tags for filtering and categorization
  • Contextual data for better debugging
  • Request IDs for correlation
  • Performance timing information

Metrics Tracked

Window Management:

  • window.open, window.close, window.minimize, window.maximize, window.restore, window.focus
  • window.count (gauge)

Chat Interactions:

  • chat.message.sent, chat.response.received, chat.tool.execution
  • chat.api.duration, chat.stream.duration (distributions)
  • chat.active_sessions (gauge)

Desktop:

  • desktop.icon.click, desktop.app.launch

Testing

All changes have been implemented following best practices:

  • ✅ Privacy-conscious (message previews limited to 50 characters)
  • ✅ Performance-aware (debug-level for high-frequency events)
  • ✅ Structured with consistent naming conventions (kebab-case)
  • ✅ Enhanced error tracking with full context

Verification

To verify the changes:

  1. Start the development server
  2. Interact with the application (open windows, send chat messages, etc.)
  3. Check Sentry dashboard for:
    • Structured logs in the Logs section
    • Custom metrics in the Metrics section
    • Enhanced errors with breadcrumbs in the Issues section
    • Performance distributions

🤖 Generated with Claude Code

- Created sentry-utils.ts with helper functions for logging, metrics, and breadcrumbs
- Instrumented WindowManager with lifecycle event logging (open, close, minimize, maximize, etc.)
- Added comprehensive Chat component instrumentation with session tracking, message logging, and tool execution metrics
- Enhanced Chat API route with request tracking, streaming metrics, and error context
- Added Desktop component logging for icon clicks and app launches
- Enhanced SentryTest component with structured logging, breadcrumbs, and metrics
- Updated sentry-test API route with enhanced error context and logging

Features implemented:
- Structured logging using Sentry.logger (debug, info, warning, error levels)
- Custom metrics using Sentry.metrics (counters, distributions, gauges)
- Breadcrumbs for user journey tracking
- Enhanced error context with tags and custom data
- Performance measurement with Timer utility class

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant