zipkin-instrumentation-fetch
Advanced tools
Comparing version 0.9.0 to 0.10.0
'use strict'; | ||
var _require = require('zipkin'), | ||
Annotation = _require.Annotation, | ||
Request = _require.Request; | ||
Instrumentation = _require.Instrumentation; | ||
@@ -13,2 +12,3 @@ function wrapFetch(fetch, _ref) { | ||
var instrumentation = new Instrumentation.HttpClient({ tracer: tracer, serviceName: serviceName, remoteServiceName: remoteServiceName }); | ||
return function zipkinfetch(url) { | ||
@@ -19,23 +19,9 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
tracer.scoped(function () { | ||
tracer.setId(tracer.createChildId()); | ||
var method = opts.method || 'GET'; | ||
var zipkinOpts = instrumentation.recordRequest(opts, url, method); | ||
var traceId = tracer.id; | ||
var method = opts.method || 'GET'; | ||
tracer.recordServiceName(serviceName); | ||
tracer.recordRpc(method.toUpperCase()); | ||
tracer.recordBinary('http.url', url); | ||
tracer.recordAnnotation(new Annotation.ClientSend()); | ||
if (remoteServiceName) { | ||
// TODO: can we get the host and port of the http connection? | ||
tracer.recordAnnotation(new Annotation.ServerAddr({ | ||
serviceName: remoteServiceName | ||
})); | ||
} | ||
var zipkinOpts = Request.addZipkinHeaders(opts, traceId); | ||
fetch(url, zipkinOpts).then(function (res) { | ||
tracer.scoped(function () { | ||
tracer.setId(traceId); | ||
tracer.recordBinary('http.status_code', res.status.toString()); | ||
tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
instrumentation.recordResponse(traceId, res.status); | ||
}); | ||
@@ -45,5 +31,3 @@ resolve(res); | ||
tracer.scoped(function () { | ||
tracer.setId(traceId); | ||
tracer.recordBinary('error', err.toString()); | ||
tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
instrumentation.recordError(traceId, err); | ||
}); | ||
@@ -50,0 +34,0 @@ reject(err); |
{ | ||
"name": "zipkin-instrumentation-fetch", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "Interceptor for HTTP clients using the 'fetch' API", | ||
@@ -19,4 +19,4 @@ "main": "lib/index.js", | ||
"node-fetch": "^1.5.3", | ||
"zipkin": "^0.9.0" | ||
"zipkin": "^0.10.0" | ||
} | ||
} |
@@ -1,28 +0,18 @@ | ||
const {Annotation, Request} = require('zipkin'); | ||
const { | ||
Instrumentation | ||
} = require('zipkin'); | ||
function wrapFetch(fetch, {tracer, serviceName = 'unknown', remoteServiceName}) { | ||
const instrumentation = new Instrumentation.HttpClient({tracer, serviceName, remoteServiceName}); | ||
return function zipkinfetch(url, opts = {}) { | ||
return new Promise((resolve, reject) => { | ||
tracer.scoped(() => { | ||
tracer.setId(tracer.createChildId()); | ||
const method = opts.method || 'GET'; | ||
const zipkinOpts = | ||
instrumentation.recordRequest(opts, url, method); | ||
const traceId = tracer.id; | ||
const method = opts.method || 'GET'; | ||
tracer.recordServiceName(serviceName); | ||
tracer.recordRpc(method.toUpperCase()); | ||
tracer.recordBinary('http.url', url); | ||
tracer.recordAnnotation(new Annotation.ClientSend()); | ||
if (remoteServiceName) { | ||
// TODO: can we get the host and port of the http connection? | ||
tracer.recordAnnotation(new Annotation.ServerAddr({ | ||
serviceName: remoteServiceName | ||
})); | ||
} | ||
const zipkinOpts = Request.addZipkinHeaders(opts, traceId); | ||
fetch(url, zipkinOpts).then(res => { | ||
tracer.scoped(() => { | ||
tracer.setId(traceId); | ||
tracer.recordBinary('http.status_code', res.status.toString()); | ||
tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
instrumentation.recordResponse(traceId, res.status); | ||
}); | ||
@@ -32,5 +22,3 @@ resolve(res); | ||
tracer.scoped(() => { | ||
tracer.setId(traceId); | ||
tracer.recordBinary('error', err.toString()); | ||
tracer.recordAnnotation(new Annotation.ClientRecv()); | ||
instrumentation.recordError(traceId, err); | ||
}); | ||
@@ -37,0 +25,0 @@ reject(err); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9430
8
183
5