Skip to content

Add Module 1: Observability Primitives & Instrumentation#6

Merged
gwho merged 1 commit intomasterfrom
claude/fastapi-logfire-setup-wPLhv
Dec 25, 2025
Merged

Add Module 1: Observability Primitives & Instrumentation#6
gwho merged 1 commit intomasterfrom
claude/fastapi-logfire-setup-wPLhv

Conversation

@gwho
Copy link
Owner

@gwho gwho commented Dec 25, 2025

Implement comprehensive FastAPI + Logfire observability lab with:

Phase 1 - Service Skeleton:

  • Initialize FastAPI application with auto-instrumentation
  • Configure Logfire with service name 'observability-lab-01'
  • Apply logfire.instrument_fastapi(app) hook for automatic tracing
  • Add fallback console-only mode for local development

Phase 2 - Structural Depth:

  • Implement GET /process-order/{order_id} endpoint
  • Use structured logging (key-value pairs) instead of string formatting
  • Create manual 'verify_inventory' span for granular tracing
  • Simulate database latency with random sleep (0.1s-0.5s)
  • Log warnings for slow queries (>0.4s threshold)
  • Attach metadata to spans for queryability

Phase 3 - Verification Challenge:

  • Add conditional error injection for order_id='error-test'
  • Raise HTTPException with 500 status code
  • Provide structured error logging with context
  • Enable full exception trace correlation

Testing & Verification:

  • All endpoints tested and verified working
  • Regular order processing with timing information
  • Slow query detection and warning logging
  • Error case with proper exception handling
  • Comprehensive test results documented

Documentation:

  • Complete README with setup instructions
  • Detailed implementation guide
  • Testing and verification procedures
  • TEST_RESULTS.md with actual test outputs
  • Logfire dashboard usage instructions

This implementation demonstrates production-ready observability
practices suitable for real-world applications.

Implement comprehensive FastAPI + Logfire observability lab with:

Phase 1 - Service Skeleton:
- Initialize FastAPI application with auto-instrumentation
- Configure Logfire with service name 'observability-lab-01'
- Apply logfire.instrument_fastapi(app) hook for automatic tracing
- Add fallback console-only mode for local development

Phase 2 - Structural Depth:
- Implement GET /process-order/{order_id} endpoint
- Use structured logging (key-value pairs) instead of string formatting
- Create manual 'verify_inventory' span for granular tracing
- Simulate database latency with random sleep (0.1s-0.5s)
- Log warnings for slow queries (>0.4s threshold)
- Attach metadata to spans for queryability

Phase 3 - Verification Challenge:
- Add conditional error injection for order_id='error-test'
- Raise HTTPException with 500 status code
- Provide structured error logging with context
- Enable full exception trace correlation

Testing & Verification:
- All endpoints tested and verified working
- Regular order processing with timing information
- Slow query detection and warning logging
- Error case with proper exception handling
- Comprehensive test results documented

Documentation:
- Complete README with setup instructions
- Detailed implementation guide
- Testing and verification procedures
- TEST_RESULTS.md with actual test outputs
- Logfire dashboard usage instructions

This implementation demonstrates production-ready observability
practices suitable for real-world applications.
@gwho gwho merged commit 2534cb7 into master Dec 25, 2025
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.

2 participants