# tstats

> Tstats Library

Latest version **1.0.1** (published 2020-10-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install tstats
pnpm add tstats
yarn add tstats
bun add tstats
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-10-07 |
| First published | 2020-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | emree-kul |

## Links

- npm: https://www.npmjs.com/package/tstats
- Repository: https://github.com/Trendyol/tstats
- Homepage: https://github.com/Trendyol/tstats#readme
- Issues: https://github.com/Trendyol/tstats/issues
- npm.io page: https://npm.io/package/tstats

## Dependencies (8)

- [rxjs](https://npm.io/package/rxjs.md) ^6.6.0
- [zipkin](https://npm.io/package/zipkin.md) ^0.22.0
- [prom-client](https://npm.io/package/prom-client.md) ^12.0.0
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^7.3.2
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^7.3.2
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [zipkin-transport-http](https://npm.io/package/zipkin-transport-http.md) ^0.22.0
- [zipkin-instrumentation-express](https://npm.io/package/zipkin-instrumentation-express.md) ^0.22.0

## Recent versions

- 1.0.1 (latest) — 2020-10-07
- 1.0.0 — 2020-10-07

## README

# Tstats
[![CircleCI](https://circleci.com/gh/Trendyol/tstats.svg?style=svg)](https://circleci.com/gh/Trendyol/tstats)
[![codecov](https://codecov.io/gh/Trendyol/tstats/branch/master/graph/badge.svg)](https://codecov.io/gh/Trendyol/tstats) 
![npm](https://img.shields.io/npm/v/tstats)
<br/>

> A library for collecting app metrics from nest.js application.
<br/>

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.

<br/>

## Getting started
Just install the library `tstats`:

```sh
$ npm i tstats -S
```

```sh
$ yarn add tstats
```
<br/>

## Usage

APPLY MODULE
```typescript
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 {}
```
<br/>

ZIPKIN SEGMENTATION
<br/>
This decorator not compulsory to use but most of the time You will need it.
<br/>
```typescript

class SomeClassToTrace {
    
    @ZipkinSegment()
    public async someAsyncMethodToTrace() {
        return await someAsyncJob();
    }
    
    @ZipkinSegment('Optional name')
    public someMethodToTrace() {
        return someJob();
    }

}
```
<br/>

## 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                                  |

---
_Source: https://npm.io/package/tstats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
