Skip to content

Commit

Permalink
Assign url field in Connect and Koa (#448)
Browse files Browse the repository at this point in the history
PR-URL: #448
  • Loading branch information
kjin committed Mar 22, 2017
1 parent c108b35 commit 733f33c
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 58 deletions.
1 change: 1 addition & 0 deletions src/plugins/plugin-connect.js
Expand Up @@ -23,6 +23,7 @@ function createMiddleware(api) {
return function middleware(req, res, next) {
var options = {
name: urlParse(req.originalUrl).pathname,
url: req.originalUrl,
traceContext: req.headers[api.constants.TRACE_CONTEXT_HEADER_NAME.toLowerCase()],
skipFrames: 3
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/plugin-hapi.js
Expand Up @@ -37,7 +37,7 @@ function createMiddleware(api) {
var originalEnd = res.end;
var options = {
name: urlParse(req.url).pathname,
url: urlParse(req.url).pathname,
url: req.url,
traceContext: req.headers[api.constants.TRACE_CONTEXT_HEADER_NAME],
skipFrames: 3
};
Expand Down
1 change: 1 addition & 0 deletions src/plugins/plugin-koa.js
Expand Up @@ -40,6 +40,7 @@ function createMiddleware(api) {
const originalEnd = res.end;
var options = {
name: urlParse(req.url).pathname,
url: req.url,
traceContext: this.req.headers[api.constants.TRACE_CONTEXT_HEADER_NAME],
skipFrames: 3
};
Expand Down
18 changes: 17 additions & 1 deletion test/plugins/test-trace-connect.js
Expand Up @@ -28,7 +28,10 @@ describe('test-trace-connect', function() {
var agent;
var connect;
before(function() {
agent = require('../..').start({ samplingRate: 0 });
agent = require('../..').start({
ignoreUrls: ['/ignore'],
samplingRate: 0
});
connect = require('./fixtures/connect3');
// Mute stderr to satiate appveyor
write = process.stderr.write;
Expand Down Expand Up @@ -165,6 +168,19 @@ describe('test-trace-connect', function() {
});
});
});

it('should not trace ignored urls', function(done) {
var app = connect();
app.use('/ignore/me', function (req, res) {
res.end(common.serverRes);
});
server = app.listen(common.serverPort, function() {
http.get({port: common.serverPort, path: '/ignore/me'}, function(res) {
assert.equal(common.getTraces(agent).length, 0);
done();
});
});
});
});

function connectPredicate(span) {
Expand Down
18 changes: 17 additions & 1 deletion test/plugins/test-trace-express.js
Expand Up @@ -28,7 +28,10 @@ describe('test-trace-express', function() {
var agent;
var express;
before(function() {
agent = require('../..').start({ samplingRate: 0 });
agent = require('../..').start({
ignoreUrls: ['/ignore'],
samplingRate: 0
});
express = require('./fixtures/express4');

// Mute stderr to satiate appveyor
Expand Down Expand Up @@ -234,6 +237,19 @@ describe('test-trace-express', function() {
});
});
});

it('should not trace ignored urls', function(done) {
var app = express();
app.get('/ignore/me', function (req, res) {
res.send(common.serverRes);
});
server = app.listen(common.serverPort, function() {
http.get({port: common.serverPort, path: '/ignore/me'}, function(res) {
assert.equal(common.getTraces(agent).length, 0);
done();
});
});
});
});

function expressPredicate(span) {
Expand Down
23 changes: 22 additions & 1 deletion test/plugins/test-trace-hapi.js
Expand Up @@ -41,7 +41,10 @@ describe('hapi', function() {
var agent;

before(function() {
agent = require('../..').start({ samplingRate: 0 });
agent = require('../..').start({
ignoreUrls: ['/ignore'],
samplingRate: 0
});
});

Object.keys(versions).forEach(function(version) {
Expand Down Expand Up @@ -280,6 +283,24 @@ describe('hapi', function() {
});
});
});

it('should not trace ignored urls', function(done) {
server = new hapi.Server();
server.connection({ port: common.serverPort });
server.route({
method: 'GET',
path: '/ignore/me',
handler: function (req, reply) {
reply(common.serverRes);
}
});
server.start(function() {
http.get({port: common.serverPort, path: '/ignore/me'}, function(res) {
assert.equal(common.getTraces(agent).length, 0);
done();
});
});
});
});
});
});
Expand Down
22 changes: 21 additions & 1 deletion test/plugins/test-trace-koa.js
Expand Up @@ -27,7 +27,10 @@ describe('test-trace-koa', function() {
var agent;
var koa;
before(function() {
agent = require('../..').start();
agent = require('../..').start({
ignoreUrls: ['/ignore'],
samplingRate: 0
});
koa = require('./fixtures/koa1');
});

Expand Down Expand Up @@ -136,6 +139,23 @@ describe('test-trace-koa', function() {
});
});
});

it('should not trace ignored urls', function(done) {
var app = koa();
app.use(function* () {
this.body = yield function(cb) {
setTimeout(function() {
cb(null, common.serverRes);
}, common.serverWait);
};
});
server = app.listen(common.serverPort, function() {
http.get({port: common.serverPort, path: '/ignore/me'}, function(res) {
assert.equal(common.getTraces(agent).length, 0);
done();
});
});
});
});

function koaPredicate(span) {
Expand Down
23 changes: 22 additions & 1 deletion test/plugins/test-trace-restify.js
Expand Up @@ -32,7 +32,10 @@ describe('restify', function() {
var agent;

before(function() {
agent = require('../..').start({ samplingRate: 0 });
agent = require('../..').start({
ignoreUrls: ['/ignore'],
samplingRate: 0
});
});

var server;
Expand Down Expand Up @@ -235,6 +238,24 @@ describe('restify', function() {
});
});
});

it('should not trace ignored urls', function(done) {
server = restify.createServer();
server.get('/ignore/me', function (req, res, next) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.write(common.serverRes);
res.end();
return next();
});
server.listen(common.serverPort, function() {
http.get({port: common.serverPort, path: '/ignore/me'}, function(res) {
assert.equal(common.getTraces(agent).length, 0);
done();
});
});
});
});
});
});
Expand Down
52 changes: 0 additions & 52 deletions test/test-ignore-url-express.js

This file was deleted.

0 comments on commit 733f33c

Please sign in to comment.