zipkin-instrumentation-cujojs-rest
Advanced tools
Comparing version 0.1.9 to 0.2.0
{ | ||
"name": "zipkin-instrumentation-cujojs-rest", | ||
"version": "0.1.9", | ||
"version": "0.2.0", | ||
"description": "Interceptor for instrumenting HTTP calls from the cujoJS rest library", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
}, | ||
"author": "Openzipkin <openzipkin.alt@gmail.com>", | ||
"author": "OpenZipkin <openzipkin.alt@gmail.com>", | ||
"license": "Apache-2.0", | ||
@@ -15,7 +15,5 @@ "repository": "https://github.com/openzipkin/zipkin-js", | ||
"express": "^4.13.4", | ||
"rest": "^1.3.2" | ||
}, | ||
"peerDependencies": { | ||
"zipkin": "^0.1.9" | ||
"rest": "^1.3.2", | ||
"zipkin": "^0.2.0" | ||
} | ||
} |
/* eslint-disable no-param-reassign */ | ||
const interceptor = require('rest/interceptor'); | ||
const { | ||
trace, | ||
HttpHeaders: Header, | ||
@@ -20,14 +19,6 @@ Annotation | ||
function request(req, {serviceName}) { | ||
function recordTraceData(name) { | ||
const method = getRequestMethod(req); | ||
trace.recordServiceName(name); | ||
trace.recordRpc(method.toUpperCase()); | ||
trace.recordBinary('http.url', req.path); | ||
trace.recordAnnotation(new Annotation.ClientSend()); | ||
} | ||
trace.withContext(() => { | ||
trace.setId(trace.nextId()); | ||
const traceId = trace.id(); | ||
function request(req, {serviceName, tracer}) { | ||
tracer.scoped(() => { | ||
tracer.setId(tracer.createChildId()); | ||
const traceId = tracer.id; | ||
this.traceId = traceId; | ||
@@ -45,9 +36,7 @@ | ||
if (trace.isActivelyTracing()) { | ||
if (serviceName instanceof Function) { | ||
serviceName(req, recordTraceData); | ||
} else { | ||
recordTraceData(serviceName); | ||
} | ||
} | ||
const method = getRequestMethod(req); | ||
tracer.recordServiceName(serviceName); | ||
tracer.recordRpc(method.toUpperCase()); | ||
tracer.recordBinary('http.url', req.path); | ||
tracer.recordAnnotation(new Annotation.ClientSend()); | ||
}); | ||
@@ -58,7 +47,7 @@ | ||
function response(res) { | ||
trace.withContext(() => { | ||
trace.setId(this.traceId); | ||
trace.recordBinary('http.status_code', res.status.code.toString()); | ||
trace.recordAnnotation(new Annotation.ClientRecv()); | ||
function response(res, {tracer}) { | ||
tracer.scoped(() => { | ||
tracer.setId(this.traceId); | ||
tracer.recordBinary('http.status_code', res.status.code.toString()); | ||
tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
}); | ||
@@ -65,0 +54,0 @@ return res; |
@@ -1,2 +0,2 @@ | ||
const {trace} = require('zipkin'); | ||
const {Tracer, ExplicitContext} = require('zipkin'); | ||
const express = require('express'); | ||
@@ -19,6 +19,8 @@ const sinon = require('sinon'); | ||
const record = sinon.spy(); | ||
const tracer = {record}; | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
trace.letTracer(tracer, () => { | ||
const client = rest.wrap(restInterceptor, {serviceName: 'service-a'}); | ||
tracer.scoped(() => { | ||
const client = rest.wrap(restInterceptor, {tracer, serviceName: 'service-a'}); | ||
const port = server.address().port; | ||
@@ -25,0 +27,0 @@ const path = `http://127.0.0.1:${port}/abc`; |
Sorry, the diff of this file is not supported yet
0
5039
3
112