Coder Social home page Coder Social logo

adambraimbridge / n-express-monitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from financial-times/n-express-monitor

0.0 1.0 0.0 118 KB

๐ŸŽฏ configurable express decorator to automate log, metrics for more consistent monitor and debugging across micro-services

License: MIT License

Makefile 8.45% JavaScript 91.55%

n-express-monitor's Introduction

n-express-monitor

a configurable express decorator to automate log, metrics to ensure monitor consistency and make debugging more predictable across micro-services

npm version CircleCI Coverage Status gitter chat FOSSA Status

node version Known Vulnerabilities Scrutinizer Code Quality Dependencies devDependencies



Install

npm install @financial-times/n-express-monitor --save

Demo

next-monitor-express

Usage

setupMonitor

import express, { metrics } from '@financial-times/n-express';
import { setupMonitor } from '@financial-times/n-express-monitor';

const app = express();

setupMonitor({ app, metrics }); // if metrics is not set, it would only do the log

// ...middlewares and routes

it uses n-logger by default, use custom logger instance, check example of setupMonitor with n-mask-logger

monitor

import { monitor } from '@financial-times/n-express-monitor';

const getUserProfileBySession = async (req, res) => {
	const { meta } = req;
	const { sessionId } = req.params;
	if (sessionId === 'uncovered') {
		throw Error('an uncovered function has thrown an error');
	}
	const { userId } = await SessionApi.verifySession({ sessionId }, meta);
	const userProfile = await UserProfileSvc.getUserProfileById({ userId }, meta);
	res.json(userProfile);
};

export default monitor(getUserProfileBySession);

monitorService

import { monitorService } from '@financial-times/n-express-monitor';

/*
	SHORTHAND DEFAULT: in case we don't need to add extra error handling,
	the default method from n-api-factory can be used to setup a client method
 */
const getUserProfileById = async ({ userId }, meta) =>
	userProfileSvc.get({
		endpoint: `/user-profile/${userId}`,
		meta,
	});

export default monitorService('user-profile-svc', {
	getUserProfileById,
});

monitorModule

import { monitorModule } from '@financial-times/n-express-monitor';

export default monitorModule({
	validateUserId: () => {},
	mapUserProfileToView: () => {},
});

Configuration

Apart from the configuration you need for the logger, metrics instance you used, you can config n-express-monitor with the following ENV_VAR for the log automation behaviour:

ENV_VAR values function
AUTO_LOG_LEVEL verbose, standard(default), concise, error control how operation and action would be logged, check example
LOGGER_MUTE_FIELDS key names of values in the meta or error use to reduce amount of log information

Convention

operation function

same as express middleware/controller but without next: (req, res) => {}

action function

(param, meta) => {}

How It Works

If you are interested in how it works under the hood, it is using n-auto-logger, n-auto-metrics, and you can build your own customised decorator and add it into the chain with n-express-enhancer.

Licence

MIT

n-express-monitor's People

Contributors

zhenyulin avatar sjparkinson avatar edds avatar jenniferemshepherd avatar ker-an avatar renovate-bot avatar fossabot avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.