src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

nop.go (3382B)


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