README
Tstats
A library for collecting app metrics from nest.js application.
TSTATS contains decorator(s) and interceptor(s) for tracing and collecting performance metrics from nest.js application.
This library was created as a nest.js module and heavily depended on Prometheus and Zipkin.
Features
- Injects global interceptor and collect performance metrics on requests and publishes for Prometheus.
- Injects global middleware and Traces every request with Zipkin (zipkin-express).
- Provides decorator for Zipkin segmentation.
Getting started
Just install the library tstats
:
$ npm i tstats -S
$ yarn add tstats
Usage
APPLY MODULE
import { TstatsModule } from 'tstats/dist/tstats-module';
@Module({
imports: [
TstatsModule.register({
namespace: 'NAMESPACE_FOR_PROMETHEUS',
appName: 'APPLICATION_NAME_FOR_PROMETHEUS_AND_IN_GENERAL',
zipkin: {
serviceName: 'ZIPKIN_SERVICE_NAME',
url: 'http://[ZIPKIN_URL]/api/v2/spans'
},
enabled: true
})
],
providers: []
})
export class ApplicationModule {}
ZIPKIN SEGMENTATION
This decorator not compulsory to use but most of the time You will need it.
class SomeClassToTrace {
@ZipkinSegment()
public async someAsyncMethodToTrace() {
return await someAsyncJob();
}
@ZipkinSegment('Optional name')
public someMethodToTrace() {
return someJob();
}
}
Configuration
Module Options
Param | Type | Optional | Description |
---|---|---|---|
namespace | string | NO | Prometheus summary namespace |
appName | string | NO | Prometheus service name |
zipkin | ZipkinOptions | NO | Zipkin Options |
enabled | boolean | YES | Is module active (ex: enabled = env == 'prod') |
ZipkinOptions
Param | Type | Optional | Description |
---|---|---|---|
serviceName | string | NO | Zipkin service name app identifier |
url | string | NO | Zipkin url |