meter.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Copyright The OpenTelemetry Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package metric // import "go.opentelemetry.io/otel/metric"
  15. import (
  16. "context"
  17. "go.opentelemetry.io/otel/metric/embedded"
  18. )
  19. // MeterProvider provides access to named Meter instances, for instrumenting
  20. // an application or package.
  21. //
  22. // Warning: Methods may be added to this interface in minor releases. See
  23. // package documentation on API implementation for information on how to set
  24. // default behavior for unimplemented methods.
  25. type MeterProvider interface {
  26. // Users of the interface can ignore this. This embedded type is only used
  27. // by implementations of this interface. See the "API Implementations"
  28. // section of the package documentation for more information.
  29. embedded.MeterProvider
  30. // Meter returns a new Meter with the provided name and configuration.
  31. //
  32. // A Meter should be scoped at most to a single package. The name needs to
  33. // be unique so it does not collide with other names used by
  34. // an application, nor other applications. To achieve this, the import path
  35. // of the instrumentation package is recommended to be used as name.
  36. //
  37. // If the name is empty, then an implementation defined default name will
  38. // be used instead.
  39. Meter(name string, opts ...MeterOption) Meter
  40. }
  41. // Meter provides access to instrument instances for recording metrics.
  42. //
  43. // Warning: Methods may be added to this interface in minor releases. See
  44. // package documentation on API implementation for information on how to set
  45. // default behavior for unimplemented methods.
  46. type Meter interface {
  47. // Users of the interface can ignore this. This embedded type is only used
  48. // by implementations of this interface. See the "API Implementations"
  49. // section of the package documentation for more information.
  50. embedded.Meter
  51. // Int64Counter returns a new Int64Counter instrument identified by name
  52. // and configured with options. The instrument is used to synchronously
  53. // record increasing int64 measurements during a computational operation.
  54. Int64Counter(name string, options ...Int64CounterOption) (Int64Counter, error)
  55. // Int64UpDownCounter returns a new Int64UpDownCounter instrument
  56. // identified by name and configured with options. The instrument is used
  57. // to synchronously record int64 measurements during a computational
  58. // operation.
  59. Int64UpDownCounter(name string, options ...Int64UpDownCounterOption) (Int64UpDownCounter, error)
  60. // Int64Histogram returns a new Int64Histogram instrument identified by
  61. // name and configured with options. The instrument is used to
  62. // synchronously record the distribution of int64 measurements during a
  63. // computational operation.
  64. Int64Histogram(name string, options ...Int64HistogramOption) (Int64Histogram, error)
  65. // Int64ObservableCounter returns a new Int64ObservableCounter identified
  66. // by name and configured with options. The instrument is used to
  67. // asynchronously record increasing int64 measurements once per a
  68. // measurement collection cycle.
  69. //
  70. // Measurements for the returned instrument are made via a callback. Use
  71. // the WithInt64Callback option to register the callback here, or use the
  72. // RegisterCallback method of this Meter to register one later. See the
  73. // Measurements section of the package documentation for more information.
  74. Int64ObservableCounter(name string, options ...Int64ObservableCounterOption) (Int64ObservableCounter, error)
  75. // Int64ObservableUpDownCounter returns a new Int64ObservableUpDownCounter
  76. // instrument identified by name and configured with options. The
  77. // instrument is used to asynchronously record int64 measurements once per
  78. // a measurement collection cycle.
  79. //
  80. // Measurements for the returned instrument are made via a callback. Use
  81. // the WithInt64Callback option to register the callback here, or use the
  82. // RegisterCallback method of this Meter to register one later. See the
  83. // Measurements section of the package documentation for more information.
  84. Int64ObservableUpDownCounter(name string, options ...Int64ObservableUpDownCounterOption) (Int64ObservableUpDownCounter, error)
  85. // Int64ObservableGauge returns a new Int64ObservableGauge instrument
  86. // identified by name and configured with options. The instrument is used
  87. // to asynchronously record instantaneous int64 measurements once per a
  88. // measurement collection cycle.
  89. //
  90. // Measurements for the returned instrument are made via a callback. Use
  91. // the WithInt64Callback option to register the callback here, or use the
  92. // RegisterCallback method of this Meter to register one later. See the
  93. // Measurements section of the package documentation for more information.
  94. Int64ObservableGauge(name string, options ...Int64ObservableGaugeOption) (Int64ObservableGauge, error)
  95. // Float64Counter returns a new Float64Counter instrument identified by
  96. // name and configured with options. The instrument is used to
  97. // synchronously record increasing float64 measurements during a
  98. // computational operation.
  99. Float64Counter(name string, options ...Float64CounterOption) (Float64Counter, error)
  100. // Float64UpDownCounter returns a new Float64UpDownCounter instrument
  101. // identified by name and configured with options. The instrument is used
  102. // to synchronously record float64 measurements during a computational
  103. // operation.
  104. Float64UpDownCounter(name string, options ...Float64UpDownCounterOption) (Float64UpDownCounter, error)
  105. // Float64Histogram returns a new Float64Histogram instrument identified by
  106. // name and configured with options. The instrument is used to
  107. // synchronously record the distribution of float64 measurements during a
  108. // computational operation.
  109. Float64Histogram(name string, options ...Float64HistogramOption) (Float64Histogram, error)
  110. // Float64ObservableCounter returns a new Float64ObservableCounter
  111. // instrument identified by name and configured with options. The
  112. // instrument is used to asynchronously record increasing float64
  113. // measurements once per a measurement collection cycle.
  114. //
  115. // Measurements for the returned instrument are made via a callback. Use
  116. // the WithFloat64Callback option to register the callback here, or use the
  117. // RegisterCallback method of this Meter to register one later. See the
  118. // Measurements section of the package documentation for more information.
  119. Float64ObservableCounter(name string, options ...Float64ObservableCounterOption) (Float64ObservableCounter, error)
  120. // Float64ObservableUpDownCounter returns a new
  121. // Float64ObservableUpDownCounter instrument identified by name and
  122. // configured with options. The instrument is used to asynchronously record
  123. // float64 measurements once per a measurement collection cycle.
  124. //
  125. // Measurements for the returned instrument are made via a callback. Use
  126. // the WithFloat64Callback option to register the callback here, or use the
  127. // RegisterCallback method of this Meter to register one later. See the
  128. // Measurements section of the package documentation for more information.
  129. Float64ObservableUpDownCounter(name string, options ...Float64ObservableUpDownCounterOption) (Float64ObservableUpDownCounter, error)
  130. // Float64ObservableGauge returns a new Float64ObservableGauge instrument
  131. // identified by name and configured with options. The instrument is used
  132. // to asynchronously record instantaneous float64 measurements once per a
  133. // measurement collection cycle.
  134. //
  135. // Measurements for the returned instrument are made via a callback. Use
  136. // the WithFloat64Callback option to register the callback here, or use the
  137. // RegisterCallback method of this Meter to register one later. See the
  138. // Measurements section of the package documentation for more information.
  139. Float64ObservableGauge(name string, options ...Float64ObservableGaugeOption) (Float64ObservableGauge, error)
  140. // RegisterCallback registers f to be called during the collection of a
  141. // measurement cycle.
  142. //
  143. // If Unregister of the returned Registration is called, f needs to be
  144. // unregistered and not called during collection.
  145. //
  146. // The instruments f is registered with are the only instruments that f may
  147. // observe values for.
  148. //
  149. // If no instruments are passed, f should not be registered nor called
  150. // during collection.
  151. //
  152. // The function f needs to be concurrent safe.
  153. RegisterCallback(f Callback, instruments ...Observable) (Registration, error)
  154. }
  155. // Callback is a function registered with a Meter that makes observations for
  156. // the set of instruments it is registered with. The Observer parameter is used
  157. // to record measurement observations for these instruments.
  158. //
  159. // The function needs to complete in a finite amount of time and the deadline
  160. // of the passed context is expected to be honored.
  161. //
  162. // The function needs to make unique observations across all registered
  163. // Callbacks. Meaning, it should not report measurements for an instrument with
  164. // the same attributes as another Callback will report.
  165. //
  166. // The function needs to be concurrent safe.
  167. type Callback func(context.Context, Observer) error
  168. // Observer records measurements for multiple instruments in a Callback.
  169. //
  170. // Warning: Methods may be added to this interface in minor releases. See
  171. // package documentation on API implementation for information on how to set
  172. // default behavior for unimplemented methods.
  173. type Observer interface {
  174. // Users of the interface can ignore this. This embedded type is only used
  175. // by implementations of this interface. See the "API Implementations"
  176. // section of the package documentation for more information.
  177. embedded.Observer
  178. // ObserveFloat64 records the float64 value for obsrv.
  179. ObserveFloat64(obsrv Float64Observable, value float64, opts ...ObserveOption)
  180. // ObserveInt64 records the int64 value for obsrv.
  181. ObserveInt64(obsrv Int64Observable, value int64, opts ...ObserveOption)
  182. }
  183. // Registration is an token representing the unique registration of a callback
  184. // for a set of instruments with a Meter.
  185. //
  186. // Warning: Methods may be added to this interface in minor releases. See
  187. // package documentation on API implementation for information on how to set
  188. // default behavior for unimplemented methods.
  189. type Registration interface {
  190. // Users of the interface can ignore this. This embedded type is only used
  191. // by implementations of this interface. See the "API Implementations"
  192. // section of the package documentation for more information.
  193. embedded.Registration
  194. // Unregister removes the callback registration from a Meter.
  195. //
  196. // This method needs to be idempotent and concurrent safe.
  197. Unregister() error
  198. }