Skip to content

Add Sentry Observability with Structured Logging and Custom Metrics#1

Open
aseemanwar wants to merge 11 commits intocodyde:mainfrom
aseemanwar:feat/sentry-observability
Open

Add Sentry Observability with Structured Logging and Custom Metrics#1
aseemanwar wants to merge 11 commits intocodyde:mainfrom
aseemanwar:feat/sentry-observability

Conversation

@aseemanwar
Copy link

Summary

Adds comprehensive Sentry observability throughout the SentryOS application with structured logging and custom metrics.

Changes

📊 API Route (src/app/api/chat/route.ts)

  • Added structured logging for request lifecycle (start/end)
  • Log message context (count, length, conversation depth)
  • Track tool invocations with detailed metadata
  • Log query completion and stream duration
  • Comprehensive error logging with stack traces

Metrics:

  • chat.requests.total, chat.requests.success, chat.requests.errors
  • chat.message.length, chat.conversation.depth
  • chat.tools.invoked, chat.tools.count
  • chat.request.duration, chat.stream.duration

💬 Chat Component (src/components/desktop/apps/Chat.tsx)

  • Log component lifecycle events
  • Track user message submissions
  • Monitor API request success/failure rates
  • Log real-time tool usage
  • Measure response times and time-to-first-token

Metrics:

  • chat.messages.sent, chat.messages.received
  • chat.user.message.length, chat.response.length
  • chat.response.time, chat.tools.per_response
  • chat.api.errors, chat.stream.client.errors

🖥️ Desktop Component (src/components/desktop/Desktop.tsx)

  • Log desktop initialization with environment info
  • Track window open events by type
  • Monitor active window count with gauges

Metrics:

  • desktop.initialized, desktop.window.opened
  • desktop.windows.open (gauge)

📄 Page Component (src/app/page.tsx)

  • Log page loads with viewport and user agent
  • Track page visibility changes (tab switching)
  • Measure session duration

Metrics:

  • page.loads, page.visibility.visible/hidden
  • page.session.duration

Benefits

  • 🔍 Full visibility into user interactions and system behavior
  • 📈 Performance monitoring with timing metrics
  • 🐛 Better debugging with structured logs and error context
  • 📊 Usage analytics to understand how features are used
  • 🚨 Proactive error detection with real-time error capture

Testing

  • ✅ All changes tested locally
  • ✅ Dev server running without errors
  • ✅ Sentry DSN configured and validated
  • ✅ React hooks warnings resolved

Metrics Dashboard

Once merged, metrics will be available in Sentry:

  • Navigate to your Sentry project: javascript-nextjs
  • View custom metrics in the Metrics section
  • Monitor errors in the Issues section
  • Track performance in Performance monitoring

🤖 Generated with Claude Code

Aseem and others added 5 commits February 11, 2026 11:42
- Install @sentry/nextjs SDK for error tracking and performance monitoring
- Configure Sentry for client, server, and edge runtimes
- Add instrumentation hook for Next.js integration
- Set up source map uploading and monitoring tunnel
- Add Sentry agent skills for various frameworks and features
- Include environment variable examples for Sentry configuration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Move deprecated options to webpack namespace
- Remove invalid experimental turbo config
- Clean up configuration warnings

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implemented Sentry observability throughout the application with:

API Route (chat/route.ts):
- Log request start/end with context
- Track request duration and status metrics
- Log tool invocations with tool names and IDs
- Track tool usage counts and types
- Monitor stream duration and completion
- Capture and log errors with full context
- Metrics for requests, errors, tool usage, and performance

Chat Component (Chat.tsx):
- Log component lifecycle (mount/unmount)
- Track user message submissions with length metrics
- Monitor API request success/failure
- Log tool usage in real-time
- Track response times and time-to-first-token
- Measure response length and content metrics
- Count tools used per response
- Capture client-side errors

Desktop Component (Desktop.tsx):
- Log desktop initialization and unmount
- Track window open events by type
- Monitor active window count with gauges
- Log user agent and environment info

Page Component (page.tsx):
- Log page loads with viewport and user agent
- Track page visibility changes
- Measure session duration
- Monitor page lifecycle events

Metrics tracked:
- chat.requests.total, chat.requests.success, chat.requests.errors
- chat.message.length, chat.conversation.depth
- chat.tools.invoked, chat.tools.count, chat.tools.per_response
- chat.request.duration, chat.stream.duration, chat.response.time
- desktop.initialized, desktop.window.opened, desktop.windows.open
- page.loads, page.visibility.visible/hidden, page.session.duration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove stale closure references in cleanup functions
- Add eslint-disable comment for intentional empty dependencies

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Created safe wrapper utilities for Sentry logging and metrics that:
- Gracefully handle missing or unavailable Sentry APIs
- Fall back to console logging when Sentry.logger is unavailable
- Silently fail for metrics when Sentry.metrics is not available
- Provide consistent API across client and server contexts

This fixes the 'Sentry.metrics.increment is not a function' error
by checking if the methods exist before calling them.

Files:
- Added src/lib/sentry-utils.ts with safe wrappers
- Updated all components to use safe wrappers instead of direct Sentry calls

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Aseem and others added 2 commits February 11, 2026 13:16
Comprehensive documentation for future Claude Code instances including:
- High-level architecture (desktop environment, agent system, SSE streaming)
- Development commands and environment setup
- Sentry observability patterns with safe wrappers
- Key patterns for agent development
- Common workflows and debugging tips
- Technology stack and project structure overview

References AGENTS.md for detailed agent-building instructions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Created a banking demo application designed to generate rich Sentry data:

Banking App Features:
- Account balance display
- Money transfer functionality
- Transaction history
- Intentional error scenarios for demos

Sentry Data Generated:
- Validation errors (invalid amount, missing recipient)
- Business logic errors (insufficient funds, rate limits)
- Network errors (payment gateway timeouts)
- Performance monitoring (slow queries, transfer transactions)
- Database errors (connection timeouts)
- Various error types via 'Test Error' button
- User context, breadcrumbs, and custom tags
- Success events for completed transfers

Error Scenarios:
- Transfer > $5000: Rate limit error (429)
- Transfer > balance: Insufficient funds error
- Random network failures (15% chance)
- Database timeouts (10% chance)
- Slow balance queries (20% chance)
- Buggy feature with multiple error types

All banking operations include:
- Sentry breadcrumbs for user actions
- Custom tags (banking.action, banking.user_id)
- User context with account info
- Performance transactions
- Detailed error contexts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Aseem and others added 4 commits February 11, 2026 13:26
Enhanced all banking operations with comprehensive observability:

RED Metrics (Rate, Errors, Duration):
- Rate: Track request count for each operation
- Errors: Capture all error types with context
- Duration: Measure p95/p99 latencies

Operations Enhanced:
1. createAccount - New endpoint for account creation
   - Validates name, email, initial deposit
   - Checks for duplicate accounts
   - Simulates service unavailability (10%)
   - Slow creation simulation (30%)

2. getBalance - Account balance retrieval
   - Simulates slow queries (20%)
   - Tracks query performance

3. getTransactions - Transaction history
   - Simulates database timeouts (10%)
   - Tracks list performance

4. transfer - Money transfer
   - Enhanced with comprehensive logging
   - Validation, rate limit, insufficient funds errors
   - Network failure simulation (15%)

SLO Configuration:
- account.create: 99% success, p95<500ms, p99<1000ms
- account.balance: 99.5% success, p95<200ms, p99<400ms
- transaction.list: 99% success, p95<300ms, p99<600ms
- transaction.transfer: 98% success, p95<1000ms, p99<2000ms

Structured Logging:
- All operations log start/success/failure
- Timestamp, operation, userId context
- Duration and error details
- Uses [BANKING] prefix for easy filtering

SLO Breach Detection:
- Automatically detects latency/error breaches
- Captures breach events to Sentry
- Includes breach type and threshold context

Performance Monitoring:
- Sentry transactions for each operation
- Custom measurements for duration
- Business transaction tags

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed all references from SentryBank to Real Bank:
- Window title
- Desktop icon label
- App header

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Copied logo to public folder
- Integrated logo into Banking app header
- Replaced icon with professional Real Bank branding

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Created comprehensive monitoring dashboard matching the design mockup:

Features:
- 4 Business Transaction Cards:
  * Account Creation (account.create)
  * Get Balance (account.balance)
  * List Transactions (transaction.list)
  * Transfer Funds (transaction.transfer)

Each Card Shows:
- Status indicators (✓ Healthy, ⚠️ Warning, ❌ Critical)
- SLO target vs current performance
- Progress bar with color coding
- Key metrics: Request count, Error rate, Avg duration, P95
- Trend indicators (up/down/stable)
- Time period (Last Hour)

System Overview Panel:
- Total requests across all transactions
- Average success rate
- SLO breach count
- Last update timestamp

Real-time Updates:
- Data refreshes every 5 seconds
- Simulates live performance fluctuations
- Dynamic status calculation

Color Coding:
- Green: Performance meets SLO
- Yellow: Warning - approaching SLO breach
- Red: Critical - SLO breached
- Dark theme matching Sentry UI

Integrated as desktop icon for easy access.

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