logtail / logtail-js

Better Stack JavaScript client
https://betterstack.com/logs
ISC License
52 stars 12 forks source link

@logtail/pino in nextjs #106

Open TranHung92 opened 6 months ago

TranHung92 commented 6 months ago

When I follow this setup

const token = '$SOURCE_TOKEN'; 
const pino = require('pino');
const transport = pino.transport({
  target: "@logtail/pino",
  options: { sourceToken: token }
});
const logger = pino(transport);

I get the error below nonstop and the server crashes

⨯ node_modules/thread-stream/index.js (235:18) @ ThreadStream.write
 ⨯ uncaughtException: Error: the worker has exited
    at ThreadStream.write (webpack-internal:///(rsc)/./node_modules/thread-stream/index.js:199:25)
    at Pino.write (webpack-internal:///(rsc)/./node_modules/pino/lib/proto.js:163:12)
    at Pino.LOG (webpack-internal:///(rsc)/./node_modules/pino/lib/tools.js:39:27)
    at Pino.eval [as fatal] (webpack-internal:///(rsc)/./node_modules/pino/lib/levels.js:17:22)
    at process.eval (webpack-internal:///(rsc)/./src/logging.ts:53:16)
    at process.emit (node:events:529:35)
    at process._fatalException (node:internal/process/execution:158:25)
null
Error: the worker has exited
    at ThreadStream.write (webpack-internal:///(rsc)/./node_modules/thread-stream/index.js:199:25)
    at Pino.write (webpack-internal:///(rsc)/./node_modules/pino/lib/proto.js:163:12)
    at Pino.LOG (webpack-internal:///(rsc)/./node_modules/pino/lib/tools.js:39:27)
    at Pino.eval [as fatal] (webpack-internal:///(rsc)/./node_modules/pino/lib/levels.js:17:22)
    at process.eval (webpack-internal:///(rsc)/./src/logging.ts:53:16)
    at process.emit (node:events:529:35)
    at process._fatalException (node:internal/process/execution:158:25)

What would be the best way to stream pino logs to logtail?

curusarn commented 6 months ago

Hi @TranHung92,

Thank you for reaching out! I hope you're doing great!

Could you share more details about your setup? 🙏 What NextJS version are you using? Are you using the latest @logtail/pino version?

Thanks again for raising this!

TranHung92 commented 6 months ago

Hi @curusarn I'm using nextjs 14.1.0 with app router setup and @logtail/pino@0.4.19

TranHung92 commented 6 months ago

@curusarn any update on this?