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

@evo/gotcha-log

v1.5.1

Published

Logger for [gotcha](https://gitlab.uaprom/gotcha/gotcha). Will use global gotcha config (if gotcha client is already present in page than *window._GOTCHA_IS_HERE* will be *true* ). Or if there is no gotcha on page, it will not work until you will set the

Downloads

3,773

Readme

gotcha-log

Logger for gotcha. Will use global gotcha config (if gotcha client is already present in page than window._GOTCHA_IS_HERE will be true ). Or if there is no gotcha on page, it will not work until you will set the config with initGotchaLogger function.

Installation

npm install --save -E @evo/gotcha-log

API

gotcha.log(msg, extra);

gotcha.error(msg, extra);

Usage with global gotcha client

import * as gotcha from '@evo/gotcha-log';
// or import { log } from '@evo/gotcha-log';

gotcha.log('test msg')
// or log('test msg')
gotcha.error('error msg')

Usage as a standalone logger

import * as gotcha from '@evo/gotcha-log';

gotcha.initGotchaLogger(<GOTCHA_SITE>, <GOTCHA_HOST>, <TXID>)

gotcha.log('test');
gotcha.error('test');

See details about GOTCHA_SITE, GOTCHA_HOST here

Example of the resulting message:

{
    "message":"test msg",
    "filename":"default",
    "screenWidth":1855,
    "screenHeight":1056,
    "userLanguage":"US",
    "currentUrl":"http://localhost:8000/",
    "site":"evodoc-dev",
    "type":"log"
}

logging extra

const extra = { user: { name: 'test', age: 1 } };
gotcha.log('test msg', extra);

Will log:

{
    message: "test msg",
    ctx: { user_name_str: "test", user_age_int: 1 },
    //...
}

extra will be flattened as described here

txid

By default gotcha log will apply txid from global gotcha configuration. But you can also specify txid per log in the extra argument:

gotcha.log('test msg', { txid: '<some id>' });

@evo/gotcha-log/src/metrics

There was a need to transfer the numerical data of event metrics to the backend from the frontend to save them in the Prometheus. For this purpose a sub-module of metrics was created.

The design of the module has been inspired by the package prom-client

All metrics are uploaded to backend using window.sendBeacon(). If browser does not support this API, it will fallbacks to XMLHttpRequest()

NOTE:

Before add metrics to your project, you must add your project config to gotcha-server

Usage:

Common usage:

// at start of your application, initialize metrics module
import {initGotchaMetrics, metric} from '@evo/gotcha-log/src/metrics';

initGotchaMetrics({
    project: <project-id>, // do not forget, to add your project to gotcha-server config
    host: <gotcha-backend-host>
});

// create metric: metric(<name>, [<value>], [<labels>])
metric(
    'pageview', // metric name
     1, // value
    {page:'koshyk'} // labels
)

Also you can create metric instance manually:

import { Counter } from '@evo/gotcha-log/src/metrics';

const reduxActionsErrorsCounter=new Counter({
    name: 'redux-errors'
});
reduxActionsErrorsCounter.inc(123, {action: 'createOrder', version: '1.2.3'})

// or

const incCounter=reduxActionsErrorsCounter.getStandaloneInc( {action: 'createOrder', version: '1.2.3'})
incCounter(3) // which is equivalent to reduxActionsErrorsCounter.inc(3, {action: 'createOrder', version: '1.2.3'})

All metrics will upload to backend automatically each 5s. You can stop uploading by calling:

import { stopUploadByInterval } from '@evo/gotcha-log/src/metrics';
stopUploadByInterval()

And resume it by calling:

import { startUploadByInterval } from '@evo/gotcha-log/src/metrics';
startUploadByInterval()

NOTE:

startUploadByInterval and stopUploadByInterval also add beforeonload event listener, which will upload the last metrics to backend, before user leaves current page

Send metrics to backend immediately:

import { immediatelyUploadMetrics } from '@evo/gotcha-log/src/metrics';
immediatelyUploadMetrics()