Skip to content

Commit

Permalink
feat(mustCollect): add header to outgoing requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyke committed Dec 3, 2015
1 parent e6ceda2 commit 49a17fb
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/providers/httpTransaction/wraps/http.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ function wrapRequest (original, collector, config) {
var whiteListHosts = config.whiteListHosts

return function (requestParams) {
var spanId
var session = getNamespace('trace')
var requestId = session.get('request-id')
var mustCollect = session.get('mustCollect')
var clientSendTime = microtime.now()
var spanId = uuid.v1()
var collectorDataBag
var returned

if (typeof requestParams === 'string') {
requestParams = url.parse(requestParams)
Expand All @@ -25,29 +31,27 @@ function wrapRequest (original, collector, config) {
return original.apply(this, arguments)
}

var session = getNamespace('trace')
var requestId = session.get('request-id')

debug('trace id:', requestId)

var clientSendTime = microtime.now()

requestParams.headers = requestParams.headers || {}

if (requestId) {
requestParams.headers['request-id'] = requestId
}

if (mustCollect) {
requestParams.headers['X-Must-Collect'] = 1
}

if (typeof collector.getService() !== 'undefined') {
requestParams.headers['x-parent'] = collector.getService()
}

requestParams.headers['x-client-send'] = clientSendTime

spanId = uuid.v1()
requestParams.headers['x-span-id'] = spanId

var collectorDataBag = {
collectorDataBag = {
id: requestId,
host: requestParams.host,
url: requestParams.path,
Expand All @@ -64,7 +68,7 @@ function wrapRequest (original, collector, config) {
/*
* CLIENT_RECV
*/
var returned

returned = original.apply(this, arguments)

returned.on('error', function (err) {
Expand Down

0 comments on commit 49a17fb

Please sign in to comment.