Skip to content

Commit abb8daf

Browse files
peteyyczgergelyke
authored andcommitted
fix(spanId): fix spanId collecting
1 parent 8c64375 commit abb8daf

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/providers/httpTransaction/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,15 @@ HttpTransaction.prototype.onClientSend = function (data) {
122122

123123
HttpTransaction.prototype.onClientReceive = function (data) {
124124
var trace = this._initTrace(data);
125-
var spanId;
126-
127-
if (data.headers) {
128-
spanId = data.headers['x-span-id'];
129-
}
130125

131126
if (data.err) {
132127
trace.isSampled = true;
133128
}
134129

135130
trace.events.push({
136-
id: spanId,
131+
id: data.spanId,
132+
host: data.host,
133+
url: data.url,
137134
time: data.time,
138135
type: HttpTransaction.CLIENT_RECV,
139136
data: data.err,

lib/providers/httpTransaction/index.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ describe('The HttpTransaction module', function () {
6262
var headers = {
6363
'x-span-id': spanId
6464
};
65+
var host = 'localhost:3000';
6566

6667
httpTransaction.onClientReceive({
6768
id: id,
68-
url: '/fruits/apple',
69+
spanId: spanId,
70+
url: url,
6971
time: time,
70-
host: 'localhost:3000',
72+
host: host,
7173
statusCode: 301,
7274
headers: headers
7375
});
@@ -82,6 +84,8 @@ describe('The HttpTransaction module', function () {
8284
{
8385
statusCode: 301,
8486
id: spanId,
87+
url: url,
88+
host: host,
8589
time: time,
8690
type: 'cr',
8791
data: undefined

lib/providers/httpTransaction/wraps/http.request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Collector = require('../');
88

99
function wrapRequest (original, collector, config) {
1010

11+
var spanId;
1112
var whiteListHosts = config.whiteListHosts;
1213

1314
return function (requestParams) {
@@ -44,7 +45,8 @@ function wrapRequest (original, collector, config) {
4445

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

47-
requestParams.headers['x-span-id'] = uuid.v1();
48+
spanId = uuid.v1();
49+
requestParams.headers['x-span-id'] = spanId;
4850

4951
var collectorDataBag = {
5052
id: requestId,
@@ -69,6 +71,7 @@ function wrapRequest (original, collector, config) {
6971
returned.on('error', function (err) {
7072
var collectorDataBag = {
7173
id: requestId,
74+
spanId: spanId,
7275
host: requestParams.host,
7376
url: requestParams.path,
7477
time: microtime.now(),
@@ -82,6 +85,7 @@ function wrapRequest (original, collector, config) {
8285
returned.on('response', function (incomingMessage) {
8386
var collectorDataBag = {
8487
id: requestId,
88+
spanId: spanId,
8589
host: requestParams.host,
8690
url: requestParams.path,
8791
time: microtime.now(),

0 commit comments

Comments
 (0)