-
Notifications
You must be signed in to change notification settings - Fork 233
feat(http): add monitorIncomingHTTPRequests config #1298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cf0b9bc
feat(http): add monitorIncomingHTTPRequests config
Qard dfc3b57
refactor(config): rename to instrumentIncomingHTTPRequests
Qard 177cf25
test: http enable/disable combinations
Qard efaede0
chore(typings): add instrumentIncomingHTTPRequests
Qard 64ad676
docs(config): add instrumentIncomingHTTPRequests
Qard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
'use strict' | ||
|
||
const cluster = require('cluster') | ||
|
||
if (cluster.isMaster) { | ||
const test = require('tape') | ||
|
||
const findObjInArray = require('../../../_utils').findObjInArray | ||
|
||
test('http split disabling', t => { | ||
function makeTest (config, handler) { | ||
return t => { | ||
const worker = cluster.fork() | ||
worker.send(config) | ||
worker.on('message', data => { | ||
worker.disconnect() | ||
handler(t, data) | ||
}) | ||
} | ||
} | ||
|
||
function assertTopTransaction (t, transactions) { | ||
const trans = findObjInArray(transactions, 'type', 'custom') | ||
t.ok(trans, 'found top transaction') | ||
t.equal(trans.name, 'top', 'transaction name') | ||
} | ||
|
||
function assertRequestTransaction (t, transactions) { | ||
const trans = findObjInArray(transactions, 'type', 'request') | ||
t.ok(trans, 'found request transaction') | ||
t.equal(trans.name, 'GET /', 'transaction name') | ||
t.equal(trans.result, 'HTTP 2xx', 'transaction result') | ||
t.equal(trans.context.request.method, 'GET', 'transaction method') | ||
} | ||
|
||
function assertSpan (t, span) { | ||
t.ok(/GET localhost:\d+\//.test(span.name), 'span name') | ||
t.equal(span.type, 'ext.http.http', 'span type') | ||
} | ||
|
||
t.test('incoming enabled + outgoing enabled', makeTest({ | ||
disableInstrumentations: '', | ||
instrumentIncomingHTTPRequests: true | ||
}, (t, data) => { | ||
t.equal(data.transactions.length, 2, 'transaction count') | ||
t.equal(data.spans.length, 1, 'span count') | ||
|
||
assertRequestTransaction(t, data.transactions) | ||
assertTopTransaction(t, data.transactions) | ||
assertSpan(t, data.spans[0]) | ||
|
||
t.end() | ||
})) | ||
|
||
t.test('incoming enabled + outgoing disabled', makeTest({ | ||
disableInstrumentations: 'http', | ||
instrumentIncomingHTTPRequests: true | ||
}, (t, data) => { | ||
t.equal(data.transactions.length, 2, 'transaction count') | ||
t.equal(data.spans.length, 0, 'span count') | ||
|
||
assertRequestTransaction(t, data.transactions) | ||
assertTopTransaction(t, data.transactions) | ||
|
||
t.end() | ||
})) | ||
|
||
t.test('incoming disabled + outgoing enabled', makeTest({ | ||
disableInstrumentations: '', | ||
instrumentIncomingHTTPRequests: false | ||
}, (t, data) => { | ||
t.equal(data.transactions.length, 1, 'transaction count') | ||
t.equal(data.spans.length, 1, 'span count') | ||
|
||
assertTopTransaction(t, data.transactions) | ||
assertSpan(t, data.spans[0]) | ||
|
||
t.end() | ||
})) | ||
|
||
t.test('incoming disabled + outgoing disabled', makeTest({ | ||
disableInstrumentations: 'http', | ||
instrumentIncomingHTTPRequests: false | ||
}, (t, data) => { | ||
t.equal(data.transactions.length, 1, 'transaction count') | ||
t.equal(data.spans.length, 0, 'span count') | ||
|
||
assertTopTransaction(t, data.transactions) | ||
|
||
t.end() | ||
})) | ||
}) | ||
} else { | ||
const http = require('http') | ||
|
||
process.on('message', config => { | ||
class MockTransport { | ||
constructor () { | ||
this.transactions = [] | ||
this.spans = [] | ||
} | ||
|
||
config () { } | ||
|
||
sendSpan (span) { | ||
this.spans.push(span) | ||
} | ||
|
||
sendTransaction (transaction) { | ||
this.transactions.push(transaction) | ||
} | ||
} | ||
|
||
const mock = new MockTransport() | ||
|
||
const agent = require('../../../..').start(Object.assign({ | ||
captureExceptions: false, | ||
metricsInterval: 0, | ||
centralConfig: false, | ||
transport: () => mock | ||
}, config)) | ||
|
||
const express = require('express') | ||
|
||
const app = express() | ||
|
||
app.get('/', (req, res) => { | ||
res.end('hello') | ||
}) | ||
|
||
let trans | ||
sendRequest(app).then(() => { | ||
trans.end() | ||
setTimeout(() => { | ||
process.send(mock) | ||
}, 10) | ||
}) | ||
|
||
function ping (url, fn = res => res.resume()) { | ||
return new Promise((resolve, reject) => { | ||
const req = http.get(url, res => { | ||
res.on('error', reject) | ||
res.on('end', resolve) | ||
fn(res) | ||
}) | ||
req.on('error', reject) | ||
}) | ||
} | ||
|
||
function sendRequest (app) { | ||
return new Promise((resolve, reject) => { | ||
const server = app.listen(function () { | ||
const port = server.address().port | ||
trans = agent.startTransaction('top') | ||
ping(`http://localhost:${port}`) | ||
.then(resolve, reject) | ||
}) | ||
}) | ||
} | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.