syncint64.go 7.3 KB

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