Skip to content

Cannot pass onError function in pino.transport() options #360

@thienscmon

Description

@thienscmon

I’m using @axiomhq/pino as a transport and want to customize the default error handling of the Axiom client.
However, it seems that functions like onError cannot be passed through pino.transport() options, since they are cloned and sent to a worker thread.

target: "@axiomhq/pino",
options: {
  dataset: process.env.AXIOM_DATASET,
  token: process.env.AXIOM_TOKEN,
  onError: (error: unknown) => {
    console.error("Axiom error: ", error);
  },
},

I get the following error:

node: internal/per_context/domexception:53
ErrorCaptureStackTrace(this);
DOMException [DataCloneError]: (error) = € console.error(error);
} could not be cloned.
at new DOMException (node: internal/per_context/domexception:53:5)
at new Worker (node: internal/worker:271:17)
at createWorker /app/node_modules/thread-stream/index. js:55:18) at new ThreadStream (/app/node_modules/thread-stream/index. js:230:19) at buildStream (/app/node_modules/pino/lib/transport.js:21:18)
at Function. transport (/app/node_modules/pino/lib/transport.js:130:10)
at Log (file:///app/packages/core/dist/config/axiom. js:15:8)

It looks like new Axiom(options) is created directly from the transport options.
Since functions can’t be cloned, is there any recommended way to customize or override the default console.error message used by the Axiom client for error logging?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions