Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zipkin-instrumentation-fetch

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zipkin-instrumentation-fetch - npm Package Compare versions

Comparing version 0.2.7 to 0.4.0

4

package.json
{
"name": "zipkin-instrumentation-fetch",
"version": "0.2.7",
"version": "0.4.0",
"description": "Interceptor for HTTP clients using the 'fetch' API",

@@ -15,4 +15,4 @@ "main": "index.js",

"node-fetch": "^1.5.1",
"zipkin": "^0.2.7"
"zipkin": "^0.4.0"
}
}

@@ -17,3 +17,3 @@ # zipkin-instrumentation-fetch

const nameOfRemoteService = 'youtube';
const zipkinFetch = wrapFetch(fetch, {tracer, serviceName: nameOfRemoteService});
const zipkinFetch = wrapFetch(fetch, {tracer, remoteServiceName: nameOfRemoteService});

@@ -20,0 +20,0 @@ // Your application code here

@@ -18,3 +18,3 @@ const {HttpHeaders, Annotation} = require('zipkin');

function wrapFetch(fetch, {serviceName, tracer}) {
function wrapFetch(fetch, {tracer, serviceName = 'unknown', remoteServiceName}) {
return function zipkinfetch(url, opts = {}) {

@@ -31,2 +31,8 @@ return new Promise((resolve, reject) => {

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
}));
}

@@ -33,0 +39,0 @@ const headers = getHeaders(traceId, opts);

@@ -31,3 +31,7 @@ const {Tracer, ExplicitContext, createNoopTracer} = require('zipkin');

const fetch = wrapFetch(nodeFetch, {serviceName: 'user-service', tracer});
const fetch = wrapFetch(nodeFetch, {
tracer,
serviceName: 'caller',
remoteServiceName: 'callee'
});

@@ -51,3 +55,3 @@ ctxImpl.scoped(() => {

expect(annotations[0].annotation.annotationType).to.equal('ServiceName');
expect(annotations[0].annotation.serviceName).to.equal('user-service');
expect(annotations[0].annotation.serviceName).to.equal('caller');

@@ -63,8 +67,11 @@ expect(annotations[1].annotation.annotationType).to.equal('Rpc');

expect(annotations[4].annotation.annotationType).to.equal('BinaryAnnotation');
expect(annotations[4].annotation.key).to.equal('http.status_code');
expect(annotations[4].annotation.value).to.equal('202');
expect(annotations[4].annotation.annotationType).to.equal('ServerAddr');
expect(annotations[4].annotation.serviceName).to.equal('callee');
expect(annotations[5].annotation.annotationType).to.equal('ClientRecv');
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation');
expect(annotations[5].annotation.key).to.equal('http.status_code');
expect(annotations[5].annotation.value).to.equal('202');
expect(annotations[6].annotation.annotationType).to.equal('ClientRecv');
const traceIdOnServer = data.traceId;

@@ -71,0 +78,0 @@ expect(traceIdOnServer).to.equal(traceId);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc