- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5
 
Implement structured JSON logging with Pino for enhanced observability #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
          ✅ Deploy Preview for mcp-storybook ready!
 To edit notification comments on pull requests, go to your Netlify project configuration.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a comprehensive structured JSON logging system using Pino, replacing all console.* calls with production-ready logging that supports user/session tracing and log aggregation.
- Replaces plaintext console logging with structured JSON logging for enhanced observability
 - Enables user and request tracing with contextual information (userId, model, operation)
 - Provides dual-mode logger supporting both server-side (Pino) and browser environments
 
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description | 
|---|---|
| src/lib/logger.ts | New dual-mode logger implementation with Pino for server-side and structured console for browser | 
| src/routes/api/chat.ts | Enhanced API route with contextual logging including userId, model, and operation tracking | 
| src/routes/api/models.ts | Updated error logging with structured context for model fetching operations | 
| src/routes/api/container-file.ts | Added structured logging for file operations with fileId and containerId context | 
| src/lib/streaming.ts | Updated streaming functionality to use structured logging with messageId tracking | 
| src/hooks/useStreamingChat.ts | Replaced console calls with structured logging throughout chat functionality | 
| src/hooks/useLocalStorage.ts | Added structured error logging for localStorage operations | 
| src/hooks/useDisconnectServer.ts | Updated server disconnection error logging | 
| src/components/ServerSelector.tsx | Enhanced server management logging with structured context | 
| src/components/CodeInterpreterMessage.tsx | Added structured logging for image loading errors | 
| package.json | Added Pino dependencies for production logging | 
| src/lib/streaming.test.ts | Updated test to mock logger instead of console | 
| src/hooks/useDisconnectServer.tsx.test.tsx | Removed console error assertions to match new logging approach | 
- Install pino and pino-pretty dependencies - Create logger utility with browser/server compatibility - Replace all console.* calls with structured logging - Add userId and context to API route logs - Update tests to not depend on console.* calls - Tests pass (same baseline as before) - Linting and build successful Co-authored-by: nickytonline <[email protected]>
b816d42    to
    9a5eaff      
    Compare
  
    
Overview
This PR implements structured JSON logging throughout the application using Pino, replacing all
console.*calls with a production-ready logging system that supports user/session tracing and log aggregation.Problem
The application was logging in plaintext without any structured context, making it difficult to:
Before:
Solution
Implemented a comprehensive structured logging system using Pino that:
userId,model, and contextual information for tracking user sessionsAfter:
Key Changes
Logger Implementation (
src/lib/logger.ts)ENABLE_TEST_LOGGING)API Routes Enhanced with Context
src/routes/api/chat.ts- Added userId, model, and operation contextsrc/routes/api/models.ts- Structured error loggingsrc/routes/api/container-file.ts- File operation logging with IDsCore Libraries Updated
src/lib/streaming.ts- Stream processing with messageId trackingTest Updates
console.*assertionsExample Output
Development (pretty-printed):
Production (JSON for aggregation):
{"level":"info","time":1704789045000,"service":"mcp-app-demo","module":"api-chat","userId":"[email protected]","model":"gpt-4o","messageCount":3,"toolCount":2,"operation":"chat-request","msg":"Creating OpenAI response"}Benefits
Configuration
Set log level via environment variable:
LOG_LEVEL=debug # Options: trace, debug, info, warn, error, fatalTesting
Closes #[issue-number]
Original prompt
This section details on the original issue you should resolve
<issue_title>structured logging</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
currently the application is logging in plaintext without any identification of which user's request the message is related to.
Describe the solution you'd like
Describe alternatives you've considered
Explain any additional use-cases
If there are any use-cases that would help us understand the use/need/value please share them as they can help us decide on acceptance and prioritization.
Additional context
Add any other context or screenshots about the feature request here.
</issue_description>
Comments on the Issue (you are @copilot in this section)
@nickytonline replace all console.* with structured logging as defined in the PRDPRD: Structured Logging in TypeScript Applications
Overview
This document provides guidance for implementing structured logging in TypeScript applications using Pino, a high-performance JSON logger optimized for Node.js applications.
Why Structured Logging?
Benefits:
Use Cases:
Implementation Guide
Step 1: Install Dependencies
Package versions:
pino: ^8.16.0 or later (production logger)pino-pretty: ^10.2.0 (development formatting, optional)Step 2: Create Logger Configuration
Step 3: Basic Usage
Step 4: Log Levels
Use appropriate log levels for different scenarios:
Step 5: Contextual Logging
Create loggers with persistent context for related operations: