npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@financial-times/n-auto-metrics

v4.0.0-beta.2

Published

an [enhancer](https://github.com/Financial-Times/n-express-enhancer) to auto record metrics of function calls in operation/action model with a single line of code

Downloads

128

Readme

n-auto-metrics

an enhancer to auto record metrics of function calls in operation/action model with a single line of code

npm version npm download node version

CircleCI Coverage Status Known Vulnerabilities Scrutinizer Code Quality Dependencies devDependencies

Quickstart

initialise metrics before using enhanced middleware

/* app.js */
import { metrics } from 'n-express'; // or any other source has the `next-metrics` instance
import { initAutoMetrics } from '@financial-times/n-auto-metrics';

initAutoMetrics(metrics); // do this before app.use() any enhanced middleware/controller

enhance action function to auto metrics, use tagService to add service before metricsAction if you want to set metrics of one service namespace

import { metricsAction, tagService, compose } from '@financial-times/n-auto-metrics';

// auto metrics function of its start, success/failure state
const result = metricsAction(someFunction)(args: Object, meta?: Object);

// auto metrics multiple functions wrapped in an object
const APIService = compose(
  tagService('some-service'),
  metricsAction
)({ 
  methodA, 
  methodB, 
  methodC 
});

more details on action function

// auto log success/failure express middleware/controller as an operation function 
// function name would be logged as `operation`, and available in meta
const operationFunction = (meta, req, res) => { /* try-catch-throw */ };
export default toMiddleware(metricsOperation(operationFunction));

// auto log multiple operation functions wrapped in an object as controller
const someController = toMiddlewares(metricsOperation({ operationFunctionA, operationFuncitonB }));

check use res.render

more details on operation function

more details on chain with other enhancers

Install

npm install @financial-times/n-auto-metrics

Gotcha

reserved fields

  • operation default to operationFunction.name
  • service default to undefined, can be specified in paramsOrArgs or meta(autoLogActions('service-name'))
  • action default to callFunction.name
  • category NError category would be recorded in metrics
  • type is used by convention to record custom error type names for monitoring and debugging
  • status in error object would be recorded for service action call failure
  • stack used in Error or NError to store the stack trace
  • result default to success/failure

metrics format

operation.${operation}.segment.${segment}.state.start operation.${operation}.action.${action}.state.start operation.${operation}.action.${action}.state.success operation.${operation}.action.${action}.state.failure.category.${e.category}.type.${e.type} operation.${operation}.action.${action}.state.failure.category.${e.category}.status.${e.status} operation.${operation}.segment.${segment}.state.success operation.${operation}.segment.${segment}.state.failure.category.${e.category}.type.${e.type} service.${service}.action.${action}.state.start service.${service}.action.${action}.state.success service.${service}.action.${action}.state.failure.category.${e.category}.type.${e.type} service.${service}.action.${action}.state.failure.category.${e.category}.status.${e.status}

Licence

MIT