Metric.d.ts 4.4 KB

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