Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const createPlugin = ({ options: pluginOptions } = {}) => {
const defaultedOptions = merge(
createMetricTypes.defaultedOptions,
createRequestRecorder.defaultedOptions,
defaultNormalizers,
pluginOptions
);
const metricTypes = createMetricTypes(defaultedOptions);
const observeGc = createGcObserver(metricTypes);
recordRequest = createRequestRecorder(metricTypes, defaultedOptions);
upMetric = metricTypes && metricTypes.up;
observeGc();
const plugin = {
name: pkg.name,
version: pkg.version,
register(server, registrationOptions, onRegistrationFinished = () => null) {
const areServerEventsSupported = getAreServerEventsSupported(
server.version
);
const doesResponseNeedInvocation = getDoesResponseNeedInvocation(
server.version
const createMiddleware = ({ app, options } = {}) => {
let defaultedOptions = merge(
createMetricTypes.defaultedOptions,
createRequestRecorder.defaultedOptions,
defaultNormalizers,
options
);
const metricTypes = createMetricTypes(defaultedOptions);
const observeGc = createGcObserver(metricTypes);
recordRequest = createRequestRecorder(metricTypes, defaultedOptions);
upMetric = metricTypes && metricTypes.up;
exposeOnLocals(app, { key: 'Prometheus', value: Prometheus });
exposeOnLocals(app, { key: 'recordRequest', value: recordRequest });
observeGc();
return (request, response, next) => {
const start = process.hrtime();
response.on('finish', () => {
const labels = Object.assign(
{},
{
const createPlugin = async (fastify, options) => {
const defaultedOptions = merge(
createMetricTypes.defaultedOptions,
createRequestRecorder.defaultedOptions,
defaultNormalizers,
options
);
const metricTypes = createMetricTypes(defaultedOptions);
const observeGc = createGcObserver(metricTypes);
recordRequest = createRequestRecorder(metricTypes, defaultedOptions);
upMetric = metricTypes && metricTypes.up;
observeGc();
fastify.decorate('Prometheus', Prometheus);
fastify.decorate('recordRequest', recordRequest);
fastify.decorateRequest('__promsterStartTime__', null);
fastify.addHook('onRequest', async (request, _) => {
request.__promsterStartTime__ = process.hrtime();
});
fastify.addHook('onResponse', async (request, reply) => {
const createMiddleware = ({ options } = {}) => {
const defaultedOptions = merge(
createMetricTypes.defaultedOptions,
createRequestRecorder.defaultedOptions,
defaultNormalizers,
options
);
const metricTypes = createMetricTypes(defaultedOptions);
const observeGc = createGcObserver(metricTypes);
recordRequest = createRequestRecorder(metricTypes, defaultedOptions);
upMetric = metricTypes && metricTypes.up;
observeGc();
function middleware(req$, res) {
return req$.pipe(
map(req => ({ req, start: process.hrtime() })),
tap(recordHandler(res, defaultedOptions)),
map(({ req }) => req)
);
}
return middleware;