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
Developers must remember to call log.flush() explicitly
Poor handling of early returns/exits
Requires error handling in every exit path to ensure logs are saved
Performance Impact
Blocking behavior: Must wait for log flush and HTTP request completion
Delays server component response unnecessarily
Proposed Solution
Use Next.js's unstable_after API to handle log flushing automatically after request completion, similar to middleware's waitUntil.
Current Approach (Problematic)
import{Logger}from'next-axiom';exportdefaultasyncfunctionServerComponent(){constlog=newLogger();log.info('User logged in',{userId: 42});// Early return example - logs would be lostif(someCondition){return<h1>EarlyExit</h1>;
}awaitlog.flush();// Blocking operationreturn<h1>Loggedin</h1>;}
Proposed Approach
import{Logger}from'next-axiom';import{unstable_afterasafter}from"next/server"exportdefaultasyncfunctionServerComponent(){constlog=newLogger();after(log.flush);// Non-blocking, executes after request lifecyclelog.info('User logged in',{userId: 42});// Early return example - logs will still be flushedif(someCondition){return<h1>EarlyExit</h1>;
}return<h1>Loggedin</h1>;}
Benefits
Graceful handling of early exits
Non-blocking execution
Simplified developer experience
Consistent log flushing regardless of return path
Discussion Points
Should this pattern be integrated into the library as a dedicated API?
Or should it be documented as a recommended practice?
Consider adding to documentation for server component logging best practices
The text was updated successfully, but these errors were encountered:
hi @sam3d , looks like this is stable now in Next 15.1. I believe we could update your documentation to reflect this as a good practice for Server Components but not sure how can we wrap RSC to achieve this from within next-axiom library.
Current Issues
Manual Flush API Management
log.flush()
explicitlyPerformance Impact
Proposed Solution
Use Next.js's
unstable_after
API to handle log flushing automatically after request completion, similar to middleware'swaitUntil
.Current Approach (Problematic)
Proposed Approach
Benefits
Discussion Points
The text was updated successfully, but these errors were encountered: