diff --git a/packages/mysql/lib/mysql_p.js b/packages/mysql/lib/mysql_p.js index a9707649..4c87d845 100644 --- a/packages/mysql/lib/mysql_p.js +++ b/packages/mysql/lib/mysql_p.js @@ -92,7 +92,7 @@ function resolveArguments(argsObj) { args.callback = typeof argsObj[1] === 'function' ? argsObj[1] : (typeof argsObj[2] === 'function' ? argsObj[2] : undefined); } - args.segment = (argsObj[argsObj.length-1].constructor && (argsObj[argsObj.length-1].constructor.name === 'Segment' || + args.segment = (argsObj[argsObj.length-1] != null && argsObj[argsObj.length-1].constructor && (argsObj[argsObj.length-1].constructor.name === 'Segment' || argsObj[argsObj.length-1].constructor.name === 'Subsegment')) ? argsObj[argsObj.length-1] : null; } diff --git a/packages/mysql/test/unit/mysql_p.test.js b/packages/mysql/test/unit/mysql_p.test.js index 1588f243..459fab6b 100644 --- a/packages/mysql/test/unit/mysql_p.test.js +++ b/packages/mysql/test/unit/mysql_p.test.js @@ -143,6 +143,12 @@ describe('captureMySQL', function() { stubClose.should.have.been.calledWithExactly(err); }); + + it('should start a new automatic context when last query paramater is null', function() { + query.call(connectionObj, 'sql here', function() {}, null); + + assert.equal(stubBaseQuery.args[0][2].name, 'autoContext'); + }); }); }); diff --git a/packages/postgres/lib/postgres_p.js b/packages/postgres/lib/postgres_p.js index 1783ca08..1ef7896c 100644 --- a/packages/postgres/lib/postgres_p.js +++ b/packages/postgres/lib/postgres_p.js @@ -44,7 +44,7 @@ function resolveArguments(argsObj) { args.callback = typeof argsObj[1] === 'function' ? argsObj[1] : (typeof argsObj[2] === 'function' ? argsObj[2] : undefined); } - args.segment = (argsObj[argsObj.length-1].constructor && (argsObj[argsObj.length-1].constructor.name === 'Segment' || + args.segment = (argsObj[argsObj.length-1] != null && argsObj[argsObj.length-1].constructor && (argsObj[argsObj.length-1].constructor.name === 'Segment' || argsObj[argsObj.length-1].constructor.name === 'Subsegment')) ? argsObj[argsObj.length-1] : null; } diff --git a/packages/postgres/test/unit/postgres_p.test.js b/packages/postgres/test/unit/postgres_p.test.js index 94364eab..90ea381b 100644 --- a/packages/postgres/test/unit/postgres_p.test.js +++ b/packages/postgres/test/unit/postgres_p.test.js @@ -135,6 +135,12 @@ describe('capturePostgres', function() { stubClose.should.have.been.calledWithExactly(err); }); + + it('should start a new automatic context when last query paramater is null', function() { + query.call(postgres, 'sql here', [], function() {}, null); + + assert.equal(queryObj.callback.name, 'autoContext'); + }); });