refactor: move trace middleware addition to wrapHandler and update mi…#92
Merged
Suhaibinator merged 1 commit intomainfrom Jul 17, 2025
Merged
refactor: move trace middleware addition to wrapHandler and update mi…#92Suhaibinator merged 1 commit intomainfrom
Suhaibinator merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the trace middleware initialization by moving it from the router constructor to the wrapHandler method and updates the middleware execution order accordingly.
- Removes trace middleware addition from
NewRouterconstructor - Adds trace middleware creation and positioning in
wrapHandlermethod early in the chain - Updates middleware order comments to reflect the new sequence
| // 2. Authentication (Runs early) | ||
| // 2. Trace middleware (if enabled) - positioned early so all middlewares have access to trace ID | ||
| if r.traceIDGenerator != nil { | ||
| traceMW := middleware.CreateTraceMiddleware[T, U](r.traceIDGenerator) |
There was a problem hiding this comment.
Creating trace middleware on every request in wrapHandler could impact performance. Consider creating the middleware once during router initialization and reusing it, or document why per-request creation is necessary.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
=======================================
Coverage 97.17% 97.17%
=======================================
Files 18 18
Lines 2369 2370 +1
=======================================
+ Hits 2302 2303 +1
Misses 55 55
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
…ddleware order