@@ -12,6 +12,7 @@ const helper = require('../../lib/agent_helper')
1212const Shim = require ( '../../../lib/shim/shim' )
1313const DatastoreShim = require ( '../../../lib/shim/datastore-shim' )
1414const ParsedStatement = require ( '../../../lib/db/parsed-statement' )
15+ const { QuerySpec, OperationSpec } = require ( '../../../lib/shim/specs' )
1516
1617test ( 'DatastoreShim' , function ( t ) {
1718 t . autoend ( )
@@ -371,7 +372,7 @@ test('DatastoreShim', function (t) {
371372
372373 t . test ( 'should create a child segment when opaque is false' , ( t ) => {
373374 shim . recordOperation ( wrappable , 'withNested' , ( ) => {
374- return { name : 'test' , opaque : false }
375+ return new OperationSpec ( { name : 'test' , opaque : false } )
375376 } )
376377 helper . runInTransaction ( agent , ( tx ) => {
377378 const startingSegment = agent . tracer . getSegment ( )
@@ -388,7 +389,7 @@ test('DatastoreShim', function (t) {
388389
389390 t . test ( 'should not create a child segment when opaque is true' , ( t ) => {
390391 shim . recordOperation ( wrappable , 'withNested' , ( ) => {
391- return { name : 'test' , opaque : true }
392+ return new OperationSpec ( { name : 'test' , opaque : true } )
392393 } )
393394 helper . runInTransaction ( agent , ( tx ) => {
394395 const startingSegment = agent . tracer . getSegment ( )
@@ -455,7 +456,7 @@ test('DatastoreShim', function (t) {
455456 beforeEach ( )
456457 localhost = getMetricHostName ( agent , 'localhost' )
457458 shim . recordOperation ( wrappable , 'getActiveSegment' , function ( s , fn , n , args ) {
458- return { parameters : args [ 0 ] }
459+ return new OperationSpec ( { parameters : args [ 0 ] } )
459460 } )
460461 } )
461462 t . afterEach ( afterEach )
@@ -547,14 +548,14 @@ test('DatastoreShim', function (t) {
547548 t . beforeEach ( function ( ) {
548549 beforeEach ( )
549550 shim . recordOperation ( wrappable , 'getActiveSegment' , function ( ) {
550- return {
551+ return new OperationSpec ( {
551552 name : 'op' ,
552553 parameters : {
553554 host : 'some_host' ,
554555 port_path_or_id : 1234 ,
555556 database_name : 'foobar'
556557 }
557- }
558+ } )
558559 } )
559560
560561 return new Promise ( ( resolve ) => {
@@ -627,11 +628,15 @@ test('DatastoreShim', function (t) {
627628 t . test (
628629 'should create a datastore query segment but no metric when `record` is false' ,
629630 function ( t ) {
630- shim . recordQuery ( wrappable , 'getActiveSegment' , {
631- query : shim . FIRST ,
632- record : false ,
633- name : 'getActiveSegment'
634- } )
631+ shim . recordQuery (
632+ wrappable ,
633+ 'getActiveSegment' ,
634+ new QuerySpec ( {
635+ query : shim . FIRST ,
636+ record : false ,
637+ name : 'getActiveSegment'
638+ } )
639+ )
635640
636641 helper . runInTransaction ( agent , function ( tx ) {
637642 const startingSegment = agent . tracer . getSegment ( )
@@ -646,7 +651,11 @@ test('DatastoreShim', function (t) {
646651 )
647652
648653 t . test ( 'should create a datastore query metric when `record` is true' , function ( t ) {
649- shim . recordQuery ( wrappable , 'getActiveSegment' , { query : shim . FIRST , record : true } )
654+ shim . recordQuery (
655+ wrappable ,
656+ 'getActiveSegment' ,
657+ new QuerySpec ( { query : shim . FIRST , record : true } )
658+ )
650659
651660 helper . runInTransaction ( agent , function ( tx ) {
652661 const startingSegment = agent . tracer . getSegment ( )
@@ -660,7 +669,7 @@ test('DatastoreShim', function (t) {
660669 } )
661670
662671 t . test ( 'should create a datastore query metric when `record` is defaulted' , function ( t ) {
663- shim . recordQuery ( wrappable , 'getActiveSegment' , { query : shim . FIRST } )
672+ shim . recordQuery ( wrappable , 'getActiveSegment' , new QuerySpec ( { query : shim . FIRST } ) )
664673
665674 helper . runInTransaction ( agent , function ( tx ) {
666675 const startingSegment = agent . tracer . getSegment ( )
@@ -691,14 +700,17 @@ test('DatastoreShim', function (t) {
691700 t . test ( 'should allow after handlers to be specified' , function ( t ) {
692701 let executed = false
693702 const toWrap = function ( ) { }
694- const wrapped = shim . recordQuery ( toWrap , {
695- query : function ( ) {
696- return 'test'
697- } ,
698- after : function ( ) {
699- executed = true
700- }
701- } )
703+ const wrapped = shim . recordQuery (
704+ toWrap ,
705+ new QuerySpec ( {
706+ query : function ( ) {
707+ return 'test'
708+ } ,
709+ after : function ( ) {
710+ executed = true
711+ }
712+ } )
713+ )
702714
703715 helper . runInTransaction ( agent , function ( ) {
704716 t . notOk ( executed )
@@ -710,10 +722,13 @@ test('DatastoreShim', function (t) {
710722
711723 t . test ( 'should bind the callback if there is one' , function ( t ) {
712724 const cb = function ( ) { }
713- const wrapped = shim . recordQuery ( helper . checkWrappedCb . bind ( t , shim , cb ) , {
714- query : shim . FIRST ,
715- callback : shim . LAST
716- } )
725+ const wrapped = shim . recordQuery (
726+ helper . checkWrappedCb . bind ( t , shim , cb ) ,
727+ new QuerySpec ( {
728+ query : shim . FIRST ,
729+ callback : shim . LAST
730+ } )
731+ )
717732
718733 helper . runInTransaction ( agent , function ( ) {
719734 wrapped ( query , cb )
@@ -723,23 +738,30 @@ test('DatastoreShim', function (t) {
723738 t . test ( 'should bind the row callback if there is one' , function ( t ) {
724739 const cb = function ( ) { }
725740
726- const wrapped = shim . recordQuery ( helper . checkWrappedCb . bind ( t , shim , cb ) , {
727- query : shim . FIRST ,
728- rowCallback : shim . LAST
729- } )
741+ const wrapped = shim . recordQuery (
742+ helper . checkWrappedCb . bind ( t , shim , cb ) ,
743+ new QuerySpec ( {
744+ query : shim . FIRST ,
745+ rowCallback : shim . LAST
746+ } )
747+ )
730748
731749 helper . runInTransaction ( agent , function ( ) {
732750 wrapped ( query , cb )
733751 } )
734752 } )
735753
736754 t . test ( 'should execute inContext function when specified in spec' , function ( t ) {
737- shim . recordQuery ( wrappable , 'bar' , {
738- query : 'select foo from bar;' ,
739- inContext ( segment ) {
740- segment . addAttribute ( 'test-attr' , 'unit-test' )
741- }
742- } )
755+ shim . recordQuery (
756+ wrappable ,
757+ 'bar' ,
758+ new QuerySpec ( {
759+ query : 'select foo from bar;' ,
760+ inContext ( segment ) {
761+ segment . addAttribute ( 'test-attr' , 'unit-test' )
762+ }
763+ } )
764+ )
743765
744766 helper . runInTransaction ( agent , ( tx ) => {
745767 wrappable . bar ( )
@@ -797,7 +819,7 @@ test('DatastoreShim', function (t) {
797819 } )
798820
799821 t . test ( 'should create a datastore batch query metric' , function ( t ) {
800- shim . recordBatchQuery ( wrappable , 'getActiveSegment' , { query : shim . FIRST } )
822+ shim . recordBatchQuery ( wrappable , 'getActiveSegment' , new QuerySpec ( { query : shim . FIRST } ) )
801823
802824 helper . runInTransaction ( agent , function ( tx ) {
803825 const startingSegment = agent . tracer . getSegment ( )
0 commit comments