Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about logging for client-side code? #46

Open
avibathula opened this issue Oct 27, 2024 · 3 comments
Open

What about logging for client-side code? #46

avibathula opened this issue Oct 27, 2024 · 3 comments
Assignees

Comments

@avibathula
Copy link

avibathula commented Oct 27, 2024

I ran into an interesting issue using the logging the repo has enabled using pino & @logtail/pino packages in src/libs/Logger.ts.

I started seeing the following error
NextJS pino Error: Cannot find module <local-repo-path>/.next/server/chunks/lib/worker.js

After some significant digging, I realized that the logging using pino with logtail is limited to server-side operations only, and by mistake I was using the logger in client-side components page.tsx etc. As pino uses worker threads from NodeJS, which is not available on client side, understandably build process was running into "Cannot find module". Unfortunately, the error messages showed no hints, and it was super hard to find what was going on, at least for a newbie like me 😄

Questions

  1. As one is developing their client side UX, there can be a lot of bugs/misbehaviors over there too. How would one generate+get logs to investigate such client-side issues? - What is the suggested best practice that nodeJS and nextJS devs use?

    • One option I see is to use @logtail/browser for generating client-side logging - but that will make the logging functionality complicated to keep the logic and behaviors consistent on both client and server side. Also, as users grow, the volume of logs generated will become exponentially high and it will become a needle in a haystack to have all those logs be sent to betterstack. I guess one can have some flag in setting to enable sending detailed logs to betterstack with some session-ids to be able to point out to.

      • I tried out using @logtail/browser for client-side pages and it got complicated with nextJS's SSG optimizations resulting in some log statements executing during the build rather than at runtime - lol.
    • OR another option is to just use console logging for client side and ask the user to copy and send client-side logs from browser's console - which is not so user-friendly.

    • ??

  2. Besides investigating bugs - is product usage analytics of how users are using the product a valid usage of pino based logging? if no, what alternative packages should one consider for that?

@ixartz
Copy link
Owner

ixartz commented Oct 27, 2024

@avibathula Indeed, it seems pino.js has better support for server side.

For now, I didn't find any solution working for both server and client side. It seems most of the solution is focusing on server side. There isn't any full-stack solution. I would love to hear any suggestion.

One solution is to use console.log for the frontend and use Sentry to collect the logs. This is definitively not ideal.

@avibathula
Copy link
Author

avibathula commented Oct 27, 2024 via email

@ixartz
Copy link
Owner

ixartz commented Oct 27, 2024

I mostly use Sentry for frontend.

@ixartz ixartz self-assigned this Nov 5, 2024
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

No branches or pull requests

2 participants