summaryrefslogtreecommitdiff
path: root/lib/trace/metric/index.ts
blob: 35a06934b13c845da63240b27ddde826b2a33c39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { isTagged, Tagged, type Mapper } from '@emprespresso/pengueno';

export enum Unit {
    COUNT = 'COUNT',
    MILLISECONDS = 'MILLISECONDS',
}

export const MetricValueTag = 'MetricValue' as const;
export type MetricValueTag = typeof MetricValueTag;
export const isMetricValue = (t: unknown): t is MetricValue => isTagged(t, MetricValueTag);
export interface MetricValue extends Tagged<MetricValueTag> {
    readonly name: string;
    readonly unit: Unit;
    readonly value: number;
    readonly emissionTimestamp: number;
}

export interface IEmittableMetric {
    readonly name: string;
    readonly unit: Unit;
    readonly withValue: Mapper<number, MetricValue>;
}

export const IMetricTag = 'IMetric' as const;
export type IMetricTag = typeof IMetricTag;
export const isIMetric = (t: unknown): t is IMetric => isTagged(t, IMetricTag);
export interface IMetric extends Tagged<IMetricTag> {
    readonly name: string;
    readonly count: IEmittableMetric;
    readonly time: IEmittableMetric;
    readonly parent: undefined | IMetric;
}

export interface IResultMetric extends IMetric {
    readonly failure: IMetric;
    readonly success: IMetric;
    readonly warn: IMetric;
}

export * from './emittable';
export * from './metric';
export * from './trace';