src/middlewares/metrics.js
function metricFinish(ctx, error) {
	if (ctx.startHrTime) {
		let diff = process.hrtime(ctx.startHrTime);
		ctx.duration = (diff[0] * 1e3) + (diff[1] / 1e6); // milliseconds
	}
	ctx.stopTime = ctx.startTime + ctx.duration;

	if (ctx.metrics) {
		const payload = generateMetricPayload(ctx);
		payload.endTime = ctx.stopTime;
		payload.duration = ctx.duration;
		payload.fromCache = ctx.cachedResult;

		if (error) {
			payload.error = {
				name: error.name,
				code: error.code,
				type: error.type,
				message: error.message
			};
		}

		ctx.broker.emit("metrics.trace.span.finish", payload);
	}
}
function metricFinish(ctx, error) {
	if (ctx.startHrTime) {
		let diff = process.hrtime(ctx.startHrTime);
		ctx.duration = (diff[0] * 1e3) + (diff[1] / 1e6); // milliseconds
	}
	ctx.stopTime = ctx.startTime + ctx.duration;

	if (ctx.metrics) {
		const payload = generateMetricPayload(ctx);
		payload.endTime = ctx.stopTime;
		payload.duration = ctx.duration;
		payload.fromCache = ctx.cachedResult;

		if (error) {
			payload.error = {
				name: error.name,
				code: error.code,
				type: error.type,
				message: error.message
			};
		}

		ctx.broker.emit("metrics.trace.span.finish", payload);
	}
}
function metricFinish ( ctx , error ) { if ( ctx . startHrTime ) { let diff = process . hrtime ( ctx . startHrTime ) ; ctx . duration = ( diff [ 0 ] * 1e3 ) + ( diff [ 1 ] / 1e6 ) ; // milliseconds } ctx . stopTime = ctx . startTime + ctx . duration ; if ( ctx . metrics ) { const payload = generateMetricPayload ( ctx ) ; payload . endTime = ctx . stopTime ; payload . duration = ctx . duration ; payload . fromCache = ctx . cachedResult ; if ( error ) { payload . error = { name : error . name , code : error . code , type : error . type , message : error . message } ; } ctx . broker . emit ( "metrics.trace.span.finish" , payload ) ; } }
Stop metrics & send finish metric event.

@param {Context} ctx
@param {Error} error

@private
Stop metrics & send finish metric event .