feat: add HTTP middleware package with multi-framework support (#45)#59
Merged
willibrandon merged 4 commits intomainfrom Aug 22, 2025
Merged
feat: add HTTP middleware package with multi-framework support (#45)#59willibrandon merged 4 commits intomainfrom
willibrandon merged 4 commits intomainfrom
Conversation
- Add middleware adapters for net/http, Gin, Echo, Fiber, and Chi - Implement request/response logging with configurable sampling strategies - Add object pooling for high-performance scenarios with zero-allocation paths - Support request ID generation, distributed tracing, and correlation IDs - Include body logging with sanitization for sensitive data protection - Add health check handlers with metrics and configurable checks - Provide test coverage (570+ tests) with benchmarks - Fix Windows compatibility issues with JSON marshaling and timing precision - Add examples and documentation for all supported frameworks
There was a problem hiding this comment.
Pull Request Overview
This PR implements a comprehensive HTTP middleware package for structured request/response logging across popular Go web frameworks. The middleware provides high-performance logging with minimal overhead through object pooling and intelligent sampling strategies.
Key changes:
- Multi-framework support: Added adapters for net/http, Gin, Echo, Fiber, and Chi web frameworks
- Advanced features: Implemented request/response logging, sampling strategies, health checks, metrics recording, and object pooling
- Documentation updates: Added HTTP middleware section to quick reference documentation and updated HTML guides
Reviewed Changes
Copilot reviewed 43 out of 44 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/quick-reference.md | Added comprehensive HTTP middleware documentation with configuration examples |
| docs/quick-reference.html | Added HTML version of middleware documentation with navigation |
| docs/index.html | Removed footer attribution line |
| docs/blog/*.html | Removed footer attribution lines from blog pages |
| adapters/middleware/*.go | Core middleware implementation with sampling, pooling, metrics, and framework adapters |
| adapters/middleware/*_test.go | Comprehensive test suites including unit, integration, and benchmark tests |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Add crypto/rand for unpredictable seeding in all samplers - Fix RateSampler, AdaptiveSampler, PathSampler, and DynamicPathSampler to use local rand.Rand instances - Add proper mutex protection for random number generation
- Improve getClientIP to correctly extract first IP from X-Forwarded-For header and trim whitespace - Strengthen TestBaggageExtraction with specific assertions for baggage extraction and propagation - Make APIVersionFromPath more strict by validating version format (v followed by numbers/dots) - Store full TraceContext in context for proper baggage access - Fix test expectations for invalid version paths like /videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements a comprehensive HTTP middleware package for structured request/response logging across popular Go web frameworks. The middleware provides high-performance logging with minimal overhead (~2.3μs per request) through object pooling and intelligent sampling strategies.
Type of change
Key Features Implemented
Checklist
go test ./...)golangci-lint run)Additional notes
adapters/middleware/examples/Size Note
This is a large PR (13,000+ lines) as it implements a complete HTTP middleware package with:
The feature was developed as a cohesive unit to ensure consistency across all frameworks.
Fixes #45