jaeger-tracer
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -0,1 +1,2 @@ | ||
import { Namespace } from 'continuation-local-storage'; | ||
import { Span } from './interfaces/jaegaer-span.interface'; | ||
@@ -5,2 +6,2 @@ export declare let associateNMSWithReqBeforeGoingNext: (req: any, res: any, next: Function, mainSpan: Span, interceptorMiddleware: Function) => void; | ||
export declare let getFromCls: (key: string) => any; | ||
export declare let getContext: () => import("continuation-local-storage").Namespace; | ||
export declare let getContext: () => Namespace; |
@@ -9,3 +9,3 @@ "use strict"; | ||
session.bindEmitter(res); | ||
session.set(constants_1.constants.mainSpan, mainSpan); | ||
exports.saveToCls(constants_1.constants.mainSpan, mainSpan); | ||
interceptorMiddleware(req, res, next); | ||
@@ -12,0 +12,0 @@ }; |
@@ -11,14 +11,15 @@ "use strict"; | ||
var tracer = tracer_1.initTracer(serviceName, config, options); | ||
return function (req, res, next) { | ||
var session = ClsManager_1.getContext(); | ||
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); | ||
}); | ||
var session = ClsManager_1.getContext(); | ||
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); | ||
}; | ||
var result = session.runAndReturn(function () { return middleware; }); | ||
console.log('result', result); | ||
return result; | ||
}; | ||
//# sourceMappingURL=middleware.js.map |
@@ -40,13 +40,15 @@ "use strict"; | ||
}); | ||
var responseSpanLog = {}; | ||
var responseSpanLog = { | ||
event: 'response', | ||
}; | ||
res.once('finish', function () { | ||
span.log(__assign({}, responseSpanLog, { headers: this.getHeaders(), statusCode: this.statusCode })); | ||
span.log(__assign({}, responseSpanLog, { headers: this.getHeaders(), statusCode: this.statusCode, statusMessage: this.statusMessage })); | ||
span.finish(); | ||
}); | ||
var responseInterceptor = function (body, req, res) { | ||
responseSpanLog = __assign({}, responseSpanLog, { event: 'response', status: 'normal', body: body }); | ||
responseSpanLog = __assign({}, responseSpanLog, { status: 'normal', body: body }); | ||
return body; | ||
}; | ||
return express_mung_1.json(responseInterceptor); | ||
return express_mung_1.json(responseInterceptor, { mungError: true }); | ||
}; | ||
//# sourceMappingURL=spanDataSetter.js.map |
{ | ||
"name": "jaeger-tracer", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "client library for jaegar to ease out the instrumenting in express and any other backend application based on express in nodejs", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -1,2 +0,2 @@ | ||
import { createNamespace } from 'continuation-local-storage'; | ||
import { createNamespace, Namespace } from 'continuation-local-storage'; | ||
import { constants } from './constants'; | ||
@@ -24,3 +24,3 @@ import { Span } from './interfaces/jaegaer-span.interface'; | ||
// and also this will always be binded to the existence to that req and res | ||
session.set(constants.mainSpan, mainSpan); | ||
saveToCls(constants.mainSpan, mainSpan); | ||
@@ -40,4 +40,4 @@ // just calling the response interceptor middleware to be applied on the response later on | ||
export let getContext = () => { | ||
export let getContext = (): Namespace => { | ||
return session; | ||
} |
@@ -8,2 +8,4 @@ import { Request, Response } from "express-serve-static-core"; | ||
import { constants } from "./constants"; | ||
import { requestWrapper } from "."; | ||
import { unirestWrapper } from "./requestWrappers"; | ||
let { FORMAT_HTTP_HEADERS } = require('opentracing'); | ||
@@ -21,2 +23,5 @@ | ||
// initiating the cls | ||
let session = getContext(); | ||
/** | ||
@@ -29,26 +34,23 @@ * @description this is an express middleware to be used to instrument an application | ||
*/ | ||
return (req: Request, res: Response, next: Function) => { | ||
let middleware = (req: Request, res: Response, next: Function) => { | ||
// saving the tracer in the cls after its initialization | ||
saveToCls(constants.tracer, tracer); | ||
// initiating the cls | ||
let session = getContext(); | ||
// extract the parent context from the tracer | ||
let parentSpanContext = tracer.extract(FORMAT_HTTP_HEADERS, req.headers); | ||
let mainReqSpan = spanMaker(req.path, parentSpanContext, tracer); | ||
// running everything inside the context | ||
session.run(() => { | ||
// saving the tracer in the cls after its initialization | ||
saveToCls(constants.tracer, tracer); | ||
// setting span data on the request | ||
setReqSpanData(req, res, mainReqSpan); | ||
// 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 response and ending the span when the response comes | ||
let responseInterceptor = setResSpanData(req, res, mainReqSpan); | ||
// setting span data on the request | ||
setReqSpanData(req, res, mainReqSpan); | ||
// calling the cls manager and after that running the response interceptor inside it | ||
associateNMSWithReqBeforeGoingNext(req, res, next, mainReqSpan, responseInterceptor); | ||
}; | ||
// 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); | ||
}); | ||
}; | ||
let result = session.runAndReturn(() => middleware); | ||
console.log('result', result); | ||
return result; | ||
} | ||
@@ -55,0 +57,0 @@ |
@@ -34,3 +34,5 @@ import { Request, Response } from "express"; | ||
let responseSpanLog = {}; | ||
let responseSpanLog: any = { | ||
event: 'response', | ||
}; | ||
@@ -42,3 +44,4 @@ res.once('finish', function (this: Response) { | ||
headers: this.getHeaders(), | ||
statusCode: this.statusCode | ||
statusCode: this.statusCode, | ||
statusMessage: this.statusMessage | ||
}); | ||
@@ -52,3 +55,2 @@ span.finish(); | ||
...responseSpanLog, | ||
event: 'response', | ||
status: 'normal', | ||
@@ -61,3 +63,3 @@ body, | ||
return json(responseInterceptor); | ||
return json(responseInterceptor, { mungError: true }); | ||
} |
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
68248
989