Skip to content

Commit

Permalink
Treat spanIds as strings to avoid integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Mar 16, 2016
1 parent 58445fa commit 9f1bdea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/trace-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ TraceAgent.prototype.shouldTrace = function(name) {
*/
TraceAgent.prototype.createRootSpanData = function(name, traceId, parentId) {
traceId = traceId || (uuid.v4().split('-').join(''));
parentId = parentId || 0;
parentId = parentId || '0';
var trace = new Trace(0, traceId); // project number added later
var spanData = new SpanData(this, trace, name, parentId, true);
cls.setRootContext(spanData);
Expand Down Expand Up @@ -208,7 +208,7 @@ TraceAgent.prototype.parseContextFromHeader = function(str) {
}
return {
traceId: matches[1],
spanId: Number(matches[2]),
spanId: matches[2],
options: matches[3]
};
};
Expand Down
12 changes: 11 additions & 1 deletion test/test-trace-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Trace Agent', function() {
options.headers[constants.TRACE_CONTEXT_HEADER_NAME]);
assert.equal(parsed.traceId, 1);
assert.equal(parsed.spanId, spanId);
assert.equal(typeof parsed.spanId, 'number');
assert.equal(typeof parsed.spanId, 'string');
assert.equal(parsed.options, 1);
});
});
Expand All @@ -92,6 +92,16 @@ describe('Trace Agent', function() {
assert.equal(result.options, '1');
});

it('should return expected values:' +
'123456/123456123456123456123456123456123456;o=1', function() {
var result = agent.parseContextFromHeader(
'123456/123456123456123456123456123456123456;o=1');
assert(result);
assert.equal(result.traceId, '123456');
assert.equal(result.spanId, '123456123456123456123456123456123456');
assert.equal(result.options, '1');
});

it('should return expected values: 123456/667', function() {
var result = agent.parseContextFromHeader(
'123456/667');
Expand Down

0 comments on commit 9f1bdea

Please sign in to comment.