Skip to content

Make pino transport work with worker threadsΒ #16723

@AbhiPrasad

Description

@AbhiPrasad

Description

pino transports run in a worker thread. This means we have to send logs via the pino transport, we need to re-initialize sentry in the worker thread. This also means that the trace ids from the worker thread will be different than the trace ids in sentry.

We can get the trace id part working via usage of https://www.npmjs.com/package/@opentelemetry/instrumentation-pino.

The main blocker then becomes initializing the Sentry SDK. The approach every other vendor takes here is to just allow people to pass in sentry config and initialize the SDK within the pino transport. This might be a bit confusing to users.

Another alternative is the following:

  1. Construct a pino logger instance, but point it toward another file:
// in main application

// Create a pino logger instance
const logger = pino({
  name: "pino-demo",
  level: "debug",
  transport: {
    target: "./pino-transport.mjs",
  },
});
  1. In that seperate file we initialize the SDK and return the pino transport:
// filename: pino-transport.mjs

import * as Sentry from "@sentry/node";

Sentry.init({
  debug: true,
  dsn: "PUBLIC_DSN",
  _experiments: {
    enableLogs: true,
  },
});

import { createSentryPinoTransport } from "@sentry/pino-transport";

export default createSentryPinoTransport;

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions