@@ -46,6 +46,7 @@ describe('log', () => {
4646 sentryScope = { setContext : sinon . stub ( ) } ;
4747 cb ( sentryScope ) ;
4848 } ) ,
49+ getActiveSpan : sinon . stub ( ) . returns ( undefined ) ,
4950 } ;
5051 sinon . stub ( sentryModule , 'reportSentryMessage' ) . returns ( { } ) ;
5152
@@ -795,7 +796,7 @@ describe('log', () => {
795796 assert . calledOnceWithExactly ( logger . info , 'op' , { uid : 'bloop' } ) ;
796797 } ) ;
797798
798- it ( 'should set trace id' , ( ) => {
799+ it ( 'should set otel trace id' , ( ) => {
799800 log = proxyquire (
800801 '../../lib/log' ,
801802 mocks
@@ -813,23 +814,83 @@ describe('log', () => {
813814 } ) ;
814815 assert . calledOnceWithExactly ( logger . info , 'op' , {
815816 uid : 'bloop' ,
816- traceId : 'fake trace id' ,
817+ otelTraceId : 'fake trace id' ,
817818 } ) ;
818819
819820 log . debug ( 'op' , {
820821 uid : 'bloop' ,
821822 } ) ;
822823 assert . calledOnceWithExactly ( logger . debug , 'op' , {
823824 uid : 'bloop' ,
824- traceId : 'fake trace id' ,
825+ otelTraceId : 'fake trace id' ,
825826 } ) ;
826827
827828 log . error ( 'op' , {
828829 uid : 'bloop' ,
829830 } ) ;
830831 assert . calledOnceWithExactly ( logger . error , 'op' , {
831832 uid : 'bloop' ,
832- traceId : 'fake trace id' ,
833+ otelTraceId : 'fake trace id' ,
834+ } ) ;
835+ } ) ;
836+
837+ it ( 'should set sentry trace id' , ( ) => {
838+ mockSentry . getActiveSpan = sinon . stub ( ) . returns ( {
839+ spanContext : sinon . stub ( ) . returns ( { traceId : 'fake-sentry-trace-id' } ) ,
840+ } ) ;
841+ log = proxyquire (
842+ '../../lib/log' ,
843+ mocks
844+ ) ( {
845+ level : 'debug' ,
846+ name : 'test' ,
847+ stdout : { on : sinon . spy ( ) } ,
848+ } ) ;
849+
850+ log . info ( 'op' , { uid : 'bloop' } ) ;
851+ assert . calledOnceWithExactly ( logger . info , 'op' , {
852+ uid : 'bloop' ,
853+ sentryTraceId : 'fake-sentry-trace-id' ,
854+ } ) ;
855+ } ) ;
856+
857+ it ( 'should store otel error in result on failure' , ( ) => {
858+ const otelErr = new Error ( 'otel error' ) ;
859+ log = proxyquire (
860+ '../../lib/log' ,
861+ mocks
862+ ) ( {
863+ level : 'debug' ,
864+ name : 'test' ,
865+ stdout : { on : sinon . spy ( ) } ,
866+ nodeTracer : {
867+ getTraceId : sinon . stub ( ) . throws ( otelErr ) ,
868+ } ,
869+ } ) ;
870+
871+ log . info ( 'op' , { uid : 'bloop' } ) ;
872+ assert . calledOnceWithExactly ( logger . info , 'op' , {
873+ uid : 'bloop' ,
874+ otelTraceIdErr : otelErr ,
875+ } ) ;
876+ } ) ;
877+
878+ it ( 'should store sentry error in result on failure' , ( ) => {
879+ const sentryErr = new Error ( 'sentry error' ) ;
880+ mockSentry . getActiveSpan = sinon . stub ( ) . throws ( sentryErr ) ;
881+ log = proxyquire (
882+ '../../lib/log' ,
883+ mocks
884+ ) ( {
885+ level : 'debug' ,
886+ name : 'test' ,
887+ stdout : { on : sinon . spy ( ) } ,
888+ } ) ;
889+
890+ log . info ( 'op' , { uid : 'bloop' } ) ;
891+ assert . calledOnceWithExactly ( logger . info , 'op' , {
892+ uid : 'bloop' ,
893+ sentryTraceIdError : sentryErr ,
833894 } ) ;
834895 } ) ;
835896 } ) ;
0 commit comments