zipkin-instrumentation-cujojs-rest
Advanced tools
Comparing version 0.5.1 to 0.6.0
{ | ||
"name": "zipkin-instrumentation-cujojs-rest", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Interceptor for instrumenting HTTP calls from the cujoJS rest library", | ||
"main": "index.js", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "node ../../node_modules/mocha/bin/mocha --require ../../test/helper.js" | ||
"build": "../../node_modules/.bin/babel src -d lib", | ||
"test": "node ../../node_modules/mocha/bin/mocha --require ../../test/helper.js", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -15,4 +17,4 @@ "author": "OpenZipkin <openzipkin.alt@gmail.com>", | ||
"rest": "^1.3.2", | ||
"zipkin": "^0.5.1" | ||
"zipkin": "^0.6.0" | ||
} | ||
} |
/* eslint-disable no-param-reassign */ | ||
const interceptor = require('rest/interceptor'); | ||
const { | ||
HttpHeaders: Header, | ||
Annotation | ||
} = require('zipkin'); | ||
Annotation, | ||
Request | ||
} = require('zipkin'); | ||
@@ -20,21 +20,12 @@ function getRequestMethod(req) { | ||
function request(req, {tracer, serviceName = 'unknown', remoteServiceName}) { | ||
tracer.scoped(() => { | ||
return tracer.scoped(() => { | ||
tracer.setId(tracer.createChildId()); | ||
const traceId = tracer.id; | ||
this.traceId = traceId; | ||
const reqWithHeaders = Request.addZipkinHeaders(req, traceId); | ||
req.headers = req.headers || {}; | ||
req.headers[Header.TraceId] = traceId.traceId; | ||
req.headers[Header.SpanId] = traceId.spanId; | ||
traceId._parentId.ifPresent(psid => { | ||
req.headers[Header.ParentSpanId] = psid; | ||
}); | ||
traceId.sampled.ifPresent(sampled => { | ||
req.headers[Header.Sampled] = sampled ? '1' : '0'; | ||
}); | ||
const method = getRequestMethod(req); | ||
const method = getRequestMethod(reqWithHeaders); | ||
tracer.recordServiceName(serviceName); | ||
tracer.recordRpc(method.toUpperCase()); | ||
tracer.recordBinary('http.url', req.path); | ||
tracer.recordBinary('http.url', reqWithHeaders.path); | ||
tracer.recordAnnotation(new Annotation.ClientSend()); | ||
@@ -47,5 +38,4 @@ if (remoteServiceName) { | ||
} | ||
return reqWithHeaders; | ||
}); | ||
return req; | ||
} | ||
@@ -52,0 +42,0 @@ |
7524
8
163