UNPKG

4.02 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 * Attributes is a map from string to attribute values.
64 *
65 * Note: only the own enumerable keys are counted as valid attribute keys.
66 */
67export declare type MetricAttributes = Attributes;
68/**
69 * Attribute values may be any non-nullish primitive value except an object.
70 *
71 * null or undefined attribute values are invalid and will result in undefined behavior.
72 */
73export declare type MetricAttributeValue = AttributeValue;
74/**
75 * The observable callback for Observable instruments.
76 */
77export declare type ObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: ObservableResult<AttributesTypes>) => void | Promise<void>;
78/**
79 * The observable callback for a batch of Observable instruments.
80 */
81export declare type BatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: BatchObservableResult<AttributesTypes>) => void | Promise<void>;
82export interface Observable<AttributesTypes extends MetricAttributes = MetricAttributes> {
83 /**
84 * Sets up a function that will be called whenever a metric collection is initiated.
85 *
86 * If the function is already in the list of callbacks for this Observable, the function is not added a second time.
87 */
88 addCallback(callback: ObservableCallback<AttributesTypes>): void;
89 /**
90 * Removes a callback previously registered with {@link Observable.addCallback}.
91 */
92 removeCallback(callback: ObservableCallback<AttributesTypes>): void;
93}
94export declare type ObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
95export declare type ObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
96export declare type ObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
97//# sourceMappingURL=Metric.d.ts.map
\No newline at end of file