1 | import type { Client } from './client';
|
2 | import type { DurationUnit, MeasurementUnit } from './measurement';
|
3 | import type { Primitive } from './misc';
|
4 | export interface MetricData {
|
5 | unit?: MeasurementUnit;
|
6 | tags?: Record<string, Primitive>;
|
7 | timestamp?: number;
|
8 | client?: Client;
|
9 | }
|
10 | /**
|
11 | * An abstract definition of the minimum required API
|
12 | * for a metric instance.
|
13 | */
|
14 | export interface MetricInstance {
|
15 | /**
|
16 | * Returns the weight of the metric.
|
17 | */
|
18 | weight: number;
|
19 | /**
|
20 | * Adds a value to a metric.
|
21 | */
|
22 | add(value: number | string): void;
|
23 | /**
|
24 | * Serializes the metric into a statsd format string.
|
25 | */
|
26 | toString(): string;
|
27 | }
|
28 | export interface MetricBucketItem {
|
29 | metric: MetricInstance;
|
30 | timestamp: number;
|
31 | metricType: 'c' | 'g' | 's' | 'd';
|
32 | name: string;
|
33 | unit: MeasurementUnit;
|
34 | tags: Record<string, string>;
|
35 | }
|
36 | /**
|
37 | * A metrics aggregator that aggregates metrics in memory and flushes them periodically.
|
38 | */
|
39 | export interface MetricsAggregator {
|
40 | /**
|
41 | * Add a metric to the aggregator.
|
42 | */
|
43 | add(metricType: 'c' | 'g' | 's' | 'd', name: string, value: number | string, unit?: MeasurementUnit, tags?: Record<string, Primitive>, timestamp?: number): void;
|
44 | /**
|
45 | * Flushes the current metrics to the transport via the transport.
|
46 | */
|
47 | flush(): void;
|
48 | /**
|
49 | * Shuts down metrics aggregator and clears all metrics.
|
50 | */
|
51 | close(): void;
|
52 | /**
|
53 | * Returns a string representation of the aggregator.
|
54 | */
|
55 | toString(): string;
|
56 | }
|
57 | export interface Metrics {
|
58 | /**
|
59 | * Adds a value to a counter metric
|
60 | *
|
61 | * @experimental This API is experimental and might have breaking changes in the future.
|
62 | */
|
63 | increment(name: string, value?: number, data?: MetricData): void;
|
64 | /**
|
65 | * Adds a value to a distribution metric
|
66 | *
|
67 | * @experimental This API is experimental and might have breaking changes in the future.
|
68 | */
|
69 | distribution(name: string, value: number, data?: MetricData): void;
|
70 | /**
|
71 | * Adds a value to a set metric. Value must be a string or integer.
|
72 | *
|
73 | * @experimental This API is experimental and might have breaking changes in the future.
|
74 | */
|
75 | set(name: string, value: number | string, data?: MetricData): void;
|
76 | /**
|
77 | * Adds a value to a gauge metric
|
78 | *
|
79 | * @experimental This API is experimental and might have breaking changes in the future.
|
80 | */
|
81 | gauge(name: string, value: number, data?: MetricData): void;
|
82 | /**
|
83 | * Adds a timing metric.
|
84 | * The metric is added as a distribution metric.
|
85 | *
|
86 | * You can either directly capture a numeric `value`, or wrap a callback function in `timing`.
|
87 | * In the latter case, the duration of the callback execution will be captured as a span & a metric.
|
88 | *
|
89 | * @experimental This API is experimental and might have breaking changes in the future.
|
90 | */
|
91 | timing(name: string, value: number, unit?: DurationUnit, data?: Omit<MetricData, 'unit'>): void;
|
92 | timing<T>(name: string, callback: () => T, unit?: DurationUnit, data?: Omit<MetricData, 'unit'>): T;
|
93 | }
|
94 | //# sourceMappingURL=metrics.d.ts.map |
\ | No newline at end of file |