6

I'm trying to migrate a Next.js project running on Vercel from

    "pino-datadog": "2.0.2",
    "pino-multi-stream": "6.0.0",

to

    "pino": "8.4.2",
    "pino-datadog-transport": "1.2.2",

and I copy the setup from the pino-datadog-transport's README.md:

import { LoggerOptions, pino } from 'pino'

const pinoConf: LoggerOptions = {
  level: 'trace',
}

const logger = pino(
  pinoConf,
  pino.transport({
    target: 'pino-datadog-transport',
    options: {
      ddClientConf: {
        authMethods: {
          apiKeyAuth: process.env.DATADOG_API_KEY,
        },
      },
      ddServerConf: {
        site: 'datadoghq.eu',
      },
      service: process.env.VERCEL_URL
      ddsource: 'nodejs',
    },
  }),
)

and this seems to be working fine locally, but when I publish it on Vercel and run it there I get the following error:

ERROR   Error: unable to determine transport target for "pino-datadog-transport"
    at fixTarget (/var/task/node_modules/pino/lib/transport.js:136:13)
    at Function.transport (/var/task/node_modules/pino/lib/transport.js:110:22)

Am I missing some additional config to get this working? Anyone else running this setup or something similar to get explicit logs working on Vercel with Next.js?

I have enabled the Datadog integration in Vercel as well, but that only forwards Next.js logs, not explicit console.logs or standard Pino logs from what I can tell.

simonauner
  • 1,021
  • 1
  • 8
  • 10
  • I'm having the same issue. Where did you see the error log, I can't seem to find the error log out on vercels site? – David Brown Oct 10 '22 at 19:16
  • @DavidBrown I have left the project now, but IIRC I saw it in Datadog when I had Vercel's Datadog integration enabled. – simonauner Oct 11 '22 at 20:11

1 Answers1

1

The solution to this problem is to import even though nothing in the import is actually used in the code.

It seems Next.js strips away all code that isn't imported when the code is deployed.

So, adding

import 'pino-datadog-transport'

at the top of the file solves the problem.

simonauner
  • 1,021
  • 1
  • 8
  • 10
  • I had the same problem with `pino-mongodb` and SvelteKit with Vercel and this solution also worked for me, so it looks like it's not specific to Nextjs – Benjineer Jul 24 '23 at 23:29