Skip to content

Instantly share code, notes, and snippets.

@steren
Last active June 16, 2018 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steren/1464f325ebb29d297e6512c2a7f84f88 to your computer and use it in GitHub Desktop.
Save steren/1464f325ebb29d297e6512c2a7f84f88 to your computer and use it in GitHub Desktop.
Use both Stackdriver Trace and Logging modules for automated trace collection in logs to enable logs correlation
require('@google-cloud/trace-agent').start();
const express = require('express');
const app = express();
const bunyan = require('bunyan');
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
const loggingBunyan = new LoggingBunyan();
const logger = bunyan.createLogger({
name: 'app',
level: 'info',
streams: [
{stream: process.stdout},
loggingBunyan.stream(),
],
});
app.get('/', (req, res) => {
logger.error('warp nacelles offline');
logger.info('shields at 99%');
res.send('🎉 Hello Node.js on App Engine Standard! 🎉');
});
const server = app.listen(process.env.PORT || 8080, () => {
const host = server.address().address;
const port = server.address().port;
console.log(`Example app listening at http://${host}:${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment