UNPKG

3.81 kBTypeScriptView Raw
1import { Attributes, AttributeValue } from '../common/Attributes';
2import { Context } from '../context/types';
3import { BatchObservableResult, ObservableResult } from './ObservableResult';
4/**
5 * Options needed for metric creation
6 */
7export interface MetricOptions {
8 /**
9 * The description of the Metric.
10 * @default ''
11 */
12 description?: string;
13 /**
14 * The unit of the Metric values.
15 * @default ''
16 */
17 unit?: string;
18 /**
19 * Indicates the type of the recorded value.
20 * @default {@link ValueType.DOUBLE}
21 */
22 valueType?: ValueType;
23}
24/** The Type of value. It describes how the data is reported. */
25export declare enum ValueType {
26 INT = 0,
27 DOUBLE = 1
28}
29/**
30 * Counter is the most common synchronous instrument. This instrument supports
31 * an `Add(increment)` function for reporting a sum, and is restricted to
32 * non-negative increments. The default aggregation is Sum, as for any additive
33 * instrument.
34 *
35 * Example uses for Counter:
36 * <ol>
37 * <li> count the number of bytes received. </li>
38 * <li> count the number of requests completed. </li>
39 * <li> count the number of accounts created. </li>
40 * <li> count the number of checkpoints run. </li>
41 * <li> count the number of 5xx errors. </li>
42 * <ol>
43 */
44export interface Counter<AttributesTypes extends MetricAttributes = MetricAttributes> {
45 /**
46 * Increment value of counter by the input. Inputs must not be negative.
47 */
48 add(value: number, attributes?: AttributesTypes, context?: Context): void;
49}
50export interface UpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> {
51 /**
52 * Increment value of counter by the input. Inputs may be negative.
53 */
54 add(value: number, attributes?: AttributesTypes, context?: Context): void;
55}
56export interface Histogram<AttributesTypes extends MetricAttributes = MetricAttributes> {
57 /**
58 * Records a measurement. Value of the measurement must not be negative.
59 */
60 record(value: number, attributes?: AttributesTypes, context?: Context): void;
61}
62/**
63 * @deprecated please use {@link Attributes}
64 */
65export declare type MetricAttributes = Attributes;
66/**
67 * @deprecated please use {@link AttributeValue}
68 */
69export declare type MetricAttributeValue = AttributeValue;
70/**
71 * The observable callback for Observable instruments.
72 */
73export declare type ObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: ObservableResult<AttributesTypes>) => void | Promise<void>;
74/**
75 * The observable callback for a batch of Observable instruments.
76 */
77export declare type BatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: BatchObservableResult<AttributesTypes>) => void | Promise<void>;
78export interface Observable<AttributesTypes extends MetricAttributes = MetricAttributes> {
79 /**
80 * Sets up a function that will be called whenever a metric collection is initiated.
81 *
82 * If the function is already in the list of callbacks for this Observable, the function is not added a second time.
83 */
84 addCallback(callback: ObservableCallback<AttributesTypes>): void;
85 /**
86 * Removes a callback previously registered with {@link Observable.addCallback}.
87 */
88 removeCallback(callback: ObservableCallback<AttributesTypes>): void;
89}
90export declare type ObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
91export declare type ObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
92export declare type ObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
93//# sourceMappingURL=Metric.d.ts.map
\No newline at end of file