pino-loki icon indicating copy to clipboard operation
pino-loki copied to clipboard

Call to pino.transport<LokiOptions>() is throwing an error in Deno

Open scar0x00 opened this issue 4 months ago • 1 comments

When executing the following script with Deno:

import pino from 'pino'
import type { LokiOptions } from 'pino-loki'

const transport = pino.transport<LokiOptions>({
  target: "pino-loki",
  options: {
    batching: true,
    interval: 5,

    host: 'http://localhost:3100',
  },
});
const logger = pino(transport);

for (let i = 0; i < 100; i++) {
  logger.info({
    msg: `Log message ${i}`,
    level: "info",
    timestamp: new Date().toISOString(),
    i,
    from: 'Deno'
  });
  console.log(`Logged message ${i}`);

  await new Promise((resolve) => setTimeout(resolve, 1000));
}

The following error pops up:

error: Uncaught (in promise) Error: unable to determine transport target for "pino-loki"
    at fixTarget (file:///path/to/.cache/deno/npm/registry.npmjs.org/pino/9.11.0/lib/transport.js:160:13)
    at pino.transport (file:///path/to/.cache/deno/npm/registry.npmjs.org/pino/9.11.0/lib/transport.js:130:22)
    at file:///path/to/Repos/loki.ts:4:24

The command im using to run the script is deno run -A loki.ts.

I'd like to add that the exact same code runs perfect with Node v22.19.0 and tsx with the command pnpx tsx loki.ts.

Im using Deno 2.5.1: deno 2.5.1 (stable, release, x86_64-unknown-linux-gnu) v8 14.0.365.4-rusty typescript 5.9.2

My OS is Pop!_OS 22.04 LTS 64-bit.

scar0x00 avatar Sep 20 '25 23:09 scar0x00

Hi!

I just looked at #40 and what @Julien-R44 suggested worked just fine. I imported pinoLoki from the module pino-loki and passed the result from the invocation to pino to build the logger.

const logger = pino({level: "info"},
  pinoLoki({
    batching: false,
    labels: { application: 'MY-APP' },
    host: "http://localhost:3100",
  })
);

Still have a doubt about the performance since i have the understanding that this way pino-loki will be in the main process instead of a worker thread.

The other work around that i could think of is piping stdout from the script to the pino-loki cli: deno run -A loki.ts | pino-loki --hostname=http://hostname:3100. This worked fine too.

Thanks!

scar0x00 avatar Sep 20 '25 23:09 scar0x00