nop.go 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package metrics
  2. import "context"
  3. // NopMeterProvider is a no-op metrics implementation.
  4. type NopMeterProvider struct{}
  5. var _ MeterProvider = (*NopMeterProvider)(nil)
  6. // Meter returns a meter which creates no-op instruments.
  7. func (NopMeterProvider) Meter(string, ...MeterOption) Meter {
  8. return NopMeter{}
  9. }
  10. // NopMeter creates no-op instruments.
  11. type NopMeter struct{}
  12. var _ Meter = (*NopMeter)(nil)
  13. // Int64Counter creates a no-op instrument.
  14. func (NopMeter) Int64Counter(string, ...InstrumentOption) (Int64Counter, error) {
  15. return nopInstrumentInt64, nil
  16. }
  17. // Int64UpDownCounter creates a no-op instrument.
  18. func (NopMeter) Int64UpDownCounter(string, ...InstrumentOption) (Int64UpDownCounter, error) {
  19. return nopInstrumentInt64, nil
  20. }
  21. // Int64Gauge creates a no-op instrument.
  22. func (NopMeter) Int64Gauge(string, ...InstrumentOption) (Int64Gauge, error) {
  23. return nopInstrumentInt64, nil
  24. }
  25. // Int64Histogram creates a no-op instrument.
  26. func (NopMeter) Int64Histogram(string, ...InstrumentOption) (Int64Histogram, error) {
  27. return nopInstrumentInt64, nil
  28. }
  29. // Int64AsyncCounter creates a no-op instrument.
  30. func (NopMeter) Int64AsyncCounter(string, Int64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  31. return nopInstrumentInt64, nil
  32. }
  33. // Int64AsyncUpDownCounter creates a no-op instrument.
  34. func (NopMeter) Int64AsyncUpDownCounter(string, Int64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  35. return nopInstrumentInt64, nil
  36. }
  37. // Int64AsyncGauge creates a no-op instrument.
  38. func (NopMeter) Int64AsyncGauge(string, Int64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  39. return nopInstrumentInt64, nil
  40. }
  41. // Float64Counter creates a no-op instrument.
  42. func (NopMeter) Float64Counter(string, ...InstrumentOption) (Float64Counter, error) {
  43. return nopInstrumentFloat64, nil
  44. }
  45. // Float64UpDownCounter creates a no-op instrument.
  46. func (NopMeter) Float64UpDownCounter(string, ...InstrumentOption) (Float64UpDownCounter, error) {
  47. return nopInstrumentFloat64, nil
  48. }
  49. // Float64Gauge creates a no-op instrument.
  50. func (NopMeter) Float64Gauge(string, ...InstrumentOption) (Float64Gauge, error) {
  51. return nopInstrumentFloat64, nil
  52. }
  53. // Float64Histogram creates a no-op instrument.
  54. func (NopMeter) Float64Histogram(string, ...InstrumentOption) (Float64Histogram, error) {
  55. return nopInstrumentFloat64, nil
  56. }
  57. // Float64AsyncCounter creates a no-op instrument.
  58. func (NopMeter) Float64AsyncCounter(string, Float64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  59. return nopInstrumentFloat64, nil
  60. }
  61. // Float64AsyncUpDownCounter creates a no-op instrument.
  62. func (NopMeter) Float64AsyncUpDownCounter(string, Float64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  63. return nopInstrumentFloat64, nil
  64. }
  65. // Float64AsyncGauge creates a no-op instrument.
  66. func (NopMeter) Float64AsyncGauge(string, Float64Callback, ...InstrumentOption) (AsyncInstrument, error) {
  67. return nopInstrumentFloat64, nil
  68. }
  69. type nopInstrument[N any] struct{}
  70. func (nopInstrument[N]) Add(context.Context, N, ...RecordMetricOption) {}
  71. func (nopInstrument[N]) Sample(context.Context, N, ...RecordMetricOption) {}
  72. func (nopInstrument[N]) Record(context.Context, N, ...RecordMetricOption) {}
  73. func (nopInstrument[_]) Stop() {}
  74. var nopInstrumentInt64 = nopInstrument[int64]{}
  75. var nopInstrumentFloat64 = nopInstrument[float64]{}