This repository was archived by the owner on Feb 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Sample code in the README doesn't work #353
Copy link
Copy link
Closed
Labels
🚨This issue needs some love.This issue needs some love.api: loggingIssues related to the googleapis/nodejs-logging-bunyan API.Issues related to the googleapis/nodejs-logging-bunyan API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
- OS: Ubuntu 19.04
- Node.js version: v8.16.1
- npm version: 6.4.1
@google-cloud/logging-bunyanversion: 1.2.3
Steps to reproduce
- Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to point to file containing service account key, project ID, etc. - Try to run the sample code in the
README. Namely,
const bunyan = require('bunyan');
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
// Creates a Bunyan Stackdriver Logging client
const loggingBunyan = new LoggingBunyan();
// Create a Bunyan logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
// The JSON payload of the log as it appears in Stackdriver Logging
// will contain "name": "my-service"
name: 'my-service',
streams: [
// Log to the console at 'info' and above
{stream: process.stdout, level: 'info'},
// And log to Stackdriver Logging, logging at 'info' and above
loggingBunyan.stream('info'),
],
});
// Writes some log entries
logger.error('warp nacelles offline');
logger.info('shields at 99%');
Expected result: The script logs the messages to the console, and then to Stackdriver Logging.
Actual result: The script logs the messages to the console, but doesn't log them to Stackdriver Logging. After a few seconds (about 15 seconds on my machine), it throws the following exception:
(node:358) UnhandledPromiseRejectionWarning: FetchError: request to http://169.254.169.254/computeMetadata/v1/instance failed, reason: connect EHOSTUNREACH 169.254.169.254:80
at ClientRequest.<anonymous> (/app/node_modules/node-fetch/lib/index.js:1430:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at Socket.socketErrorListener (_http_client.js:401:9)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)
(node:358) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:358) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
For the record, I am running the script locally on my machine.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🚨This issue needs some love.This issue needs some love.api: loggingIssues related to the googleapis/nodejs-logging-bunyan API.Issues related to the googleapis/nodejs-logging-bunyan API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.