NoopMeter.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
  18. * constant NoopMetrics for all of its methods.
  19. */
  20. export class NoopMeter {
  21. constructor() { }
  22. /**
  23. * @see {@link Meter.createGauge}
  24. */
  25. createGauge(_name, _options) {
  26. return NOOP_GAUGE_METRIC;
  27. }
  28. /**
  29. * @see {@link Meter.createHistogram}
  30. */
  31. createHistogram(_name, _options) {
  32. return NOOP_HISTOGRAM_METRIC;
  33. }
  34. /**
  35. * @see {@link Meter.createCounter}
  36. */
  37. createCounter(_name, _options) {
  38. return NOOP_COUNTER_METRIC;
  39. }
  40. /**
  41. * @see {@link Meter.createUpDownCounter}
  42. */
  43. createUpDownCounter(_name, _options) {
  44. return NOOP_UP_DOWN_COUNTER_METRIC;
  45. }
  46. /**
  47. * @see {@link Meter.createObservableGauge}
  48. */
  49. createObservableGauge(_name, _options) {
  50. return NOOP_OBSERVABLE_GAUGE_METRIC;
  51. }
  52. /**
  53. * @see {@link Meter.createObservableCounter}
  54. */
  55. createObservableCounter(_name, _options) {
  56. return NOOP_OBSERVABLE_COUNTER_METRIC;
  57. }
  58. /**
  59. * @see {@link Meter.createObservableUpDownCounter}
  60. */
  61. createObservableUpDownCounter(_name, _options) {
  62. return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
  63. }
  64. /**
  65. * @see {@link Meter.addBatchObservableCallback}
  66. */
  67. addBatchObservableCallback(_callback, _observables) { }
  68. /**
  69. * @see {@link Meter.removeBatchObservableCallback}
  70. */
  71. removeBatchObservableCallback(_callback) { }
  72. }
  73. export class NoopMetric {
  74. }
  75. export class NoopCounterMetric extends NoopMetric {
  76. add(_value, _attributes) { }
  77. }
  78. export class NoopUpDownCounterMetric extends NoopMetric {
  79. add(_value, _attributes) { }
  80. }
  81. export class NoopGaugeMetric extends NoopMetric {
  82. record(_value, _attributes) { }
  83. }
  84. export class NoopHistogramMetric extends NoopMetric {
  85. record(_value, _attributes) { }
  86. }
  87. export class NoopObservableMetric {
  88. addCallback(_callback) { }
  89. removeCallback(_callback) { }
  90. }
  91. export class NoopObservableCounterMetric extends NoopObservableMetric {
  92. }
  93. export class NoopObservableGaugeMetric extends NoopObservableMetric {
  94. }
  95. export class NoopObservableUpDownCounterMetric extends NoopObservableMetric {
  96. }
  97. export const NOOP_METER = new NoopMeter();
  98. // Synchronous instruments
  99. export const NOOP_COUNTER_METRIC = new NoopCounterMetric();
  100. export const NOOP_GAUGE_METRIC = new NoopGaugeMetric();
  101. export const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
  102. export const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
  103. // Asynchronous instruments
  104. export const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
  105. export const NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
  106. export const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
  107. /**
  108. * Create a no-op Meter
  109. */
  110. export function createNoopMeter() {
  111. return NOOP_METER;
  112. }
  113. //# sourceMappingURL=NoopMeter.js.map