Skip to content

Instantly share code, notes, and snippets.

@kjin
Created July 27, 2019 00:31
Show Gist options
  • Save kjin/3b86f1eaf6c8ee9c458df8708e77ae53 to your computer and use it in GitHub Desktop.
Save kjin/3b86f1eaf6c8ee9c458df8708e77ae53 to your computer and use it in GitHub Desktop.
const tracer = require('@google-cloud/trace-agent').start({
// Settings recommended for Cloud Functions.
samplingRate: 0,
bufferSize: 1
});
app.get('/', (req, res) => {
tracer.runInRootSpan({
name: 'outer', // Your function name here
traceContext: tracer.propagation.extract(key => req.headers[key]),
}, (span) => {
// Your logic here. Just be sure to call endSpan() after sending a response.
span.endSpan();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment