packages/hemera/lib/extensions.js
function onActFinished(context, next) {
  const msg = context.response.payload

  // pass to act context
  if (msg) {
    context.request$ = msg.request || {}
    context.trace$ = msg.trace || {}
    context.meta$ = msg.meta || {}
  }

  // calculate request duration
  const now = Util.nowHrTime()
  const diff = now - context.trace$.timestamp
  context.trace$.duration = diff

  if (context._config.traceLog) {
    context.log = context.log.child({
      tag: context._config.tag,
      requestId: context.request$.id,
      parentSpanId: context.trace$.parentSpanId,
      traceId: context.trace$.traceId,
      spanId: context.trace$.spanId
    })
    context.log.info(
      {
        pattern: context.trace$.method,
        responseTime: context.trace$.duration
      },
      'Request completed'
    )
  } else {
    context.log.info(
      {
        requestId: context.request$.id,
        pattern: context.trace$.method,
        responseTime: context.trace$.duration
      },
      'Request completed'
    )
  }

  next()
}
function onActFinished(context, next) {
  const msg = context.response.payload

  // pass to act context
  if (msg) {
    context.request$ = msg.request || {}
    context.trace$ = msg.trace || {}
    context.meta$ = msg.meta || {}
  }

  // calculate request duration
  const now = Util.nowHrTime()
  const diff = now - context.trace$.timestamp
  context.trace$.duration = diff

  if (context._config.traceLog) {
    context.log = context.log.child({
      tag: context._config.tag,
      requestId: context.request$.id,
      parentSpanId: context.trace$.parentSpanId,
      traceId: context.trace$.traceId,
      spanId: context.trace$.spanId
    })
    context.log.info(
      {
        pattern: context.trace$.method,
        responseTime: context.trace$.duration
      },
      'Request completed'
    )
  } else {
    context.log.info(
      {
        requestId: context.request$.id,
        pattern: context.trace$.method,
        responseTime: context.trace$.duration
      },
      'Request completed'
    )
  }

  next()
}
function onActFinished ( context , next ) { const msg = context . response . payload // pass to act context if ( msg ) { context . request$ = msg . request || { } context . trace$ = msg . trace || { } context . meta$ = msg . meta || { } } // calculate request duration const now = Util . nowHrTime ( ) const diff = now - context . trace$ . timestamp context . trace$ . duration = diff if ( context . _config . traceLog ) { context . log = context . log . child ( { tag : context . _config . tag , requestId : context . request$ . id , parentSpanId : context . trace$ . parentSpanId , traceId : context . trace$ . traceId , spanId : context . trace$ . spanId } ) context . log . info ( { pattern : context . trace$ . method , responseTime : context . trace$ . duration } , 'Request completed' ) } else { context . log . info ( { requestId : context . request$ . id , pattern : context . trace$ . method , responseTime : context . trace$ . duration } , 'Request completed' ) } next ( ) }
- Restore context
- Measure request duration

@param {*} context
@param {*} next
- Restore context - Measure request duration