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
I'm using the next-axiom library for Next.js and I'm trying to understand why does log.flush() needs to be called before returning on server components?
It will be great to know a little bit more about this function to really understand when to use it, that's what I'm proposing here, cause until know the docs of this library does not tell anything about that function, they only present a single use case out of 20 of more posible use cases.
Maybe you want to create a function that process errors and one of the tasks of that function is sending the error info to an Axiom dataset, so does that function will need to call log.flush() internally? What if I call this function multiple times on the server components? Does calling log.flush() multiple times will cause unwanted behavior?
Maybe you want to ingest data from middleware.ts, generateMetadata or any other context that is executed on the server, but that is not a server component, what do I do in those cases?
Do I need to call log.flush before throwing also?
It will be great to have this specified on the docs, thank you so much!
The text was updated successfully, but these errors were encountered:
It seems to me that all log.flush does is actually "flush" the queue of logs to Axiom throttled in batches. In other words, it guarantees that any unsent logs are sent before the server action completes execution. If you want to guarantee all logs are sent in the server component, you must flush. Otherwise, you may have orphaned logs that never get sent before the component is returned from the server.
What isn't clear to me is why server component, like route handlers, can't "auto flush". I can't imagine why they wouldn't be able to do that, but I have limited understanding of the library's internals.
@cereallarceny that's right, flush ensures any unset logs are shipped to Axiom. Auto flushing sounds good if we can do it, we do that with the route handlers using withAxiom(). If we can achieve the same that would be great, is it possible to wrap Server components?
I'm using the
next-axiom
library for Next.js and I'm trying to understand why doeslog.flush()
needs to be called before returning on server components?It will be great to know a little bit more about this function to really understand when to use it, that's what I'm proposing here, cause until know the docs of this library does not tell anything about that function, they only present a single use case out of 20 of more posible use cases.
Maybe you want to create a function that process errors and one of the tasks of that function is sending the error info to an Axiom dataset, so does that function will need to call
log.flush()
internally? What if I call this function multiple times on the server components? Does callinglog.flush()
multiple times will cause unwanted behavior?Maybe you want to ingest data from
middleware.ts
,generateMetadata
or any other context that is executed on the server, but that is not a server component, what do I do in those cases?Do I need to call
log.flush
before throwing also?It will be great to have this specified on the docs, thank you so much!
The text was updated successfully, but these errors were encountered: