pinojs/pino

transport options - either confusing variable names or I'm just still learning (free to admit it)

Opened this issue · 1 comments

inside of the transport code, we have the base options object defined:

interface TransportBaseOptions<TransportOptions = Record<string, any>> {
        options?: TransportOptions
        worker?: WorkerOptions & { autoEnd?: boolean}
    }

follow the definition of workerOptions to node:

interface WorkerOptions {
        /**
         * List of arguments which would be stringified and appended to
         * `process.argv` in the worker. This is mostly similar to the `workerData`
         * but the values will be available on the global `process.argv` as if they
         * were passed as CLI options to the script.
         */
        argv?: any[] | undefined;
        env?: NodeJS.Dict<string> | typeof SHARE_ENV | undefined;
        eval?: boolean | undefined;
        workerData?: any;
        stdin?: boolean | undefined;
        stdout?: boolean | undefined;
        stderr?: boolean | undefined;
        execArgv?: string[] | undefined;
        resourceLimits?: ResourceLimits | undefined;
        /**
         * Additional data to send in the first worker message.
         */
        transferList?: TransferListItem[] | undefined;
        /**
         * @default true
         */
        trackUnmanagedFds?: boolean | undefined;
        /**
         * An optional `name` to be appended to the worker title
         * for debuggin/identification purposes, making the final title as
         * `[worker ${id}] ${name}`.
         */
        name?: string | undefined;
    }

Above I would think that if I plan to use the worker_threads library to access workerData, then I should be defining workerData as an element of worker inside the options for transport.

import { workerData } from 'node:worker_threads';

However, if we take a look at transport.js:

function transport (fullOptions) {
  const { pipeline, targets, levels, dedupe, options = {}, worker = {}, caller = getCallers() } = fullOptions

<snip>

  return buildStream(fixTarget(target), options, worker)
  <snip>

this leads me to believe that the thread will be built with my workerOptions...

function buildStream (filename, workerData, workerOpts) {
  const stream = new ThreadStream({
    filename,
    workerData,
    workerOpts
  })

BUT buildStream 're-names' options to workerData, but also passes 'workerOpts' which also has the element 'workerData' as shown above.

If you do import workerData you end up with what I would think are supposed to be the logger options passed to the transport.

Please correct me if I'm wrong, or at least explain how this is supposed to work and what the actual 'options' are meant to be.

Thank you.

I'm sorry but I don't understand what you are trying to achieve.