Skip to content

Make pino transport work with worker threads #16723

Open
@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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy