You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable operational visibility into portfolio app health, performance, and failures through health check endpoints, structured logging, and failure mode definitions. This stage provides the foundation for proactive monitoring and incident response, allowing the team to detect, diagnose, and resolve issues quickly before they impact users.
Objectives
Implement a health check API endpoint that reports app status, environment, and critical resource state
Add structured logging helpers that output machine-readable logs for monitoring systems
Define failure modes (healthy/degraded/unhealthy) and their indicators
Create runbooks for common operational scenarios (degradation, deployment failure, incident response)
Enable observability integration with Vercel and future external monitoring systems
Scope
Files to Create
src/app/api/health/route.ts — Health check endpoint that verifies critical app resources and returns structured status
Endpoint: GET /api/health
Returns: JSON with status, environment, commit, build time, project count, timestamp
Status codes: 200 (healthy), 503 (degraded), 500 (unhealthy)
No caching (revalidate=0)
src/lib/observability.ts — Structured logging helpers for application logging
Exports LogEntry interface with level, message, context, timestamp, environment
Exports log() function that outputs JSON-formatted logs to console
Supports: info, warn, error, debug log levels
Includes context object for structured data (e.g., user ID, operation, timing)
Files to Update
next.config.ts — Configure error handling and logging
Add error page configuration if needed
Document any monitoring hooks or logging integrations
package.json — Add any observability dependencies if needed
May add: pino, bunyan, or similar structured logging (evaluate based on bundle impact)
Note: Prefer native console.log with JSON.stringify for lightweight approach
src/app/layout.tsx — May add error boundary or observability provider
Import observability helpers where needed
Document any new instrumentation
Dependencies to Add
None required (uses native Node.js console for JSON logging)
Optional: Lightweight structured logging package if evaluation determines benefit
Dependencies to Remove
None
Design & Architecture
System Overview
The observability system consists of three components:
All failure scenarios tested and logged appropriately
Structured logs verified as valid JSON
next.config.ts documents observability setup
pnpm verify passes with no new issues
Ready for documentation and runbook creation
Testing Strategy
Unit Tests
Health check endpoint returns correct status codes
Test file: src/app/api/health/__tests__/route.test.ts (future)
Coverage: Happy path (healthy), degraded (no projects), error cases
Mocks: PROJECTS registry, environment variables
Structured logging formats correctly
Test file: src/lib/__tests__/observability.test.ts (future)
Coverage: All log levels, context serialization, timestamp generation
Verify JSON.parse() works on output
Integration Tests
Health check with live project registry
Test: Load actual projects, verify count matches
Verify environment variables from test environment
E2E / Manual Testing
Health endpoint accessible via curl
Steps: curl http://localhost:3000/api/health
Expected: Valid JSON response with 200 status
Degradation detection works
Steps: Remove all projects, rebuild, test endpoint
Expected: 503 status, degraded message
Logging appears in console
Steps: Trigger errors in app, observe console output
Expected: Each error produces parseable JSON log entry
Test Commands
# Build verification
pnpm build
# Local verification (full suite including new health checks)
pnpm verify
# Type checking
pnpm typecheck
# Linting
pnpm lint
# Test health endpoint
curl http://localhost:3000/api/health
# Start server and monitor logs
pnpm start
Type: Feature / Enhancement / Implementation
Phase: Phase 4 — Enterprise-Grade Platform Maturity
Stage: 4.3
Linked Issue: Stage 4.3: Observability & Operational Readiness — Docs (#63)
Duration Estimate: 4–6 hours
Assignee: Bryce Seefieldt
Overview
Enable operational visibility into portfolio app health, performance, and failures through health check endpoints, structured logging, and failure mode definitions. This stage provides the foundation for proactive monitoring and incident response, allowing the team to detect, diagnose, and resolve issues quickly before they impact users.
Objectives
Scope
Files to Create
src/app/api/health/route.ts— Health check endpoint that verifies critical app resources and returns structured statusGET /api/healthsrc/lib/observability.ts— Structured logging helpers for application loggingLogEntryinterface with level, message, context, timestamp, environmentlog()function that outputs JSON-formatted logs to consoleFiles to Update
next.config.ts— Configure error handling and loggingpackage.json— Add any observability dependencies if neededpino,bunyan, or similar structured logging (evaluate based on bundle impact)src/app/layout.tsx— May add error boundary or observability providerDependencies to Add
Dependencies to Remove
Design & Architecture
System Overview
The observability system consists of three components:
graph TD App["Portfolio App<br/>(Next.js)<br/><br/>Pages, components,<br/>API routes"] Health["Health Check Endpoint<br/>GET /api/health<br/><br/>Status: 200/503/500<br/>Metrics<br/>Environment"] Logging["Structured Logging<br/>src/lib/observability.ts<br/><br/>JSON log output<br/>Log levels<br/>Context metadata"] Monitoring["Vercel Logs &<br/>External Monitoring System"] App --> Health App --> Logging Health --> Monitoring Logging --> MonitoringHealth Check Endpoint Design
Structured Logging Design
Failure Modes Definition
Key Design Decisions
Health Check Approach: Simple HTTP endpoint (not gRPC, not custom protocol)
Structured Logging: JSON output to console (not external package)
Failure Mode Detection: Application-level checks (not infrastructure)
Implementation Tasks
Phase 1: Health Check Endpoint (1–2 hours)
[Description: Implement the
/api/healthendpoint with status detection and environment metadata]Tasks
Create
src/app/api/health/route.tsExtract build metadata from environment
VERCEL_GIT_COMMIT_SHA,VERCEL_ENV,BUILD_TIMETest health endpoint locally
curl http://localhost:3000/api/healthVerify TypeScript and linting
anytypes; proper error handlingSuccess Criteria for Phase 1
src/app/api/health/route.tsexists and exports GET handlerpnpm typecheckpassespnpm lintpassesPhase 2: Structured Logging (1–2 hours)
[Description: Implement structured logging helpers and integrate into error handling paths]
Tasks
Create
src/lib/observability.tsIntegrate logging into key error paths
Test structured logging output
Verify TypeScript and formatting
anytypesSuccess Criteria for Phase 2
src/lib/observability.tsexists and exports LogEntry and log()pnpm typecheckpassespnpm format:checkpassesPhase 3: Verification & Testing (1–2 hours)
[Description: Verify health checks, test failure scenarios, document findings]
Tasks
Run health endpoint in production mode
pnpm build && pnpm startcurl http://localhost:3000/api/healthTest failure scenarios
Verify logging in build output
Document observability in next.config.ts comments
Run full verification
pnpm verifySuccess Criteria for Phase 3
pnpm verifypasses with no new issuesTesting Strategy
Unit Tests
Health check endpoint returns correct status codes
src/app/api/health/__tests__/route.test.ts(future)Structured logging formats correctly
src/lib/__tests__/observability.test.ts(future)Integration Tests
E2E / Manual Testing
Health endpoint accessible via curl
curl http://localhost:3000/api/healthDegradation detection works
Logging appears in console
Test Commands
Acceptance Criteria
This stage is complete when:
src/app/api/health/route.tsendpoint fully functionalsrc/lib/observability.tsprovides structured loggingpnpm verifypasses (lint, format, typecheck, build all succeed)pnpm typecheckpnpm lintanytypes)pnpm buildCode Quality Standards
All code must meet:
anytypes unless documentedDependencies & Blocking
Depends On
Blocks
Related Work
Performance & Optimization Considerations
Security Considerations
Effort Breakdown
Success Verification Checklist
Before marking this stage complete:
pnpm verifypassesTroubleshooting & Known Issues
Common Issues & Fixes
Issue: Health endpoint returns 500 even though projects are loaded
Issue: Structured logs not appearing in Vercel console
console.log()directly; verify JSON is valid before outputjqorJSON.parse()Issue: Environment variables undefined in production
BUILD_TIMEorVERCEL_GIT_COMMIT_SHAenv varsDocumentation Requirements
By the time this stage is complete:
Notes & Assumptions
VERCEL_ENVandVERCEL_GIT_COMMIT_SHAenv varsBUILD_TIMEcan be injected during build in next.config.tsRelated Issues
Review Checklist (for Reviewer)
any)Completion Verification
pnpm test(when tests added)pnpm verifymainDate Completed: [YYYY-MM-DD]
Completed By: [Name/GitHub handle]
Post-Implementation Notes
[Any learnings, gotchas, or notes for future stages]
Milestone: Phase 4 — Enterprise-Grade Platform Maturity
Labels:
enhancement,phase-4,stage-4.3,observability,operationsPriority: High