syncint64.go raw

   1  // Copyright The OpenTelemetry Authors
   2  // SPDX-License-Identifier: Apache-2.0
   3  
   4  package metric // import "go.opentelemetry.io/otel/metric"
   5  
   6  import (
   7  	"context"
   8  
   9  	"go.opentelemetry.io/otel/metric/embedded"
  10  )
  11  
  12  // Int64Counter is an instrument that records increasing int64 values.
  13  //
  14  // Warning: Methods may be added to this interface in minor releases. See
  15  // package documentation on API implementation for information on how to set
  16  // default behavior for unimplemented methods.
  17  type Int64Counter interface {
  18  	// Users of the interface can ignore this. This embedded type is only used
  19  	// by implementations of this interface. See the "API Implementations"
  20  	// section of the package documentation for more information.
  21  	embedded.Int64Counter
  22  
  23  	// Add records a change to the counter.
  24  	//
  25  	// Use the WithAttributeSet (or, if performance is not a concern,
  26  	// the WithAttributes) option to include measurement attributes.
  27  	Add(ctx context.Context, incr int64, options ...AddOption)
  28  }
  29  
  30  // Int64CounterConfig contains options for synchronous counter instruments that
  31  // record int64 values.
  32  type Int64CounterConfig struct {
  33  	description string
  34  	unit        string
  35  }
  36  
  37  // NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts
  38  // applied.
  39  func NewInt64CounterConfig(opts ...Int64CounterOption) Int64CounterConfig {
  40  	var config Int64CounterConfig
  41  	for _, o := range opts {
  42  		config = o.applyInt64Counter(config)
  43  	}
  44  	return config
  45  }
  46  
  47  // Description returns the configured description.
  48  func (c Int64CounterConfig) Description() string {
  49  	return c.description
  50  }
  51  
  52  // Unit returns the configured unit.
  53  func (c Int64CounterConfig) Unit() string {
  54  	return c.unit
  55  }
  56  
  57  // Int64CounterOption applies options to a [Int64CounterConfig]. See
  58  // [InstrumentOption] for other options that can be used as an
  59  // Int64CounterOption.
  60  type Int64CounterOption interface {
  61  	applyInt64Counter(Int64CounterConfig) Int64CounterConfig
  62  }
  63  
  64  // Int64UpDownCounter is an instrument that records increasing or decreasing
  65  // int64 values.
  66  //
  67  // Warning: Methods may be added to this interface in minor releases. See
  68  // package documentation on API implementation for information on how to set
  69  // default behavior for unimplemented methods.
  70  type Int64UpDownCounter interface {
  71  	// Users of the interface can ignore this. This embedded type is only used
  72  	// by implementations of this interface. See the "API Implementations"
  73  	// section of the package documentation for more information.
  74  	embedded.Int64UpDownCounter
  75  
  76  	// Add records a change to the counter.
  77  	//
  78  	// Use the WithAttributeSet (or, if performance is not a concern,
  79  	// the WithAttributes) option to include measurement attributes.
  80  	Add(ctx context.Context, incr int64, options ...AddOption)
  81  }
  82  
  83  // Int64UpDownCounterConfig contains options for synchronous counter
  84  // instruments that record int64 values.
  85  type Int64UpDownCounterConfig struct {
  86  	description string
  87  	unit        string
  88  }
  89  
  90  // NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with
  91  // all opts applied.
  92  func NewInt64UpDownCounterConfig(opts ...Int64UpDownCounterOption) Int64UpDownCounterConfig {
  93  	var config Int64UpDownCounterConfig
  94  	for _, o := range opts {
  95  		config = o.applyInt64UpDownCounter(config)
  96  	}
  97  	return config
  98  }
  99  
 100  // Description returns the configured description.
 101  func (c Int64UpDownCounterConfig) Description() string {
 102  	return c.description
 103  }
 104  
 105  // Unit returns the configured unit.
 106  func (c Int64UpDownCounterConfig) Unit() string {
 107  	return c.unit
 108  }
 109  
 110  // Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig].
 111  // See [InstrumentOption] for other options that can be used as an
 112  // Int64UpDownCounterOption.
 113  type Int64UpDownCounterOption interface {
 114  	applyInt64UpDownCounter(Int64UpDownCounterConfig) Int64UpDownCounterConfig
 115  }
 116  
 117  // Int64Histogram is an instrument that records a distribution of int64
 118  // values.
 119  //
 120  // Warning: Methods may be added to this interface in minor releases. See
 121  // package documentation on API implementation for information on how to set
 122  // default behavior for unimplemented methods.
 123  type Int64Histogram interface {
 124  	// Users of the interface can ignore this. This embedded type is only used
 125  	// by implementations of this interface. See the "API Implementations"
 126  	// section of the package documentation for more information.
 127  	embedded.Int64Histogram
 128  
 129  	// Record adds an additional value to the distribution.
 130  	//
 131  	// Use the WithAttributeSet (or, if performance is not a concern,
 132  	// the WithAttributes) option to include measurement attributes.
 133  	Record(ctx context.Context, incr int64, options ...RecordOption)
 134  }
 135  
 136  // Int64HistogramConfig contains options for synchronous histogram instruments
 137  // that record int64 values.
 138  type Int64HistogramConfig struct {
 139  	description              string
 140  	unit                     string
 141  	explicitBucketBoundaries []float64
 142  }
 143  
 144  // NewInt64HistogramConfig returns a new [Int64HistogramConfig] with all opts
 145  // applied.
 146  func NewInt64HistogramConfig(opts ...Int64HistogramOption) Int64HistogramConfig {
 147  	var config Int64HistogramConfig
 148  	for _, o := range opts {
 149  		config = o.applyInt64Histogram(config)
 150  	}
 151  	return config
 152  }
 153  
 154  // Description returns the configured description.
 155  func (c Int64HistogramConfig) Description() string {
 156  	return c.description
 157  }
 158  
 159  // Unit returns the configured unit.
 160  func (c Int64HistogramConfig) Unit() string {
 161  	return c.unit
 162  }
 163  
 164  // ExplicitBucketBoundaries returns the configured explicit bucket boundaries.
 165  func (c Int64HistogramConfig) ExplicitBucketBoundaries() []float64 {
 166  	return c.explicitBucketBoundaries
 167  }
 168  
 169  // Int64HistogramOption applies options to a [Int64HistogramConfig]. See
 170  // [InstrumentOption] for other options that can be used as an
 171  // Int64HistogramOption.
 172  type Int64HistogramOption interface {
 173  	applyInt64Histogram(Int64HistogramConfig) Int64HistogramConfig
 174  }
 175  
 176  // Int64Gauge is an instrument that records instantaneous int64 values.
 177  //
 178  // Warning: Methods may be added to this interface in minor releases. See
 179  // package documentation on API implementation for information on how to set
 180  // default behavior for unimplemented methods.
 181  type Int64Gauge interface {
 182  	// Users of the interface can ignore this. This embedded type is only used
 183  	// by implementations of this interface. See the "API Implementations"
 184  	// section of the package documentation for more information.
 185  	embedded.Int64Gauge
 186  
 187  	// Record records the instantaneous value.
 188  	//
 189  	// Use the WithAttributeSet (or, if performance is not a concern,
 190  	// the WithAttributes) option to include measurement attributes.
 191  	Record(ctx context.Context, value int64, options ...RecordOption)
 192  }
 193  
 194  // Int64GaugeConfig contains options for synchronous gauge instruments that
 195  // record int64 values.
 196  type Int64GaugeConfig struct {
 197  	description string
 198  	unit        string
 199  }
 200  
 201  // NewInt64GaugeConfig returns a new [Int64GaugeConfig] with all opts
 202  // applied.
 203  func NewInt64GaugeConfig(opts ...Int64GaugeOption) Int64GaugeConfig {
 204  	var config Int64GaugeConfig
 205  	for _, o := range opts {
 206  		config = o.applyInt64Gauge(config)
 207  	}
 208  	return config
 209  }
 210  
 211  // Description returns the configured description.
 212  func (c Int64GaugeConfig) Description() string {
 213  	return c.description
 214  }
 215  
 216  // Unit returns the configured unit.
 217  func (c Int64GaugeConfig) Unit() string {
 218  	return c.unit
 219  }
 220  
 221  // Int64GaugeOption applies options to a [Int64GaugeConfig]. See
 222  // [InstrumentOption] for other options that can be used as a
 223  // Int64GaugeOption.
 224  type Int64GaugeOption interface {
 225  	applyInt64Gauge(Int64GaugeConfig) Int64GaugeConfig
 226  }
 227