syncfloat64.go 9.2 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. // Float64Counter is an instrument that records increasing float64 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 Float64Counter 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.Float64Counter
  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 float64, 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. // Float64CounterConfig contains options for synchronous counter instruments that
  36. // record float64 values.
  37. type Float64CounterConfig struct {
  38. description string
  39. unit string
  40. }
  41. // NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts
  42. // applied.
  43. func NewFloat64CounterConfig(opts ...Float64CounterOption) Float64CounterConfig {
  44. var config Float64CounterConfig
  45. for _, o := range opts {
  46. config = o.applyFloat64Counter(config)
  47. }
  48. return config
  49. }
  50. // Description returns the configured description.
  51. func (c Float64CounterConfig) Description() string {
  52. return c.description
  53. }
  54. // Unit returns the configured unit.
  55. func (c Float64CounterConfig) Unit() string {
  56. return c.unit
  57. }
  58. // Float64CounterOption applies options to a [Float64CounterConfig]. See
  59. // [InstrumentOption] for other options that can be used as a
  60. // Float64CounterOption.
  61. type Float64CounterOption interface {
  62. applyFloat64Counter(Float64CounterConfig) Float64CounterConfig
  63. }
  64. // Float64UpDownCounter is an instrument that records increasing or decreasing
  65. // float64 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 Float64UpDownCounter 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.Float64UpDownCounter
  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 float64, 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. // Float64UpDownCounterConfig contains options for synchronous counter
  93. // instruments that record float64 values.
  94. type Float64UpDownCounterConfig struct {
  95. description string
  96. unit string
  97. }
  98. // NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig]
  99. // with all opts applied.
  100. func NewFloat64UpDownCounterConfig(opts ...Float64UpDownCounterOption) Float64UpDownCounterConfig {
  101. var config Float64UpDownCounterConfig
  102. for _, o := range opts {
  103. config = o.applyFloat64UpDownCounter(config)
  104. }
  105. return config
  106. }
  107. // Description returns the configured description.
  108. func (c Float64UpDownCounterConfig) Description() string {
  109. return c.description
  110. }
  111. // Unit returns the configured unit.
  112. func (c Float64UpDownCounterConfig) Unit() string {
  113. return c.unit
  114. }
  115. // Float64UpDownCounterOption applies options to a
  116. // [Float64UpDownCounterConfig]. See [InstrumentOption] for other options that
  117. // can be used as a Float64UpDownCounterOption.
  118. type Float64UpDownCounterOption interface {
  119. applyFloat64UpDownCounter(Float64UpDownCounterConfig) Float64UpDownCounterConfig
  120. }
  121. // Float64Histogram is an instrument that records a distribution of float64
  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 Float64Histogram 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.Float64Histogram
  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 float64, 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. // Float64HistogramConfig contains options for synchronous histogram
  150. // instruments that record float64 values.
  151. type Float64HistogramConfig struct {
  152. description string
  153. unit string
  154. explicitBucketBoundaries []float64
  155. }
  156. // NewFloat64HistogramConfig returns a new [Float64HistogramConfig] with all
  157. // opts applied.
  158. func NewFloat64HistogramConfig(opts ...Float64HistogramOption) Float64HistogramConfig {
  159. var config Float64HistogramConfig
  160. for _, o := range opts {
  161. config = o.applyFloat64Histogram(config)
  162. }
  163. return config
  164. }
  165. // Description returns the configured description.
  166. func (c Float64HistogramConfig) Description() string {
  167. return c.description
  168. }
  169. // Unit returns the configured unit.
  170. func (c Float64HistogramConfig) Unit() string {
  171. return c.unit
  172. }
  173. // ExplicitBucketBoundaries returns the configured explicit bucket boundaries.
  174. func (c Float64HistogramConfig) ExplicitBucketBoundaries() []float64 {
  175. return c.explicitBucketBoundaries
  176. }
  177. // Float64HistogramOption applies options to a [Float64HistogramConfig]. See
  178. // [InstrumentOption] for other options that can be used as a
  179. // Float64HistogramOption.
  180. type Float64HistogramOption interface {
  181. applyFloat64Histogram(Float64HistogramConfig) Float64HistogramConfig
  182. }
  183. // Float64Gauge is an instrument that records instantaneous float64 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 Float64Gauge 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.Float64Gauge
  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 float64, 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. // Float64GaugeConfig contains options for synchronous gauge instruments that
  211. // record float64 values.
  212. type Float64GaugeConfig struct {
  213. description string
  214. unit string
  215. }
  216. // NewFloat64GaugeConfig returns a new [Float64GaugeConfig] with all opts
  217. // applied.
  218. func NewFloat64GaugeConfig(opts ...Float64GaugeOption) Float64GaugeConfig {
  219. var config Float64GaugeConfig
  220. for _, o := range opts {
  221. config = o.applyFloat64Gauge(config)
  222. }
  223. return config
  224. }
  225. // Description returns the configured description.
  226. func (c Float64GaugeConfig) Description() string {
  227. return c.description
  228. }
  229. // Unit returns the configured unit.
  230. func (c Float64GaugeConfig) Unit() string {
  231. return c.unit
  232. }
  233. // Float64GaugeOption applies options to a [Float64GaugeConfig]. See
  234. // [InstrumentOption] for other options that can be used as a
  235. // Float64GaugeOption.
  236. type Float64GaugeOption interface {
  237. applyFloat64Gauge(Float64GaugeConfig) Float64GaugeConfig
  238. }