@opentelemetry/api
Version:
Public API for OpenTelemetry
1 lines • 6.65 kB
Source Map (JSON)
{"version":3,"file":"Metric.js","sourceRoot":"","sources":["../../../src/metrics/Metric.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmDH;;;;GAIG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,uCAAG,CAAA;IACH,6CAAM,CAAA;AACR,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes, AttributeValue } from '../common/Attributes';\nimport type { Context } from '../context/types';\n\n/**\n * Advisory options influencing aggregation configuration parameters.\n *\n * @since 1.7.0\n * @experimental\n */\nexport interface MetricAdvice {\n /**\n * Hint the explicit bucket boundaries for SDK if the metric is been\n * aggregated with a HistogramAggregator.\n */\n explicitBucketBoundaries?: number[];\n}\n\n/**\n * Options needed for metric creation\n *\n * @since 1.3.0\n */\nexport interface MetricOptions {\n /**\n * The description of the Metric.\n * @default ''\n */\n description?: string;\n\n /**\n * The unit of the Metric values.\n * @default ''\n */\n unit?: string;\n\n /**\n * Indicates the type of the recorded value.\n * @default {@link ValueType.DOUBLE}\n */\n valueType?: ValueType;\n\n /**\n * The advice influencing aggregation configuration parameters.\n * @experimental\n * @since 1.7.0\n */\n advice?: MetricAdvice;\n}\n\n/**\n * The Type of value. It describes how the data is reported.\n *\n * @since 1.3.0\n */\nexport enum ValueType {\n INT,\n DOUBLE,\n}\n\n/**\n * Counter is the most common synchronous instrument. This instrument supports\n * an `Add(increment)` function for reporting a sum, and is restricted to\n * non-negative increments. The default aggregation is Sum, as for any additive\n * instrument.\n *\n * Example uses for Counter:\n * <ol>\n * <li> count the number of bytes received. </li>\n * <li> count the number of requests completed. </li>\n * <li> count the number of accounts created. </li>\n * <li> count the number of checkpoints run. </li>\n * <li> count the number of 5xx errors. </li>\n * <ol>\n *\n * @since 1.3.0\n */\nexport interface Counter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs must not be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @since 1.3.0\n */\nexport interface UpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Increment value of counter by the input. Inputs may be negative.\n */\n add(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @since 1.9.0\n */\nexport interface Gauge<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Records a measurement.\n */\n record(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @since 1.3.0\n */\nexport interface Histogram<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Records a measurement. Value of the measurement must not be negative.\n */\n record(value: number, attributes?: AttributesTypes, context?: Context): void;\n}\n\n/**\n * @deprecated please use {@link Attributes}\n * @since 1.3.0\n */\nexport type MetricAttributes = Attributes;\n\n/**\n * @deprecated please use {@link AttributeValue}\n * @since 1.3.0\n */\nexport type MetricAttributeValue = AttributeValue;\n\n/**\n * Interface that is being used in callback function for Observable Metric.\n *\n * @since 1.3.0\n */\nexport interface ObservableResult<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Observe a measurement of the value associated with the given attributes.\n *\n * @param value The value to be observed.\n * @param attributes The attributes associated with the value. If more than\n * one value is associated with the same attributes values, SDK may pick the\n * last one or simply drop the entire observable result.\n */\n observe(\n this: ObservableResult<AttributesTypes>,\n value: number,\n attributes?: AttributesTypes\n ): void;\n}\n\n/**\n * Interface that is being used in batch observable callback function.\n */\nexport interface BatchObservableResult<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Observe a measurement of the value associated with the given attributes.\n *\n * @param metric The observable metric to be observed.\n * @param value The value to be observed.\n * @param attributes The attributes associated with the value. If more than\n * one value is associated with the same attributes values, SDK may pick the\n * last one or simply drop the entire observable result.\n */\n observe(\n this: BatchObservableResult<AttributesTypes>,\n metric: Observable<AttributesTypes>,\n value: number,\n attributes?: AttributesTypes\n ): void;\n}\n\n/**\n * The observable callback for Observable instruments.\n *\n * @since 1.3.0\n */\nexport type ObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: ObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\n/**\n * The observable callback for a batch of Observable instruments.\n *\n * @since 1.3.0\n */\nexport type BatchObservableCallback<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = (\n observableResult: BatchObservableResult<AttributesTypes>\n) => void | Promise<void>;\n\n/**\n * @since 1.3.0\n */\nexport interface Observable<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> {\n /**\n * Sets up a function that will be called whenever a metric collection is initiated.\n *\n * If the function is already in the list of callbacks for this Observable, the function is not added a second time.\n */\n addCallback(callback: ObservableCallback<AttributesTypes>): void;\n\n /**\n * Removes a callback previously registered with {@link Observable.addCallback}.\n */\n removeCallback(callback: ObservableCallback<AttributesTypes>): void;\n}\n\n/**\n * @since 1.3.0\n */\nexport type ObservableCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\n/**\n * @since 1.3.0\n */\nexport type ObservableUpDownCounter<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\n/**\n * @since 1.3.0\n */\nexport type ObservableGauge<\n AttributesTypes extends MetricAttributes = MetricAttributes,\n> = Observable<AttributesTypes>;\n"]}