Last active
June 16, 2018 06:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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