@@ -348,4 +348,92 @@ describe('AWS patcher', function() {
348348 } ) ;
349349
350350 } ) ;
351+
352+
353+ describe ( '#captureAWSRequest-PassThrough-Header' , function ( ) {
354+ var awsClient , awsRequest , MyEmitter , sandbox , segment , stubResolve , addNewSubsegmentStub , sub , addNewServiceSubsegmentStub , service ;
355+
356+ before ( function ( ) {
357+ MyEmitter = function ( ) {
358+ EventEmitter . call ( this ) ;
359+ } ;
360+
361+ awsClient = {
362+ customizeRequests : function customizeRequests ( captureAWSRequest ) {
363+ this . call = captureAWSRequest ;
364+ } ,
365+ throttledError : function throttledError ( ) { }
366+ } ;
367+ awsClient = awsPatcher . captureAWSClient ( awsClient ) ;
368+
369+ util . inherits ( MyEmitter , EventEmitter ) ;
370+ } ) ;
371+
372+ beforeEach ( function ( ) {
373+ sandbox = sinon . createSandbox ( ) ;
374+
375+ awsRequest = {
376+ httpRequest : {
377+ method : 'GET' ,
378+ url : '/' ,
379+ connection : {
380+ remoteAddress : 'localhost'
381+ } ,
382+ headers : { }
383+ } ,
384+ response : { }
385+ } ;
386+
387+ awsRequest . on = function ( event , fcn ) {
388+ if ( event === 'complete' ) {
389+ this . emitter . on ( event , fcn . bind ( this , this . response ) ) ;
390+ } else {
391+ this . emitter . on ( event , fcn . bind ( this , this ) ) ;
392+ }
393+ return this ;
394+ } ;
395+
396+ awsRequest . emitter = new MyEmitter ( ) ;
397+
398+ segment = new Segment ( 'testSegment' , traceId ) ;
399+ segment . noOp = true ; // enforce passthrough behaviour
400+ segment . additionalTraceData = { 'Foo' : 'bar' } ;
401+ sub = segment . addNewSubsegmentWithoutSampling ( 'subseg' ) ;
402+ service = sub . addNewSubsegmentWithoutSampling ( 'service' ) ;
403+
404+ stubResolve = sandbox . stub ( contextUtils , 'resolveSegment' ) . returns ( sub ) ;
405+ addNewSubsegmentStub = sandbox . stub ( segment , 'addNewSubsegmentWithoutSampling' ) . returns ( sub ) ;
406+ addNewServiceSubsegmentStub = sandbox . stub ( sub , 'addNewSubsegmentWithoutSampling' ) . returns ( service ) ;
407+ } ) ;
408+
409+ afterEach ( function ( ) {
410+ sandbox . restore ( ) ;
411+ } ) ;
412+
413+ it ( 'should log an info statement and exit if parent is not found on the context or on the call params' , function ( done ) {
414+ stubResolve . returns ( ) ;
415+ var logStub = sandbox . stub ( logger , 'info' ) ;
416+
417+ awsClient . call ( awsRequest ) ;
418+
419+ setTimeout ( function ( ) {
420+ logStub . should . have . been . calledOnce ;
421+ done ( ) ;
422+ } , 50 ) ;
423+ } ) ;
424+
425+ it ( 'should not inject the tracing headers if passthrough mode' , function ( done ) {
426+ sandbox . stub ( contextUtils , 'isAutomaticMode' ) . returns ( true ) ;
427+
428+ awsClient . call ( awsRequest ) ;
429+
430+ awsRequest . emitter . emit ( 'build' ) ;
431+
432+ setTimeout ( function ( ) {
433+ assert . equal ( awsRequest . httpRequest . headers [ 'X-Amzn-Trace-Id' ] , undefined ) ;
434+ done ( ) ;
435+ } , 50 ) ;
436+ } ) ;
437+
438+ } ) ;
351439} ) ;
0 commit comments