pinojs / pino-socket

🌲 A transport for sending pino logs to network sockets
43 stars 14 forks source link

not supported by esbuild-plugin-pino #105

Closed ben-reitz closed 4 months ago

ben-reitz commented 4 months ago

Raised an issue on esbuild-plugin-pino too (https://github.com/wd-David/esbuild-plugin-pino/issues/173) as I'm not sure where the issues lies. I've looked into it a bit and I think this is where the issue lies:


I'm getting the following error when running my app:

"Error: Cannot find module '/var/task/dist/lib/TcpConnection'",
        "Require stack:",
        "- /var/task/dist/pino-socket.js",
        "    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)",
        "    at Module._load (node:internal/modules/cjs/loader:986:27)",
        "    at Module.require (node:internal/modules/cjs/loader:1233:19)",
        "    at require (node:internal/modules/helpers:179:18)",
        "    at Object.<anonymous> (/var/task/node_modules/pino-socket/psock.js:5:30)",
        "    at Module._compile (node:internal/modules/cjs/loader:1358:14)",
        "    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1208:32)",
        "    at Module._load (node:internal/modules/cjs/loader:1024:12)",
        "    at cjsLoader (node:internal/modules/esm/translators:348:17)"

This is because pino-socket has the following line in its main entrypoint:

const tcpConnectionFactory = require(path.join(__dirname, 'lib', 'TcpConnection'))`

which is being transpiled by esbuild to

sf=require(Ie.join(__dirname,"lib","TcpConnection"))

which doesn't work as only a single file pino-socket.js is being created for it.

Is there a way around this or is there an issue with my config?

pino config:
const logger = pino({
    level: 'info',
    transport: {
        pipeline: [
            {
                target: 'pino-syslog',
                options: {
                    appname: process.env.AWS_LAMBDA_FUNCTION_NAME,
                    newline: true,
                },
            },
            {
                target: 'pino-socket',
                options: {
                    host: process.env.LOG_COLLECTOR_HOST,
                    port: process.env.LOG_COLLECTOR_PORT,
                    mode: 'tcp',
                    secure: true,
                },
            },
        ],
    },
});
build:
await esbuild.build({
    entryPoints: [{ in: 'src/server/lambdaHandler.ts', out: 'server' }],
    bundle: true,
    platform: 'node',
    target: 'node20',
    outdir: 'dist',
    minify: true,
    sourcemap: true,
    plugins: [esbuildPluginPino({ transports: ['pino-pretty', 'pino-syslog', 'pino-socket'] })],
    logLevel: 'info',
});
mcollina commented 4 months ago

I think you can send a PR here that removes that path.join(). It's not necessary.

ben-reitz commented 4 months ago

Thanks @mcollina - I've raised #106