diff --git a/packages/zipkin-instrumentation-express/package.json b/packages/zipkin-instrumentation-express/package.json index e4b545a6..827ebb0c 100644 --- a/packages/zipkin-instrumentation-express/package.json +++ b/packages/zipkin-instrumentation-express/package.json @@ -17,7 +17,7 @@ "zipkin": "^0.19.2" }, "devDependencies": { - "express-http-proxy": "^0.11.0", + "express-http-proxy": "^1.6.0", "node-fetch": "^2.6.0" } } diff --git a/packages/zipkin-instrumentation-express/src/wrapExpressHttpProxy.js b/packages/zipkin-instrumentation-express/src/wrapExpressHttpProxy.js index c49d336e..c4d521c7 100644 --- a/packages/zipkin-instrumentation-express/src/wrapExpressHttpProxy.js +++ b/packages/zipkin-instrumentation-express/src/wrapExpressHttpProxy.js @@ -50,13 +50,13 @@ class ExpressHttpProxyInstrumentation { function wrapProxy(proxy, {tracer, serviceName, remoteServiceName}) { return function zipkinProxy(host, options = {}) { - function wrapDecorateRequest(instrumentation, decorateRequest) { + function wrapProxyReqOptDecorator(instrumentation, proxyReqOptDecorator) { return (proxyReq, serverReq) => { const serverTraceId = serverReq._trace_id; let wrappedProxyReq = proxyReq; - if (typeof decorateRequest === 'function') { + if (typeof proxyReqOptDecorator === 'function') { tracer.letId(serverTraceId, () => { - wrappedProxyReq = decorateRequest(proxyReq, serverReq); + wrappedProxyReq = proxyReqOptDecorator(proxyReq, serverReq); }); } @@ -64,19 +64,19 @@ function wrapProxy(proxy, {tracer, serviceName, remoteServiceName}) { }; } - function wrapIntercept(instrumentation, intercept) { - return (rsp, data, serverReq, res, callback) => { - const instrumentedCallback = (err, rspd, sent) => { - instrumentation.recordResponse(rsp, serverReq._trace_id_proxy); - return callback(err, rspd, sent); - }; - + function wrapUserResDecorator(instrumentation, userResDecorator) { + return (rsp, data, serverReq, res) => { const serverTraceId = serverReq._trace_id; - if (typeof intercept === 'function') { - tracer.letId(serverTraceId, - () => intercept(rsp, data, serverReq, res, instrumentedCallback)); + if (typeof userResDecorator === 'function') { + let decoratedResponse; + tracer.letId(serverTraceId, () => { + decoratedResponse = userResDecorator(rsp, data, serverReq, res); + instrumentation.recordResponse(rsp, serverReq._trace_id_proxy); + }); + return decoratedResponse; } else { - instrumentedCallback(null, data); + instrumentation.recordResponse(rsp, serverReq._trace_id_proxy); + return data; } }; } @@ -87,11 +87,13 @@ function wrapProxy(proxy, {tracer, serviceName, remoteServiceName}) { const wrappedOptions = options; - const {decorateRequest} = wrappedOptions; - wrappedOptions.decorateRequest = wrapDecorateRequest(instrumentation, decorateRequest); + const {proxyReqOptDecorator} = wrappedOptions; + wrappedOptions.proxyReqOptDecorator = wrapProxyReqOptDecorator( + instrumentation, proxyReqOptDecorator + ); - const {intercept} = wrappedOptions; - wrappedOptions.intercept = wrapIntercept(instrumentation, intercept); + const {userResDecorator} = wrappedOptions; + wrappedOptions.userResDecorator = wrapUserResDecorator(instrumentation, userResDecorator); return proxy(host, wrappedOptions); }; diff --git a/packages/zipkin-instrumentation-express/test/wrapExpressHttpProxyIntegrationTest.js b/packages/zipkin-instrumentation-express/test/wrapExpressHttpProxyIntegrationTest.js index ee17bac7..ed427dbc 100644 --- a/packages/zipkin-instrumentation-express/test/wrapExpressHttpProxyIntegrationTest.js +++ b/packages/zipkin-instrumentation-express/test/wrapExpressHttpProxyIntegrationTest.js @@ -31,13 +31,13 @@ describe('express proxy instrumentation - integration test', () => { const zipkinProxy = wrapProxy(proxy, {tracer: tracer.tracer(), remoteServiceName}); frontendApp.use(middleware({tracer: tracer.tracer()})); frontendApp.use(zipkinProxy(`127.0.0.1:${backend.address().port}`, { - decorateRequest: (proxyReq) => { - tracer.tracer().recordBinary('decorateRequest', ''); + proxyReqOptDecorator: (proxyReq) => { + tracer.tracer().recordBinary('proxyReqOptDecorator', ''); return proxyReq; }, - intercept: (rsp, data, serverReq, res, callback) => { - tracer.tracer().recordBinary('intercept', ''); - callback(null, data); + userResDecorator: (rsp, data, serverReq, res) => { + tracer.tracer().recordBinary('userResDecorator', ''); + return data; } })); @@ -61,8 +61,8 @@ describe('express proxy instrumentation - integration test', () => { tags: { 'http.path': path, 'http.status_code': '200', - intercept: '', - decorateRequest: '' + userResDecorator: '', + proxyReqOptDecorator: '' } }); } @@ -154,7 +154,7 @@ describe('express proxy instrumentation - integration test', () => { 'http.path': path, 'http.status_code': '500', error: '500', // TODO: better error message - decorateRequest: '' + proxyReqOptDecorator: '' } })); }); diff --git a/yarn.lock b/yarn.lock index 21a3b11f..f4815335 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3771,7 +3771,7 @@ debug@3.1.0, debug@=3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6: +debug@^3.0.0, debug@^3.0.1, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== @@ -4282,12 +4282,7 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -es6-promise@^3.2.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.3.1.tgz#a08cdde84ccdbf34d027a1451bc91d4bcd28a613" - integrity sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM= - -es6-promise@^4.0.3: +es6-promise@^4.0.3, es6-promise@^4.1.1: version "4.2.8" resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== @@ -4590,13 +4585,14 @@ expand-template@^2.0.3: resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c" integrity sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg== -express-http-proxy@^0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/express-http-proxy/-/express-http-proxy-0.11.0.tgz#f2e6ba2e9e8677b1ba335375c3cae670d5a1bb0a" - integrity sha1-8ua6Lp6Gd7G6M1N1w8rmcNWhuwo= +express-http-proxy@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/express-http-proxy/-/express-http-proxy-1.6.0.tgz#8672b1093cc96b8a93e8e3da948dd111a668ef22" + integrity sha512-7Re6Lepg96NA2wiv7DC5csChAScn4K76/UgYnC71XiITCT1cgGTJUGK6GS0pIixudg3Fbx3Q6mmEW3mZv5tHFQ== dependencies: - es6-promise "^3.2.1" - raw-body "^2.1.7" + debug "^3.0.1" + es6-promise "^4.1.1" + raw-body "^2.3.0" express@^4.17.0: version "4.17.1" @@ -8616,7 +8612,7 @@ raw-body@2.4.0: iconv-lite "0.4.24" unpipe "1.0.0" -raw-body@^2.1.7: +raw-body@^2.3.0: version "2.4.1" resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.1.tgz#30ac82f98bb5ae8c152e67149dac8d55153b168c" integrity sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==