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

@janiscommerce/metrics

v2.0.0

Published

A package for creating metrics in Firehose

Downloads

197

Readme

Metrics

Build Status Coverage Status npm version

A package for creating metrics in Firehose

Installation

npm install @janiscommerce/metrics

Configuration

ENV variables

JANIS_SERVICE_NAME (required): The Role Session Name to assume role in order to put records in Firehose. METRIC_ROLE_ARN (required): The ARN to assume role in order to put records in Firehose.

API

add(clientCode, metricName, metricData)

Parameters: clientCode [String], metricName [String], metricData [Object] or [Object array] Puts the recieved metric or metrics into the janis-trace-firehose

Metric structure

The metricData [Object] parameter have the following structure:

  • metricData [Object|Array]: This property is a JSON that includes all the technical data about your metric.

Metric example

{
	deliveryDate: '2022-06-03T10:00:00.000Z',
	orderId: '629e578fd32fd43cd1e41944',
	salesChannelId: '629e5797f63b83029b4df49f',
	status: 'pending'
}

on(event, callback)

Parameters: event [String], callback [Function] Calls a callback when the specified event is emitted.

Errors

The errors are informed with a MetricError. This object has a code that can be useful for a correct error handling. The codes are the following:

| Code | Description | |------|--------------------------------| | 1 | Invalid metric | | 2 | Firehose Error | | 3 | Unknown stage name |

  • In case of error while sending your metrics to Firehose, this package will emit an event called create-error, you can handle it using the on() method.

Usage

const Metric = require('@janiscommerce/metrics');

// Single metric send
await Metric.add('some-client', 'order-fulfillment-status', {
	warehouseName: "Example Warehouse name",
	salesChannelId: "d555345345345as67a342a",
	salesChannelName: "Example Sales Channel name"
});

// Multiple metrics send
await Metric.add('some-client', 'order-fulfillment-status', [
	{
		warehouseName: "Example Warehouse name",
		salesChannelId: "629d269fbd8f5f5da8185ba3",
		salesChannelName: "Example Sales Channel name"
	},
	{
		warehouseName: "Other Example Warehouse name",
		salesChannelId: "629d26a36c3c06aefe297df2",
		salesChannelName: "Other Example Sales Channel name"
	}
]);

// Metric creation error handling
Metric.on('create-error', (metric, err) => {
	console.error(`An error occurred while creating the metric ${err.message}`);
});

### Serverless configuration

Returns an array with the hooks needed for Metric's serverless configuration according to [Serverless Helper](https://www.npmjs.com/package/sls-helper-plugin-janis). In `path/to/root/serverless.js` add:

```js
'use strict';

const { helper } = require('sls-helper'); // eslint-disable-line
const functions = require('./serverless/functions.json');
const Metric = require('@janiscommerce/metrics');

module.exports = helper({
	hooks: [
		// other hooks
        ...functions,
        ...Metric.serverlessConfiguration
	]
});