googleapis / nodejs-logging

Node.js client for Stackdriver Logging: Store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS).
https://cloud.google.com/logging/
Apache License 2.0
173 stars 63 forks source link

Logging a circularly dependent object does nothing. #1539

Open drunkcod opened 3 weeks ago

drunkcod commented 3 weeks ago

Environment details

Steps to reproduce

  1. log something having a circular reference
  2. see nothing in the logs

The below will using a plain console transport log an error. With the LoggingWinston transport on the other hand the error will be silent.

import { LoggingWinston } from "@google-cloud/logging-winston";
import winston from 'winston';

const logSomething = (transport) => {
    const logger = winston.createLogger({
        transports: [transport],
        format: winston.format.combine(
            winston.format.errors({ stack: true }),
            winston.format.json()),
    })

    logger.info('hello logging world');

    const error = { 
        message: 'hello error world',
    };
    //it's usally indirect but this will do
    error['cause'] = error;

    logger.error('here a circular problem', error);
    logger.info('bye');
}

logSomething(new winston.transports.Console());

logSomething(new LoggingWinston({
    redirectToStdout: true,
    useMessageField: false,
    projectId: process.env.gcpProjectId,
}));

This is extra problematic due to a common error AxiosError having a circular dependency and hence such failures are omitted from production logs.

drunkcod commented 3 weeks ago

I suspect the issue originates here: https://github.com/googleapis/nodejs-logging/blob/9d1d480406c4d1526c8a7fafd9b18379c0c7fcea/src/log-sync.ts#L446

And that doing entry.toJSON({ removeCircular: true }); is one possible solution. Or perhaps log the serialization issue and shunt it over to the client to de-circularize but swallowing the issue seems no good.