Skip to content

Instantly share code, notes, and snippets.

@guyguyon
Created November 23, 2017 16:45
Show Gist options
  • Select an option

  • Save guyguyon/00b6cdd3952ab593594666447bd62f47 to your computer and use it in GitHub Desktop.

Select an option

Save guyguyon/00b6cdd3952ab593594666447bd62f47 to your computer and use it in GitHub Desktop.
// index.js
const http = require('http');
const uuid = require('uuid');
const SomeResource = require('./some_resource');
const namespace = require('./node-request-context').createNamespace('some-namespace');
http.createServer(function (req, res) {
namespace.run(() => {
const transactionId = uuid.v1();
console.log('Setting a new transaction id => ', transactionId);
namespace.set('tid', transactionId);
console.log(namespace.get('tid'));
const sr = new SomeResource();
sr.get().then((ans) => {
console.log(namespace.get('tid'));
res.end(ans);
}).catch((err) => {
console.log('Error: ', err);
})
})
}).listen(8079);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment