0.4.1 • Published 3 years ago

@isahara/tracker-decorator v0.4.1

Weekly downloads
9
License
ISC
Repository
github
Last release
3 years ago

Agenda

A very simple decorator for metrics gathering.

Metrics are vital for any high load project and there are many ways to implement metrics

You can always do it like that:

//-------- ANTI PATTERN --------//
 function myFunc() {
        const start = Date.now();
 
        ... your logic ...
        
        metrics.add('metric name', Date.now() - start); 
    }

Byt there is a cleaner way:

    @Tracker()
    function myFunc() {
         ... your logic ...
    }
}

Description

Installation

npm install @isahara/tracker-decorator

Example

import { Tracker, metrics } from '@isahara/tracker-decorator';

class MyClass {
    @Tracker()
    method() { // if the method retuns a Promise it will work any way
        ...
    }
}

const myClassObj = new MyClass();

myClassObj.method();

console.log(metrics);

// { 'MyClass>method':{ 
//                  counter: 75, 
//                  minTime: 53, 
//                  avgTime: 112, 
//                  maxTime: 232 
//               } 
//  }

Supported features

Set custom metrics callback

import { setTrackerCallback } from '@isahara/tracker-decorator';

setTrackerCallback((name, time, dataIn, dataOut)=>{
    console.log(name, time, dataIn, dataOut);
});

Specify custom metric name

By default metric name is 'ClassName + MethodName' When you need to override default you can add custom name.

@Tracker({name: 'my-metric'})
0.4.1

3 years ago

0.4.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago