Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fix jaeger: postgres is now child of route span, jaeger config update…
Browse files Browse the repository at this point in the history
… to work with docker
  • Loading branch information
oguzcankirmemis committed Jan 14, 2019
1 parent 5b0aa8b commit ace761c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 2 additions & 4 deletions public-interface/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ appServer.set('env', ENV);
appServer.set('port', api_port);
appServer.disable('x-powered-by');
appServer.enable('trust proxy');
appServer.use(bodyParser.json({limit: config.api.bodySizeLimit}));
appServer.use(bodyParser.urlencoded({extended: true, limit: config.api.bodySizeLimit}));
appServer.use(favicon(__dirname + '/dashboard/public/favicon.png'));
appServer.registerHttpContextAndStartTracing();
appServer.use(contextProvider.middleware);
appServer.startTracing();
appServer.use(compress());
if (config.api.forceSSL) {
appServer.use(forceSSL);
Expand All @@ -74,7 +73,6 @@ if (config.api.forceSSL) {
appServer.use('/ui/public', express.static('dashboard/public'));

appServer.use(httpHeadersInjector.forwardedHeaders);
appServer.use(contextProvider.middleware);
appServer.use(bodyParser.json({limit: config.api.bodySizeLimit}));
appServer.use(bodyParser.urlencoded({extended: true, limit: config.api.bodySizeLimit}));
appServer.use(XSS());
Expand Down
9 changes: 5 additions & 4 deletions public-interface/iot-entities/postgresql/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/
'use strict';
var httpContext = require('express-http-context'),
tracer = require('../../../lib/express-jaeger/').tracer,
var contextProvider = require('../../../lib/context-provider').instance(),
expressJaeger = require('../../../lib/express-jaeger'),
tracer = expressJaeger.tracer,
Sequelize = require('sequelize'),
config = require('../../../config').postgres,
accounts = require('./accounts'),
Expand Down Expand Up @@ -61,8 +62,8 @@ var sequelize = new Sequelize(
var origQueryFunc = sequelize.query;
function patchQuery() {
return function(sql, options) {
var initSpan = httpContext.get('initSpan');
var span = tracer.startSpan('postgres-call', { childOf: initSpan });
var routeSpan = contextProvider.get('routeSpan');
var span = tracer.startSpan('postgres-call', { childOf: routeSpan });
return origQueryFunc.apply(this, arguments).then(
result => {
span.finish();
Expand Down
4 changes: 3 additions & 1 deletion public-interface/lib/express-jaeger/jaeger-tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var initTracer = function(serviceName) {
},
reporter: {
logSpans: true,
agentHost: "jaeger",
agentPort: 6832
},
};
const options = {
Expand All @@ -18,7 +20,7 @@ var initTracer = function(serviceName) {
console.log("INFO ", msg);
},
error(msg) {
console.log("ERROR", msg);
console.log("ERROR ", msg);
},
},
};
Expand Down
17 changes: 8 additions & 9 deletions public-interface/lib/express-jaeger/traced-express.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var httpContext = require('express-http-context'),
var contextProvider = require('../../lib/context-provider').instance(),
express = require('express'),
tracer = require('./jaeger-tracer');

var httpContextRegistered = false;
var contextRegistered = false;

var startRequest = function(req, res, next) {
const span = tracer.startSpan('start-request');
Expand All @@ -12,8 +12,8 @@ var startRequest = function(req, res, next) {
const middlewareSpan = tracer.startSpan('middleware', { childOf: span });
const routeSpan = tracer.startSpan(req.path, { childOf: span });
routeSpan.setTag(req.method);
httpContext.set('middlewareSpan', middlewareSpan);
httpContext.set('routeSpan', routeSpan);
contextProvider.set('middlewareSpan', middlewareSpan);
contextProvider.set('routeSpan', routeSpan);
res.on('finish', function() {
span.log({
event: 'request finish'
Expand All @@ -34,10 +34,9 @@ var useOriginal = express.application.use,
deleteOriginal = express.application.delete,
allOriginal = express.application.all;

express.application['registerHttpContextAndStartTracing'] = function() {
useOriginal.apply(this, ['/', httpContext.middleware]);
express.application['startTracing'] = function() {
useOriginal.apply(this, ['/', startRequest]);
httpContextRegistered = true;
contextRegistered = true;
};

var patchMiddlewares = function(middlewares, startIndex, method, parentSpanName) {
Expand All @@ -49,7 +48,7 @@ var patchMiddlewares = function(middlewares, startIndex, method, parentSpanName)
var serviceName = middlewares[i].name;
var spanTransform = function(service, name) {
return function(req, res, next) {
const parentSpan = httpContext.get(parentSpanName);
const parentSpan = contextProvider.get(parentSpanName);
const span = tracer.startSpan(name, {
childOf: parentSpan
});
Expand All @@ -65,7 +64,7 @@ var patchMiddlewares = function(middlewares, startIndex, method, parentSpanName)

var forkedRegister = function(original, method, parentSpanName) {
return function() {
if (httpContextRegistered) {
if (contextRegistered) {
var path = typeof arguments[0] === "string" ? arguments[0] : '/';
var start = typeof arguments[0] === "string" ? 1 : 0;
patchMiddlewares(arguments, start, method, parentSpanName);
Expand Down

0 comments on commit ace761c

Please sign in to comment.