jaeger-tracer
Advanced tools
Comparing version 1.0.24 to 1.1.0
@@ -1,2 +0,2 @@ | ||
import { Namespace } from 'cls-hooked'; | ||
import { Namespace } from 'continuation-local-storage'; | ||
import { Span } from './interfaces/jaegaer-span.interface'; | ||
@@ -3,0 +3,0 @@ export declare let associateNMSWithReqBeforeGoingNext: (req: any, res: any, next: Function, mainSpan: Span, interceptorMiddleware: Function) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cls_hooked_1 = require("cls-hooked"); | ||
var continuation_local_storage_1 = require("continuation-local-storage"); | ||
var constants_1 = require("./constants"); | ||
var session = cls_hooked_1.createNamespace(constants_1.constants.clsNamespace); | ||
exports.associateNMSWithReqBeforeGoingNext = session.bind(function (req, res, next, mainSpan, interceptorMiddleware) { | ||
var session = continuation_local_storage_1.createNamespace(constants_1.constants.clsNamespace); | ||
exports.associateNMSWithReqBeforeGoingNext = function (req, res, next, mainSpan, interceptorMiddleware) { | ||
session.bindEmitter(req); | ||
@@ -13,12 +13,12 @@ session.bindEmitter(res); | ||
}); | ||
}); | ||
exports.saveToCls = session.bind(function (key, value) { | ||
}; | ||
exports.saveToCls = function (key, value) { | ||
return session.set(key, value); | ||
}); | ||
exports.getFromCls = session.bind(function (key) { | ||
}; | ||
exports.getFromCls = function (key) { | ||
return session.get(key); | ||
}); | ||
exports.getContext = session.bind(function () { | ||
}; | ||
exports.getContext = function () { | ||
return session; | ||
}); | ||
}; | ||
//# sourceMappingURL=ClsManager.js.map |
@@ -6,4 +6,11 @@ export declare let initTracer: (serviceName: string, config?: import("./interfaces/jaeger-client-config.interface").Config, options?: import("./interfaces/jaeger-client-config.interface").Options) => import("./interfaces/jaegar-tracer.interface").Tracer; | ||
export declare let jaegarTracerMiddleware: (serviceName: string, config?: import("./interfaces/jaeger-client-config.interface").Config | undefined, options?: import("./interfaces/jaeger-client-config.interface").Options | undefined) => (req: import("express-serve-static-core").Request, res: import("express-serve-static-core").Response, next: Function) => void; | ||
export declare let getContext: () => import("cls-hooked").Namespace; | ||
export declare let unirestWrapper: (unirest: any) => any; | ||
export declare let requestWrapper: (request: any) => any; | ||
export declare let getContext: () => import("continuation-local-storage").Namespace; | ||
export declare let unirestWrapper: <T extends { | ||
[key: string]: any; | ||
}>(unirest: T) => T; | ||
export declare let requestWrapper: <T extends { | ||
[key: string]: any; | ||
}>(request: T) => T; | ||
export declare let getInjectionHeaders: () => { | ||
'uber-trace-id': string; | ||
}; |
@@ -16,2 +16,3 @@ "use strict"; | ||
exports.requestWrapper = requestWrappers_1.requestWrapper; | ||
exports.getInjectionHeaders = requestWrappers_1.getInjectHeaders; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var continuation_local_storage_1 = require("continuation-local-storage"); | ||
var ClsManager_1 = require("./ClsManager"); | ||
@@ -9,11 +10,14 @@ var constants_1 = require("./constants"); | ||
var FORMAT_HTTP_HEADERS = require('opentracing').FORMAT_HTTP_HEADERS; | ||
var session = continuation_local_storage_1.getNamespace(constants_1.constants.clsNamespace); | ||
exports.jaegarTracerMiddleWare = function (serviceName, config, options) { | ||
var tracer = tracer_1.initTracer(serviceName, config, options); | ||
var middleware = function (req, res, next) { | ||
ClsManager_1.saveToCls(constants_1.constants.tracer, tracer); | ||
var parentSpanContext = tracer.extract(FORMAT_HTTP_HEADERS, req.headers); | ||
var mainReqSpan = span_1.spanMaker(req.path, parentSpanContext, tracer); | ||
spanDataSetter_1.setReqSpanData(req, res, mainReqSpan); | ||
var responseInterceptor = spanDataSetter_1.setResSpanData(req, res, mainReqSpan); | ||
ClsManager_1.associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor); | ||
session.run(function () { | ||
ClsManager_1.saveToCls(constants_1.constants.tracer, tracer); | ||
var parentSpanContext = tracer.extract(FORMAT_HTTP_HEADERS, req.headers); | ||
var mainReqSpan = span_1.spanMaker(req.path, parentSpanContext, tracer); | ||
spanDataSetter_1.setReqSpanData(req, res, mainReqSpan); | ||
var responseInterceptor = spanDataSetter_1.setResSpanData(req, res, mainReqSpan); | ||
ClsManager_1.associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor); | ||
}); | ||
}; | ||
@@ -20,0 +24,0 @@ return middleware; |
@@ -1,2 +0,9 @@ | ||
export declare let unirestWrapper: (unirest: any) => any; | ||
export declare let requestWrapper: (request: any) => any; | ||
export declare let unirestWrapper: <T extends { | ||
[key: string]: any; | ||
}>(unirest: T) => T; | ||
export declare let requestWrapper: <T extends { | ||
[key: string]: any; | ||
}>(request: T) => T; | ||
export declare let getInjectHeaders: () => { | ||
'uber-trace-id': string; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ClsManager_1 = require("./ClsManager"); | ||
var constants_1 = require("./constants"); | ||
var FORMAT_HTTP_HEADERS = require('opentracing').FORMAT_HTTP_HEADERS; | ||
var continuation_local_storage_1 = require("continuation-local-storage"); | ||
var session = continuation_local_storage_1.getNamespace(constants_1.constants.clsNamespace); | ||
exports.unirestWrapper = function (unirest) { | ||
@@ -11,3 +10,3 @@ if (!unirest.request) | ||
var baseRequest = unirest.request; | ||
var headers = getInjectHeaders(); | ||
var headers = exports.getInjectHeaders(); | ||
baseRequest = baseRequest.defaults({ | ||
@@ -22,3 +21,3 @@ headers: headers | ||
throw Error('This is not a request object please provide a request object'); | ||
var headers = getInjectHeaders(); | ||
var headers = exports.getInjectHeaders(); | ||
var baseRequest = request.defaults({ | ||
@@ -29,5 +28,5 @@ headers: headers | ||
}; | ||
var getInjectHeaders = function () { | ||
var tracer = session.get(constants_1.constants.mainSpan); | ||
var span = session.get(constants_1.constants.mainSpan); | ||
exports.getInjectHeaders = function () { | ||
var tracer = ClsManager_1.getFromCls(constants_1.constants.tracer); | ||
var span = ClsManager_1.getFromCls(constants_1.constants.mainSpan); | ||
var headers = {}; | ||
@@ -34,0 +33,0 @@ tracer.inject(span, FORMAT_HTTP_HEADERS, headers); |
@@ -8,2 +8,3 @@ "use strict"; | ||
return tracer.startSpan(name); | ||
ClsManager_1.saveToCls(constants_1.constants.parentContext, parentContext); | ||
return tracer.startSpan(name, { | ||
@@ -10,0 +11,0 @@ childOf: parentContext |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var mergeDeep = require('merge-deep'); | ||
var initJaegerTracer = require('jaeger-client').initTracer; | ||
@@ -18,10 +8,15 @@ exports.initTracer = function (serviceName, config, options) { | ||
if (options === void 0) { options = {}; } | ||
config = __assign({ serviceName: serviceName, sampler: { | ||
config = mergeDeep({ | ||
serviceName: serviceName, | ||
sampler: { | ||
type: "const", | ||
param: 1, | ||
}, reporter: { | ||
}, | ||
reporter: { | ||
logSpans: true, | ||
agentHost: 'jaegar' | ||
} }, config); | ||
options = __assign({ logger: { | ||
} | ||
}, config); | ||
options = mergeDeep({ | ||
logger: { | ||
info: function (msg) { | ||
@@ -32,4 +27,5 @@ console.log("INFO ", msg); | ||
console.log("ERROR", msg); | ||
}, | ||
} }, options); | ||
} | ||
} | ||
}, options); | ||
var tracer = initJaegerTracer(config, options); | ||
@@ -36,0 +32,0 @@ return tracer; |
{ | ||
"name": "jaeger-tracer", | ||
"version": "1.0.24", | ||
"version": "1.1.0", | ||
"description": "client library for jaegar to ease out the instrumenting in express and any other backend application based on express in nodejs", | ||
@@ -31,11 +31,9 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"cls-hooked": "^4.2.2", | ||
"continuation-local-storage": "^3.2.1", | ||
"express-interceptor": "^1.2.0", | ||
"express-mung": "^0.5.1", | ||
"jaeger-client": "^3.13.0", | ||
"merge-deep": "^3.0.2", | ||
"opentracing": "^0.14.3" | ||
}, | ||
"devDependencies": { | ||
"@types/cls-hooked": "^4.2.1", | ||
"@types/continuation-local-storage": "^3.2.1", | ||
@@ -42,0 +40,0 @@ "@types/express": "^4.16.0", |
@@ -1,2 +0,2 @@ | ||
import { createNamespace, Namespace, getNamespace } from 'cls-hooked'; | ||
import { createNamespace, Namespace, getNamespace } from 'continuation-local-storage'; | ||
import { constants } from './constants'; | ||
@@ -13,3 +13,3 @@ import { Span } from './interfaces/jaegaer-span.interface'; | ||
*/ | ||
export let associateNMSWithReqBeforeGoingNext = session.bind(function (req: any, res: any, next: Function, mainSpan: Span, interceptorMiddleware: Function) { | ||
export let associateNMSWithReqBeforeGoingNext = function (req: any, res: any, next: Function, mainSpan: Span, interceptorMiddleware: Function) { | ||
// before rerouting just inputing binding the req , and res to the cls to | ||
@@ -29,14 +29,14 @@ // be used later to the spans | ||
}); | ||
}); | ||
} | ||
export let saveToCls = session.bind((key: string, value: any) => { | ||
export let saveToCls = (key: string, value: any) => { | ||
return session.set(key, value); | ||
}); | ||
} | ||
export let getFromCls = session.bind((key: string) => { | ||
export let getFromCls = (key: string) => { | ||
return session.get(key); | ||
}); | ||
} | ||
export let getContext = session.bind((): Namespace => { | ||
export let getContext = (): Namespace => { | ||
return session; | ||
}); | ||
} |
@@ -5,3 +5,3 @@ import { getContext as gc } from './ClsManager'; | ||
import { jaegarTracerMiddleWare as jtm } from './middleware'; | ||
import { requestWrapper as rw, unirestWrapper as uw } from './requestWrappers'; | ||
import { requestWrapper as rw, unirestWrapper as uw, getInjectHeaders as gih } from './requestWrappers'; | ||
@@ -37,2 +37,3 @@ | ||
export let unirestWrapper = uw; | ||
export let requestWrapper = rw; | ||
export let requestWrapper = rw; | ||
export let getInjectionHeaders = gih; |
@@ -0,1 +1,2 @@ | ||
import { getNamespace } from 'continuation-local-storage'; | ||
import { Request, Response } from "express-serve-static-core"; | ||
@@ -9,2 +10,3 @@ import { associateNMSWithReqBeforeGoingNext, saveToCls } from "./ClsManager"; | ||
let { FORMAT_HTTP_HEADERS } = require('opentracing'); | ||
let session = getNamespace(constants.clsNamespace); | ||
@@ -28,17 +30,19 @@ /** | ||
let middleware = (req: Request, res: Response, next: Function) => { | ||
// saving the tracer in the cls after its initialization | ||
saveToCls(constants.tracer, tracer); | ||
session.run(() => { | ||
// saving the tracer in the cls after its initialization | ||
saveToCls(constants.tracer, tracer); | ||
// extract the parent context from the tracer | ||
let parentSpanContext = tracer.extract(FORMAT_HTTP_HEADERS, req.headers); | ||
let mainReqSpan = spanMaker(req.path, parentSpanContext, tracer); | ||
// extract the parent context from the tracer | ||
let parentSpanContext = tracer.extract(FORMAT_HTTP_HEADERS, req.headers); | ||
let mainReqSpan = spanMaker(req.path, parentSpanContext, tracer); | ||
// setting span data on the request | ||
setReqSpanData(req, res, mainReqSpan); | ||
// setting span data on the request | ||
setReqSpanData(req, res, mainReqSpan); | ||
// setting span data on the response and ending the span when the response comes | ||
let responseInterceptor = setResSpanData(req, res, mainReqSpan); | ||
// setting span data on the response and ending the span when the response comes | ||
let responseInterceptor = setResSpanData(req, res, mainReqSpan); | ||
// calling the cls manager and after that running the response interceptor inside it | ||
associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor); | ||
// calling the cls manager and after that running the response interceptor inside it | ||
associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor); | ||
}); | ||
}; | ||
@@ -45,0 +49,0 @@ |
@@ -6,4 +6,2 @@ import { getFromCls } from "./ClsManager"; | ||
const { FORMAT_HTTP_HEADERS } = require('opentracing'); | ||
import { getNamespace } from 'continuation-local-storage'; | ||
let session = getNamespace(constants.clsNamespace); | ||
@@ -15,3 +13,3 @@ /** | ||
*/ | ||
export let unirestWrapper = (unirest: any) => { | ||
export let unirestWrapper = <T extends { [key: string]: any }>(unirest: T): T => { | ||
if (!unirest.request) | ||
@@ -44,3 +42,3 @@ throw Error('This is not a unirest object please provide a unirest object'); | ||
*/ | ||
export let requestWrapper = (request: any) => { | ||
export let requestWrapper = <T extends { [key: string]: any }>(request: T): T => { | ||
if (!request.defaults) | ||
@@ -64,12 +62,9 @@ throw Error('This is not a request object please provide a request object'); | ||
*/ | ||
let getInjectHeaders = () => { | ||
export let getInjectHeaders = (): { 'uber-trace-id': string } => { | ||
// getting the main span from the cls | ||
// let tracer: any = getFromCls(constants.tracer); | ||
// let span: any = getFromCls(constants.mainSpan); | ||
let tracer: Tracer = getFromCls(constants.tracer); | ||
let span: Span = getFromCls(constants.mainSpan); | ||
let tracer = session.get(constants.mainSpan); | ||
let span = session.get(constants.mainSpan); | ||
let headers: any = {}; | ||
let headers = {}; | ||
// setting the needed headers for injection of parent span | ||
@@ -76,0 +71,0 @@ tracer.inject(span, FORMAT_HTTP_HEADERS, headers); |
@@ -1,2 +0,2 @@ | ||
import { getFromCls } from './ClsManager'; | ||
import { getFromCls, saveToCls } from './ClsManager'; | ||
import { constants } from "./constants"; | ||
@@ -17,2 +17,3 @@ import { SpanContext } from "./interfaces/jaegaer-span.interface"; | ||
saveToCls(constants.parentContext, parentContext); | ||
// make the span with a parent context in any other case | ||
@@ -31,3 +32,3 @@ return tracer.startSpan(name, { | ||
// get tracer from the cls | ||
let tracer: any = getFromCls(constants.tracer); | ||
let tracer: Tracer = getFromCls(constants.tracer); | ||
@@ -34,0 +35,0 @@ // getting the parent context from the cls |
import { Tracer } from "./interfaces/jaegar-tracer.interface"; | ||
import { Config, Options } from "./interfaces/jaeger-client-config.interface"; | ||
let mergeDeep = require('merge-deep'); | ||
const { initTracer: initJaegerTracer } = require('jaeger-client'); | ||
@@ -27,3 +27,3 @@ | ||
// this is the configuration options | ||
config = { | ||
config = mergeDeep({ | ||
serviceName: serviceName, | ||
@@ -37,8 +37,7 @@ sampler: { | ||
agentHost: 'jaegar' | ||
}, | ||
...config | ||
}; | ||
} | ||
}, config); | ||
// options of the tracer | ||
options = { | ||
options = mergeDeep({ | ||
logger: { | ||
@@ -50,6 +49,5 @@ info(msg: any) { | ||
console.log("ERROR", msg); | ||
}, | ||
}, | ||
...options | ||
}; | ||
} | ||
} | ||
}, options); | ||
@@ -56,0 +54,0 @@ // initialize the tracer |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
72119
5
4
1003
+ Addedmerge-deep@^3.0.2
+ Addedarr-union@3.1.0(transitive)
+ Addedclone-deep@0.2.4(transitive)
+ Addedfor-in@0.1.81.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedkind-of@2.0.13.2.2(transitive)
+ Addedlazy-cache@0.2.71.0.4(transitive)
+ Addedmerge-deep@3.0.3(transitive)
+ Addedmixin-object@2.0.1(transitive)
+ Addedshallow-clone@0.1.2(transitive)
- Removedcls-hooked@^4.2.2
- Removedexpress-interceptor@^1.2.0
- Removedasync-hook-jl@1.7.6(transitive)
- Removedcls-hooked@4.2.2(transitive)
- Removeddebug@2.6.9(transitive)
- Removedexpress-interceptor@1.2.0(transitive)
- Removedms@2.0.0(transitive)
- Removedstack-chain@1.3.7(transitive)