@@ -37,7 +37,6 @@ export function wrap(handler: Handler) {
3737 attributes : flatten ( {
3838 event,
3939 context : {
40- callbackWaitsForEmptyEventLoop : lambda_context . callbackWaitsForEmptyEventLoop ,
4140 functionName : lambda_context . functionName ,
4241 functionVersion : lambda_context . functionVersion ,
4342 invokedFunctionArn : lambda_context . invokedFunctionArn ,
@@ -67,10 +66,7 @@ export function wrap(handler: Handler) {
6766 const ctx = trace . setSpan ( context . active ( ) , span ) ;
6867
6968 try {
70- // if (callback && handler.constructor.name !== "AsyncFunction" && handler.length === 3) {
71- // console.log("promisify handler");
72- // handler = promisify(handler);
73- // }
69+
7470 const result = await context . with ( ctx , async ( e , lc , cb ) => {
7571 const unkownResult = handler ( e , lc , ( err , res ) => {
7672 if ( err ) {
@@ -80,20 +76,21 @@ export function wrap(handler: Handler) {
8076 }
8177
8278 if ( res ) {
83- span . setAttributes ( ( { result : res } ) as Attributes ) ;
79+ span . setAttributes ( flatten ( { result : res } ) ) ;
8480 }
8581 if ( cb ) {
86- cb ( err , res )
82+ span . end ( ) ;
83+ cb ( err , res ) ;
8784 }
88- span . end ( ) ;
8985 } ) ;
90-
9186 if ( unkownResult ) {
9287 return await unkownResult
9388 }
9489 } , null , event , lambda_context , callback ) ;
90+ if ( result ) {
91+ span . setAttributes ( flatten ( { result } ) ) ;
92+ }
9593
96- span . setAttributes ( ( { result } ) as Attributes ) ;
9794 span . end ( ) ;
9895 return result ;
9996 } catch ( e ) {
0 commit comments