syncint64.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. //
  23. // Implementations of this method need to be safe for a user to call
  24. // concurrently.
  25. Add(ctx context.Context, incr int64, options ...AddOption)
  26. // Enabled reports whether the instrument will process measurements for the given context.
  27. //
  28. // This function can be used in places where measuring an instrument
  29. // would result in computationally expensive operations.
  30. //
  31. // Implementations of this method need to be safe for a user to call
  32. // concurrently.
  33. Enabled(context.Context) bool
  34. }
  35. // Int64CounterConfig contains options for synchronous counter instruments that
  36. // record int64 values.
  37. type Int64CounterConfig struct {
  38. description string
  39. unit string
  40. }
  41. // NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts
  42. // applied.
  43. func NewInt64CounterConfig(opts ...Int64CounterOption) Int64CounterConfig {
  44. var config Int64CounterConfig
  45. for _, o := range opts {
  46. config = o.applyInt64Counter(config)
  47. }
  48. return config
  49. }
  50. // Description returns the configured description.
  51. func (c Int64CounterConfig) Description() string {
  52. return c.description
  53. }
  54. // Unit returns the configured unit.
  55. func (c Int64CounterConfig) Unit() string {
  56. return c.unit
  57. }
  58. // Int64CounterOption applies options to a [Int64CounterConfig]. See
  59. // [InstrumentOption] for other options that can be used as an
  60. // Int64CounterOption.
  61. type Int64CounterOption interface {
  62. applyInt64Counter(Int64CounterConfig) Int64CounterConfig
  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. // Add records a change to the counter.
  76. //
  77. // Use the WithAttributeSet (or, if performance is not a concern,
  78. // the WithAttributes) option to include measurement attributes.
  79. //
  80. // Implementations of this method need to be safe for a user to call
  81. // concurrently.
  82. Add(ctx context.Context, incr int64, options ...AddOption)
  83. // Enabled reports whether the instrument will process measurements for the given context.
  84. //
  85. // This function can be used in places where measuring an instrument
  86. // would result in computationally expensive operations.
  87. //
  88. // Implementations of this method need to be safe for a user to call
  89. // concurrently.
  90. Enabled(context.Context) bool
  91. }
  92. // Int64UpDownCounterConfig contains options for synchronous counter
  93. // instruments that record int64 values.
  94. type Int64UpDownCounterConfig struct {
  95. description string
  96. unit string
  97. }
  98. // NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with
  99. // all opts applied.
  100. func NewInt64UpDownCounterConfig(opts ...Int64UpDownCounterOption) Int64UpDownCounterConfig {
  101. var config Int64UpDownCounterConfig
  102. for _, o := range opts {
  103. config = o.applyInt64UpDownCounter(config)
  104. }
  105. return config
  106. }
  107. // Description returns the configured description.
  108. func (c Int64UpDownCounterConfig) Description() string {
  109. return c.description
  110. }
  111. // Unit returns the configured unit.
  112. func (c Int64UpDownCounterConfig) Unit() string {
  113. return c.unit
  114. }
  115. // Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig].
  116. // See [InstrumentOption] for other options that can be used as an
  117. // Int64UpDownCounterOption.
  118. type Int64UpDownCounterOption interface {
  119. applyInt64UpDownCounter(Int64UpDownCounterConfig) Int64UpDownCounterConfig
  120. }
  121. // Int64Histogram is an instrument that records a distribution of int64
  122. // values.
  123. //
  124. // Warning: Methods may be added to this interface in minor releases. See
  125. // package documentation on API implementation for information on how to set
  126. // default behavior for unimplemented methods.
  127. type Int64Histogram interface {
  128. // Users of the interface can ignore this. This embedded type is only used
  129. // by implementations of this interface. See the "API Implementations"
  130. // section of the package documentation for more information.
  131. embedded.Int64Histogram
  132. // Record adds an additional value to the distribution.
  133. //
  134. // Use the WithAttributeSet (or, if performance is not a concern,
  135. // the WithAttributes) option to include measurement attributes.
  136. //
  137. // Implementations of this method need to be safe for a user to call
  138. // concurrently.
  139. Record(ctx context.Context, incr int64, options ...RecordOption)
  140. // Enabled reports whether the instrument will process measurements for the given context.
  141. //
  142. // This function can be used in places where measuring an instrument
  143. // would result in computationally expensive operations.
  144. //
  145. // Implementations of this method need to be safe for a user to call
  146. // concurrently.
  147. Enabled(context.Context) bool
  148. }
  149. // Int64HistogramConfig contains options for synchronous histogram instruments
  150. // that record int64 values.
  151. type Int64HistogramConfig struct {
  152. description string
  153. unit string
  154. explicitBucketBoundaries []float64
  155. }
  156. // NewInt64HistogramConfig returns a new [Int64HistogramConfig] with all opts
  157. // applied.
  158. func NewInt64HistogramConfig(opts ...Int64HistogramOption) Int64HistogramConfig {
  159. var config Int64HistogramConfig
  160. for _, o := range opts {
  161. config = o.applyInt64Histogram(config)
  162. }
  163. return config
  164. }
  165. // Description returns the configured description.
  166. func (c Int64HistogramConfig) Description() string {
  167. return c.description
  168. }
  169. // Unit returns the configured unit.
  170. func (c Int64HistogramConfig) Unit() string {
  171. return c.unit
  172. }
  173. // ExplicitBucketBoundaries returns the configured explicit bucket boundaries.
  174. func (c Int64HistogramConfig) ExplicitBucketBoundaries() []float64 {
  175. return c.explicitBucketBoundaries
  176. }
  177. // Int64HistogramOption applies options to a [Int64HistogramConfig]. See
  178. // [InstrumentOption] for other options that can be used as an
  179. // Int64HistogramOption.
  180. type Int64HistogramOption interface {
  181. applyInt64Histogram(Int64HistogramConfig) Int64HistogramConfig
  182. }
  183. // Int64Gauge is an instrument that records instantaneous int64 values.
  184. //
  185. // Warning: Methods may be added to this interface in minor releases. See
  186. // package documentation on API implementation for information on how to set
  187. // default behavior for unimplemented methods.
  188. type Int64Gauge interface {
  189. // Users of the interface can ignore this. This embedded type is only used
  190. // by implementations of this interface. See the "API Implementations"
  191. // section of the package documentation for more information.
  192. embedded.Int64Gauge
  193. // Record records the instantaneous value.
  194. //
  195. // Use the WithAttributeSet (or, if performance is not a concern,
  196. // the WithAttributes) option to include measurement attributes.
  197. //
  198. // Implementations of this method need to be safe for a user to call
  199. // concurrently.
  200. Record(ctx context.Context, value int64, options ...RecordOption)
  201. // Enabled reports whether the instrument will process measurements for the given context.
  202. //
  203. // This function can be used in places where measuring an instrument
  204. // would result in computationally expensive operations.
  205. //
  206. // Implementations of this method need to be safe for a user to call
  207. // concurrently.
  208. Enabled(context.Context) bool
  209. }
  210. // Int64GaugeConfig contains options for synchronous gauge instruments that
  211. // record int64 values.
  212. type Int64GaugeConfig struct {
  213. description string
  214. unit string
  215. }
  216. // NewInt64GaugeConfig returns a new [Int64GaugeConfig] with all opts
  217. // applied.
  218. func NewInt64GaugeConfig(opts ...Int64GaugeOption) Int64GaugeConfig {
  219. var config Int64GaugeConfig
  220. for _, o := range opts {
  221. config = o.applyInt64Gauge(config)
  222. }
  223. return config
  224. }
  225. // Description returns the configured description.
  226. func (c Int64GaugeConfig) Description() string {
  227. return c.description
  228. }
  229. // Unit returns the configured unit.
  230. func (c Int64GaugeConfig) Unit() string {
  231. return c.unit
  232. }
  233. // Int64GaugeOption applies options to a [Int64GaugeConfig]. See
  234. // [InstrumentOption] for other options that can be used as a
  235. // Int64GaugeOption.
  236. type Int64GaugeOption interface {
  237. applyInt64Gauge(Int64GaugeConfig) Int64GaugeConfig
  238. }