@@ -12,6 +12,7 @@ const helper = require('../../lib/agent_helper')
12
12
const Shim = require ( '../../../lib/shim/shim' )
13
13
const DatastoreShim = require ( '../../../lib/shim/datastore-shim' )
14
14
const ParsedStatement = require ( '../../../lib/db/parsed-statement' )
15
+ const { QuerySpec, OperationSpec } = require ( '../../../lib/shim/specs' )
15
16
16
17
test ( 'DatastoreShim' , function ( t ) {
17
18
t . autoend ( )
@@ -371,7 +372,7 @@ test('DatastoreShim', function (t) {
371
372
372
373
t . test ( 'should create a child segment when opaque is false' , ( t ) => {
373
374
shim . recordOperation ( wrappable , 'withNested' , ( ) => {
374
- return { name : 'test' , opaque : false }
375
+ return new OperationSpec ( { name : 'test' , opaque : false } )
375
376
} )
376
377
helper . runInTransaction ( agent , ( tx ) => {
377
378
const startingSegment = agent . tracer . getSegment ( )
@@ -388,7 +389,7 @@ test('DatastoreShim', function (t) {
388
389
389
390
t . test ( 'should not create a child segment when opaque is true' , ( t ) => {
390
391
shim . recordOperation ( wrappable , 'withNested' , ( ) => {
391
- return { name : 'test' , opaque : true }
392
+ return new OperationSpec ( { name : 'test' , opaque : true } )
392
393
} )
393
394
helper . runInTransaction ( agent , ( tx ) => {
394
395
const startingSegment = agent . tracer . getSegment ( )
@@ -455,7 +456,7 @@ test('DatastoreShim', function (t) {
455
456
beforeEach ( )
456
457
localhost = getMetricHostName ( agent , 'localhost' )
457
458
shim . recordOperation ( wrappable , 'getActiveSegment' , function ( s , fn , n , args ) {
458
- return { parameters : args [ 0 ] }
459
+ return new OperationSpec ( { parameters : args [ 0 ] } )
459
460
} )
460
461
} )
461
462
t . afterEach ( afterEach )
@@ -547,14 +548,14 @@ test('DatastoreShim', function (t) {
547
548
t . beforeEach ( function ( ) {
548
549
beforeEach ( )
549
550
shim . recordOperation ( wrappable , 'getActiveSegment' , function ( ) {
550
- return {
551
+ return new OperationSpec ( {
551
552
name : 'op' ,
552
553
parameters : {
553
554
host : 'some_host' ,
554
555
port_path_or_id : 1234 ,
555
556
database_name : 'foobar'
556
557
}
557
- }
558
+ } )
558
559
} )
559
560
560
561
return new Promise ( ( resolve ) => {
@@ -627,11 +628,15 @@ test('DatastoreShim', function (t) {
627
628
t . test (
628
629
'should create a datastore query segment but no metric when `record` is false' ,
629
630
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
+ )
635
640
636
641
helper . runInTransaction ( agent , function ( tx ) {
637
642
const startingSegment = agent . tracer . getSegment ( )
@@ -646,7 +651,11 @@ test('DatastoreShim', function (t) {
646
651
)
647
652
648
653
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
+ )
650
659
651
660
helper . runInTransaction ( agent , function ( tx ) {
652
661
const startingSegment = agent . tracer . getSegment ( )
@@ -660,7 +669,7 @@ test('DatastoreShim', function (t) {
660
669
} )
661
670
662
671
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 } ) )
664
673
665
674
helper . runInTransaction ( agent , function ( tx ) {
666
675
const startingSegment = agent . tracer . getSegment ( )
@@ -691,14 +700,17 @@ test('DatastoreShim', function (t) {
691
700
t . test ( 'should allow after handlers to be specified' , function ( t ) {
692
701
let executed = false
693
702
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
+ )
702
714
703
715
helper . runInTransaction ( agent , function ( ) {
704
716
t . notOk ( executed )
@@ -710,10 +722,13 @@ test('DatastoreShim', function (t) {
710
722
711
723
t . test ( 'should bind the callback if there is one' , function ( t ) {
712
724
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
+ )
717
732
718
733
helper . runInTransaction ( agent , function ( ) {
719
734
wrapped ( query , cb )
@@ -723,23 +738,30 @@ test('DatastoreShim', function (t) {
723
738
t . test ( 'should bind the row callback if there is one' , function ( t ) {
724
739
const cb = function ( ) { }
725
740
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
+ )
730
748
731
749
helper . runInTransaction ( agent , function ( ) {
732
750
wrapped ( query , cb )
733
751
} )
734
752
} )
735
753
736
754
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
+ )
743
765
744
766
helper . runInTransaction ( agent , ( tx ) => {
745
767
wrappable . bar ( )
@@ -797,7 +819,7 @@ test('DatastoreShim', function (t) {
797
819
} )
798
820
799
821
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 } ) )
801
823
802
824
helper . runInTransaction ( agent , function ( tx ) {
803
825
const startingSegment = agent . tracer . getSegment ( )
0 commit comments