Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging a circularly dependent object does nothing. #1539

Open
drunkcod opened this issue Nov 4, 2024 · 1 comment
Open

Logging a circularly dependent object does nothing. #1539

drunkcod opened this issue Nov 4, 2024 · 1 comment
Assignees
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@drunkcod
Copy link

drunkcod commented Nov 4, 2024

Environment details

  • OS: Mac OS 15
  • Node.js version: 22
  • npm version: 10.8.3
  • @google-cloud/logging version: 11.2 (via logging-winston 6.0.0)

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 drunkcod added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 4, 2024
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/nodejs-logging API. label Nov 4, 2024
@drunkcod
Copy link
Author

drunkcod commented Nov 4, 2024

I suspect the issue originates here:

this.transport.write(JSON.stringify(entry) + '\n');

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/nodejs-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants