syncfloat64.go 7.5 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. // 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. Add(ctx context.Context, incr float64, options ...AddOption)
  23. }
  24. // Float64CounterConfig contains options for synchronous counter instruments that
  25. // record float64 values.
  26. type Float64CounterConfig struct {
  27. description string
  28. unit string
  29. }
  30. // NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts
  31. // applied.
  32. func NewFloat64CounterConfig(opts ...Float64CounterOption) Float64CounterConfig {
  33. var config Float64CounterConfig
  34. for _, o := range opts {
  35. config = o.applyFloat64Counter(config)
  36. }
  37. return config
  38. }
  39. // Description returns the configured description.
  40. func (c Float64CounterConfig) Description() string {
  41. return c.description
  42. }
  43. // Unit returns the configured unit.
  44. func (c Float64CounterConfig) Unit() string {
  45. return c.unit
  46. }
  47. // Float64CounterOption applies options to a [Float64CounterConfig]. See
  48. // [InstrumentOption] for other options that can be used as a
  49. // Float64CounterOption.
  50. type Float64CounterOption interface {
  51. applyFloat64Counter(Float64CounterConfig) Float64CounterConfig
  52. }
  53. // Float64UpDownCounter is an instrument that records increasing or decreasing
  54. // float64 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 Float64UpDownCounter 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.Float64UpDownCounter
  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 float64, options ...AddOption)
  69. }
  70. // Float64UpDownCounterConfig contains options for synchronous counter
  71. // instruments that record float64 values.
  72. type Float64UpDownCounterConfig struct {
  73. description string
  74. unit string
  75. }
  76. // NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig]
  77. // with all opts applied.
  78. func NewFloat64UpDownCounterConfig(opts ...Float64UpDownCounterOption) Float64UpDownCounterConfig {
  79. var config Float64UpDownCounterConfig
  80. for _, o := range opts {
  81. config = o.applyFloat64UpDownCounter(config)
  82. }
  83. return config
  84. }
  85. // Description returns the configured description.
  86. func (c Float64UpDownCounterConfig) Description() string {
  87. return c.description
  88. }
  89. // Unit returns the configured unit.
  90. func (c Float64UpDownCounterConfig) Unit() string {
  91. return c.unit
  92. }
  93. // Float64UpDownCounterOption applies options to a
  94. // [Float64UpDownCounterConfig]. See [InstrumentOption] for other options that
  95. // can be used as a Float64UpDownCounterOption.
  96. type Float64UpDownCounterOption interface {
  97. applyFloat64UpDownCounter(Float64UpDownCounterConfig) Float64UpDownCounterConfig
  98. }
  99. // Float64Histogram is an instrument that records a distribution of float64
  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 Float64Histogram 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.Float64Histogram
  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 float64, options ...RecordOption)
  115. }
  116. // Float64HistogramConfig contains options for synchronous histogram
  117. // instruments that record float64 values.
  118. type Float64HistogramConfig struct {
  119. description string
  120. unit string
  121. explicitBucketBoundaries []float64
  122. }
  123. // NewFloat64HistogramConfig returns a new [Float64HistogramConfig] with all
  124. // opts applied.
  125. func NewFloat64HistogramConfig(opts ...Float64HistogramOption) Float64HistogramConfig {
  126. var config Float64HistogramConfig
  127. for _, o := range opts {
  128. config = o.applyFloat64Histogram(config)
  129. }
  130. return config
  131. }
  132. // Description returns the configured description.
  133. func (c Float64HistogramConfig) Description() string {
  134. return c.description
  135. }
  136. // Unit returns the configured unit.
  137. func (c Float64HistogramConfig) Unit() string {
  138. return c.unit
  139. }
  140. // ExplicitBucketBoundaries returns the configured explicit bucket boundaries.
  141. func (c Float64HistogramConfig) ExplicitBucketBoundaries() []float64 {
  142. return c.explicitBucketBoundaries
  143. }
  144. // Float64HistogramOption applies options to a [Float64HistogramConfig]. See
  145. // [InstrumentOption] for other options that can be used as a
  146. // Float64HistogramOption.
  147. type Float64HistogramOption interface {
  148. applyFloat64Histogram(Float64HistogramConfig) Float64HistogramConfig
  149. }
  150. // Float64Gauge is an instrument that records instantaneous float64 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 Float64Gauge 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.Float64Gauge
  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 float64, options ...RecordOption)
  165. }
  166. // Float64GaugeConfig contains options for synchronous gauge instruments that
  167. // record float64 values.
  168. type Float64GaugeConfig struct {
  169. description string
  170. unit string
  171. }
  172. // NewFloat64GaugeConfig returns a new [Float64GaugeConfig] with all opts
  173. // applied.
  174. func NewFloat64GaugeConfig(opts ...Float64GaugeOption) Float64GaugeConfig {
  175. var config Float64GaugeConfig
  176. for _, o := range opts {
  177. config = o.applyFloat64Gauge(config)
  178. }
  179. return config
  180. }
  181. // Description returns the configured description.
  182. func (c Float64GaugeConfig) Description() string {
  183. return c.description
  184. }
  185. // Unit returns the configured unit.
  186. func (c Float64GaugeConfig) Unit() string {
  187. return c.unit
  188. }
  189. // Float64GaugeOption applies options to a [Float64GaugeConfig]. See
  190. // [InstrumentOption] for other options that can be used as a
  191. // Float64GaugeOption.
  192. type Float64GaugeOption interface {
  193. applyFloat64Gauge(Float64GaugeConfig) Float64GaugeConfig
  194. }