diff --git a/packages/zipkin-context-cls/package.json b/packages/zipkin-context-cls/package.json index df664556..b0b73bcf 100644 --- a/packages/zipkin-context-cls/package.json +++ b/packages/zipkin-context-cls/package.json @@ -13,6 +13,11 @@ "license": "Apache-2.0", "repository": "https://github.com/openzipkin/zipkin-js", "dependencies": { - "continuation-local-storage": "^3.1.7" + "cls-hooked": "^4.2.2" + }, + "devDependencies": { + "babel-cli": "^6.23.0", + "babel-eslint": "^8.2.2", + "mocha": "^3.2.0" } } diff --git a/packages/zipkin-context-cls/src/CLSContext.js b/packages/zipkin-context-cls/src/CLSContext.js index c6f8d96e..d1767ed9 100644 --- a/packages/zipkin-context-cls/src/CLSContext.js +++ b/packages/zipkin-context-cls/src/CLSContext.js @@ -1,4 +1,4 @@ -const {createNamespace, getNamespace} = require('continuation-local-storage'); +const {createNamespace, getNamespace} = require('cls-hooked'); module.exports = class CLSContext { constructor(namespace = 'zipkin') { diff --git a/packages/zipkin-context-cls/test/.eslintrc b/packages/zipkin-context-cls/test/.eslintrc index 3c8fcd73..0ea9840b 100644 --- a/packages/zipkin-context-cls/test/.eslintrc +++ b/packages/zipkin-context-cls/test/.eslintrc @@ -4,5 +4,6 @@ }, "globals": { "expect": true - } + }, + "parser": "babel-eslint" } diff --git a/packages/zipkin-context-cls/test/CLSContext.test.js b/packages/zipkin-context-cls/test/CLSContext.test.js index 857de186..22a04e93 100644 --- a/packages/zipkin-context-cls/test/CLSContext.test.js +++ b/packages/zipkin-context-cls/test/CLSContext.test.js @@ -80,4 +80,24 @@ describe('CLSContext', () => { setTimeout(callback, 10); }); }); + it('should support async-await', async () => { + const ctx = new CLSContext(); + + async function log() { + return ctx.getContext(); + } + + async function afn() { + const cid1 = await log(1); + const cid2 = await log(2); + return {cid1, cid2}; + } + + async function newP(id) { + const {cid1, cid2} = await ctx.letContext(id, () => afn()); + expect(cid1).to.not.equal(null); + expect(cid2).to.not.equal(null); + } + await newP(1); // eslint-disable-line + }); });