A Egg Plugin for Server Timing
$ npm install egg-plugin-server-timing
# or
$ yarn add egg-plugin-server-timing
// config/plugin.ts
export default {
serverTiming: {
enable: true,
package: "egg-plugin-server-timing",
},
};
// config/config.default.ts
config.serverTiming = {
name: "Total", // The name of the total metric to be set.
description: "Total Response Time", // The description of the total metric to be set.
total: true, // Whether to set the total metric automatically.
enabled: true, // Whether to enable the plugin.
autoEnd: true, // Whether to set the metric automatically when the request ends.
precision: +Infinity, // Number of digits after the decimal point of the statistical time
};
ctx.serverTimer.startTime("all");
await new Promise((resolve) => setTimeout(resolve, 100));
ctx.serverTimer.endTime("all");