noop.go raw

   1  // Copyright The OpenTelemetry Authors
   2  // SPDX-License-Identifier: Apache-2.0
   3  
   4  // Package noop provides an implementation of the OpenTelemetry metric API that
   5  // produces no telemetry and minimizes used computation resources.
   6  //
   7  // Using this package to implement the OpenTelemetry metric API will
   8  // effectively disable OpenTelemetry.
   9  //
  10  // This implementation can be embedded in other implementations of the
  11  // OpenTelemetry metric API. Doing so will mean the implementation defaults to
  12  // no operation for methods it does not implement.
  13  package noop // import "go.opentelemetry.io/otel/metric/noop"
  14  
  15  import (
  16  	"context"
  17  
  18  	"go.opentelemetry.io/otel/metric"
  19  	"go.opentelemetry.io/otel/metric/embedded"
  20  )
  21  
  22  var (
  23  	// Compile-time check this implements the OpenTelemetry API.
  24  
  25  	_ metric.MeterProvider                  = MeterProvider{}
  26  	_ metric.Meter                          = Meter{}
  27  	_ metric.Observer                       = Observer{}
  28  	_ metric.Registration                   = Registration{}
  29  	_ metric.Int64Counter                   = Int64Counter{}
  30  	_ metric.Float64Counter                 = Float64Counter{}
  31  	_ metric.Int64UpDownCounter             = Int64UpDownCounter{}
  32  	_ metric.Float64UpDownCounter           = Float64UpDownCounter{}
  33  	_ metric.Int64Histogram                 = Int64Histogram{}
  34  	_ metric.Float64Histogram               = Float64Histogram{}
  35  	_ metric.Int64Gauge                     = Int64Gauge{}
  36  	_ metric.Float64Gauge                   = Float64Gauge{}
  37  	_ metric.Int64ObservableCounter         = Int64ObservableCounter{}
  38  	_ metric.Float64ObservableCounter       = Float64ObservableCounter{}
  39  	_ metric.Int64ObservableGauge           = Int64ObservableGauge{}
  40  	_ metric.Float64ObservableGauge         = Float64ObservableGauge{}
  41  	_ metric.Int64ObservableUpDownCounter   = Int64ObservableUpDownCounter{}
  42  	_ metric.Float64ObservableUpDownCounter = Float64ObservableUpDownCounter{}
  43  	_ metric.Int64Observer                  = Int64Observer{}
  44  	_ metric.Float64Observer                = Float64Observer{}
  45  )
  46  
  47  // MeterProvider is an OpenTelemetry No-Op MeterProvider.
  48  type MeterProvider struct{ embedded.MeterProvider }
  49  
  50  // NewMeterProvider returns a MeterProvider that does not record any telemetry.
  51  func NewMeterProvider() MeterProvider {
  52  	return MeterProvider{}
  53  }
  54  
  55  // Meter returns an OpenTelemetry Meter that does not record any telemetry.
  56  func (MeterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
  57  	return Meter{}
  58  }
  59  
  60  // Meter is an OpenTelemetry No-Op Meter.
  61  type Meter struct{ embedded.Meter }
  62  
  63  // Int64Counter returns a Counter used to record int64 measurements that
  64  // produces no telemetry.
  65  func (Meter) Int64Counter(string, ...metric.Int64CounterOption) (metric.Int64Counter, error) {
  66  	return Int64Counter{}, nil
  67  }
  68  
  69  // Int64UpDownCounter returns an UpDownCounter used to record int64
  70  // measurements that produces no telemetry.
  71  func (Meter) Int64UpDownCounter(string, ...metric.Int64UpDownCounterOption) (metric.Int64UpDownCounter, error) {
  72  	return Int64UpDownCounter{}, nil
  73  }
  74  
  75  // Int64Histogram returns a Histogram used to record int64 measurements that
  76  // produces no telemetry.
  77  func (Meter) Int64Histogram(string, ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
  78  	return Int64Histogram{}, nil
  79  }
  80  
  81  // Int64Gauge returns a Gauge used to record int64 measurements that
  82  // produces no telemetry.
  83  func (Meter) Int64Gauge(string, ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
  84  	return Int64Gauge{}, nil
  85  }
  86  
  87  // Int64ObservableCounter returns an ObservableCounter used to record int64
  88  // measurements that produces no telemetry.
  89  func (Meter) Int64ObservableCounter(
  90  	string,
  91  	...metric.Int64ObservableCounterOption,
  92  ) (metric.Int64ObservableCounter, error) {
  93  	return Int64ObservableCounter{}, nil
  94  }
  95  
  96  // Int64ObservableUpDownCounter returns an ObservableUpDownCounter used to
  97  // record int64 measurements that produces no telemetry.
  98  func (Meter) Int64ObservableUpDownCounter(
  99  	string,
 100  	...metric.Int64ObservableUpDownCounterOption,
 101  ) (metric.Int64ObservableUpDownCounter, error) {
 102  	return Int64ObservableUpDownCounter{}, nil
 103  }
 104  
 105  // Int64ObservableGauge returns an ObservableGauge used to record int64
 106  // measurements that produces no telemetry.
 107  func (Meter) Int64ObservableGauge(string, ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
 108  	return Int64ObservableGauge{}, nil
 109  }
 110  
 111  // Float64Counter returns a Counter used to record int64 measurements that
 112  // produces no telemetry.
 113  func (Meter) Float64Counter(string, ...metric.Float64CounterOption) (metric.Float64Counter, error) {
 114  	return Float64Counter{}, nil
 115  }
 116  
 117  // Float64UpDownCounter returns an UpDownCounter used to record int64
 118  // measurements that produces no telemetry.
 119  func (Meter) Float64UpDownCounter(string, ...metric.Float64UpDownCounterOption) (metric.Float64UpDownCounter, error) {
 120  	return Float64UpDownCounter{}, nil
 121  }
 122  
 123  // Float64Histogram returns a Histogram used to record int64 measurements that
 124  // produces no telemetry.
 125  func (Meter) Float64Histogram(string, ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
 126  	return Float64Histogram{}, nil
 127  }
 128  
 129  // Float64Gauge returns a Gauge used to record float64 measurements that
 130  // produces no telemetry.
 131  func (Meter) Float64Gauge(string, ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
 132  	return Float64Gauge{}, nil
 133  }
 134  
 135  // Float64ObservableCounter returns an ObservableCounter used to record int64
 136  // measurements that produces no telemetry.
 137  func (Meter) Float64ObservableCounter(
 138  	string,
 139  	...metric.Float64ObservableCounterOption,
 140  ) (metric.Float64ObservableCounter, error) {
 141  	return Float64ObservableCounter{}, nil
 142  }
 143  
 144  // Float64ObservableUpDownCounter returns an ObservableUpDownCounter used to
 145  // record int64 measurements that produces no telemetry.
 146  func (Meter) Float64ObservableUpDownCounter(
 147  	string,
 148  	...metric.Float64ObservableUpDownCounterOption,
 149  ) (metric.Float64ObservableUpDownCounter, error) {
 150  	return Float64ObservableUpDownCounter{}, nil
 151  }
 152  
 153  // Float64ObservableGauge returns an ObservableGauge used to record int64
 154  // measurements that produces no telemetry.
 155  func (Meter) Float64ObservableGauge(
 156  	string,
 157  	...metric.Float64ObservableGaugeOption,
 158  ) (metric.Float64ObservableGauge, error) {
 159  	return Float64ObservableGauge{}, nil
 160  }
 161  
 162  // RegisterCallback performs no operation.
 163  func (Meter) RegisterCallback(metric.Callback, ...metric.Observable) (metric.Registration, error) {
 164  	return Registration{}, nil
 165  }
 166  
 167  // Observer acts as a recorder of measurements for multiple instruments in a
 168  // Callback, it performing no operation.
 169  type Observer struct{ embedded.Observer }
 170  
 171  // ObserveFloat64 performs no operation.
 172  func (Observer) ObserveFloat64(metric.Float64Observable, float64, ...metric.ObserveOption) {
 173  }
 174  
 175  // ObserveInt64 performs no operation.
 176  func (Observer) ObserveInt64(metric.Int64Observable, int64, ...metric.ObserveOption) {
 177  }
 178  
 179  // Registration is the registration of a Callback with a No-Op Meter.
 180  type Registration struct{ embedded.Registration }
 181  
 182  // Unregister unregisters the Callback the Registration represents with the
 183  // No-Op Meter. This will always return nil because the No-Op Meter performs no
 184  // operation, including hold any record of registrations.
 185  func (Registration) Unregister() error { return nil }
 186  
 187  // Int64Counter is an OpenTelemetry Counter used to record int64 measurements.
 188  // It produces no telemetry.
 189  type Int64Counter struct{ embedded.Int64Counter }
 190  
 191  // Add performs no operation.
 192  func (Int64Counter) Add(context.Context, int64, ...metric.AddOption) {}
 193  
 194  // Float64Counter is an OpenTelemetry Counter used to record float64
 195  // measurements. It produces no telemetry.
 196  type Float64Counter struct{ embedded.Float64Counter }
 197  
 198  // Add performs no operation.
 199  func (Float64Counter) Add(context.Context, float64, ...metric.AddOption) {}
 200  
 201  // Int64UpDownCounter is an OpenTelemetry UpDownCounter used to record int64
 202  // measurements. It produces no telemetry.
 203  type Int64UpDownCounter struct{ embedded.Int64UpDownCounter }
 204  
 205  // Add performs no operation.
 206  func (Int64UpDownCounter) Add(context.Context, int64, ...metric.AddOption) {}
 207  
 208  // Float64UpDownCounter is an OpenTelemetry UpDownCounter used to record
 209  // float64 measurements. It produces no telemetry.
 210  type Float64UpDownCounter struct{ embedded.Float64UpDownCounter }
 211  
 212  // Add performs no operation.
 213  func (Float64UpDownCounter) Add(context.Context, float64, ...metric.AddOption) {}
 214  
 215  // Int64Histogram is an OpenTelemetry Histogram used to record int64
 216  // measurements. It produces no telemetry.
 217  type Int64Histogram struct{ embedded.Int64Histogram }
 218  
 219  // Record performs no operation.
 220  func (Int64Histogram) Record(context.Context, int64, ...metric.RecordOption) {}
 221  
 222  // Float64Histogram is an OpenTelemetry Histogram used to record float64
 223  // measurements. It produces no telemetry.
 224  type Float64Histogram struct{ embedded.Float64Histogram }
 225  
 226  // Record performs no operation.
 227  func (Float64Histogram) Record(context.Context, float64, ...metric.RecordOption) {}
 228  
 229  // Int64Gauge is an OpenTelemetry Gauge used to record instantaneous int64
 230  // measurements. It produces no telemetry.
 231  type Int64Gauge struct{ embedded.Int64Gauge }
 232  
 233  // Record performs no operation.
 234  func (Int64Gauge) Record(context.Context, int64, ...metric.RecordOption) {}
 235  
 236  // Float64Gauge is an OpenTelemetry Gauge used to record instantaneous float64
 237  // measurements. It produces no telemetry.
 238  type Float64Gauge struct{ embedded.Float64Gauge }
 239  
 240  // Record performs no operation.
 241  func (Float64Gauge) Record(context.Context, float64, ...metric.RecordOption) {}
 242  
 243  // Int64ObservableCounter is an OpenTelemetry ObservableCounter used to record
 244  // int64 measurements. It produces no telemetry.
 245  type Int64ObservableCounter struct {
 246  	metric.Int64Observable
 247  	embedded.Int64ObservableCounter
 248  }
 249  
 250  // Float64ObservableCounter is an OpenTelemetry ObservableCounter used to record
 251  // float64 measurements. It produces no telemetry.
 252  type Float64ObservableCounter struct {
 253  	metric.Float64Observable
 254  	embedded.Float64ObservableCounter
 255  }
 256  
 257  // Int64ObservableGauge is an OpenTelemetry ObservableGauge used to record
 258  // int64 measurements. It produces no telemetry.
 259  type Int64ObservableGauge struct {
 260  	metric.Int64Observable
 261  	embedded.Int64ObservableGauge
 262  }
 263  
 264  // Float64ObservableGauge is an OpenTelemetry ObservableGauge used to record
 265  // float64 measurements. It produces no telemetry.
 266  type Float64ObservableGauge struct {
 267  	metric.Float64Observable
 268  	embedded.Float64ObservableGauge
 269  }
 270  
 271  // Int64ObservableUpDownCounter is an OpenTelemetry ObservableUpDownCounter
 272  // used to record int64 measurements. It produces no telemetry.
 273  type Int64ObservableUpDownCounter struct {
 274  	metric.Int64Observable
 275  	embedded.Int64ObservableUpDownCounter
 276  }
 277  
 278  // Float64ObservableUpDownCounter is an OpenTelemetry ObservableUpDownCounter
 279  // used to record float64 measurements. It produces no telemetry.
 280  type Float64ObservableUpDownCounter struct {
 281  	metric.Float64Observable
 282  	embedded.Float64ObservableUpDownCounter
 283  }
 284  
 285  // Int64Observer is a recorder of int64 measurements that performs no operation.
 286  type Int64Observer struct{ embedded.Int64Observer }
 287  
 288  // Observe performs no operation.
 289  func (Int64Observer) Observe(int64, ...metric.ObserveOption) {}
 290  
 291  // Float64Observer is a recorder of float64 measurements that performs no
 292  // operation.
 293  type Float64Observer struct{ embedded.Float64Observer }
 294  
 295  // Observe performs no operation.
 296  func (Float64Observer) Observe(float64, ...metric.ObserveOption) {}
 297