metcoder95 / cloud-pine

Pino Transport abstraction for Google Cloud Logging
MIT License
12 stars 2 forks source link

Unhandled 'error' event for the initial example #33

Open sbcgua opened 1 year ago

sbcgua commented 1 year ago

Describe the bug The (slightly modified) example from the docs results in Unhandled 'error' event. Although the logs were successfully sent (!).

To Reproduce

import fs from 'node:fs';
const CRED_FILE_PATH = './path-to-credentials.json';
const creds = JSON.parse(fs.readFileSync(CRED_FILE_PATH, 'utf-8'));

import pino from 'pino';
const logger = pino({
    transport: {
        target: 'cloud-pine',
        options: {
            logName: 'my_cloud-pine',
            cloudLoggingOptions: {
                googleCloudOptions: {
                    projectId:   creds.project_id,
                    credentials: creds,
                },     
            }
        }
    }
});

logger.info('Hello from pino');
logger.error({ andSomedata: 1 }, 'Pino Error');

Expected behavior No errors, graceful exit

Screenshots

$node pino.js
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: end() took too long (10s)
    at end (C:\Users\...\test-google-logs\node_modules\thread-stream\index.js:406:15)
    at ThreadStream.end (C:\Users\...\test-google-logs\node_modules\thread-stream\index.js:258:5)
    at autoEnd (C:\Users\...\test-google-logs\node_modules\pino\lib\transport.js:75:10)
    at process.wrap (C:\Users\...\test-google-logs\node_modules\on-exit-leak-free\index.js:10:7)
    at Object.onceWrapper (node:events:628:26)
    at process.emit (node:events:513:28)
Emitted 'error' event on ThreadStream instance at:
    at destroy (C:\Users\...\test-google-logs\node_modules\thread-stream\index.js:349:12)
    at end (C:\Users\...\test-google-logs\node_modules\thread-stream\index.js:415:5)
    at ThreadStream.end (C:\Users\...\test-google-logs\node_modules\thread-stream\index.js:258:5)
    [... lines matching original stack trace ...]
    at process.emit (node:events:513:28)

Desktop (please complete the following information):

metcoder95 commented 1 year ago

Hi! Thanks for the report! šŸ™‚ I've tried to reproduce the error but I only could do it if I try to connect to GCP, as I lack credentials. Most likely something similar might happened.

Could you reproduce it or is there any other stack trace or error message? Sadly it is not rich enough to reproduce it šŸ˜ž

sbcgua commented 1 year ago

Hi, sorry for late response :(

The log entry is delivered so it is not an issue with the credentials. image

And I retried this code which I posted - it actually fails and with the stack I posted. Not sure how to extract additional information.

Here is also the package.json just in case (though it is a bit messy with other experiments)

{
  "name": "test-google-logs",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@google-cloud/logging": "^9.9.0",
    "@google-cloud/logging-bunyan": "^4.2.2",
    "bunyan": "^1.8.15",
    "cloud-pine": "^2.0.0",
    "dotenv": "^16.0.3",
    "pino": "^7.9.2"
  }
}
metcoder95 commented 1 year ago

Hey! No worries at all!

Then, here I'm guessing the Google logging implementation is taking longer to close the other end of the stream, causing the transport to time out.

Let me take a look deeply into it soon based on what you are sharing! Thanks for the information