meter.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. // MeterProvider provides access to named Meter instances, for instrumenting
  9. // an application or package.
  10. //
  11. // Warning: Methods may be added to this interface in minor releases. See
  12. // package documentation on API implementation for information on how to set
  13. // default behavior for unimplemented methods.
  14. type MeterProvider interface {
  15. // Users of the interface can ignore this. This embedded type is only used
  16. // by implementations of this interface. See the "API Implementations"
  17. // section of the package documentation for more information.
  18. embedded.MeterProvider
  19. // Meter returns a new Meter with the provided name and configuration.
  20. //
  21. // A Meter should be scoped at most to a single package. The name needs to
  22. // be unique so it does not collide with other names used by
  23. // an application, nor other applications. To achieve this, the import path
  24. // of the instrumentation package is recommended to be used as name.
  25. //
  26. // If the name is empty, then an implementation defined default name will
  27. // be used instead.
  28. Meter(name string, opts ...MeterOption) Meter
  29. }
  30. // Meter provides access to instrument instances for recording metrics.
  31. //
  32. // Warning: Methods may be added to this interface in minor releases. See
  33. // package documentation on API implementation for information on how to set
  34. // default behavior for unimplemented methods.
  35. type Meter interface {
  36. // Users of the interface can ignore this. This embedded type is only used
  37. // by implementations of this interface. See the "API Implementations"
  38. // section of the package documentation for more information.
  39. embedded.Meter
  40. // Int64Counter returns a new Int64Counter instrument identified by name
  41. // and configured with options. The instrument is used to synchronously
  42. // record increasing int64 measurements during a computational operation.
  43. //
  44. // The name needs to conform to the OpenTelemetry instrument name syntax.
  45. // See the Instrument Name section of the package documentation for more
  46. // information.
  47. Int64Counter(name string, options ...Int64CounterOption) (Int64Counter, error)
  48. // Int64UpDownCounter returns a new Int64UpDownCounter instrument
  49. // identified by name and configured with options. The instrument is used
  50. // to synchronously record int64 measurements during a computational
  51. // operation.
  52. //
  53. // The name needs to conform to the OpenTelemetry instrument name syntax.
  54. // See the Instrument Name section of the package documentation for more
  55. // information.
  56. Int64UpDownCounter(name string, options ...Int64UpDownCounterOption) (Int64UpDownCounter, error)
  57. // Int64Histogram returns a new Int64Histogram instrument identified by
  58. // name and configured with options. The instrument is used to
  59. // synchronously record the distribution of int64 measurements during a
  60. // computational operation.
  61. //
  62. // The name needs to conform to the OpenTelemetry instrument name syntax.
  63. // See the Instrument Name section of the package documentation for more
  64. // information.
  65. Int64Histogram(name string, options ...Int64HistogramOption) (Int64Histogram, error)
  66. // Int64Gauge returns a new Int64Gauge instrument identified by name and
  67. // configured with options. The instrument is used to synchronously record
  68. // instantaneous int64 measurements during a computational operation.
  69. //
  70. // The name needs to conform to the OpenTelemetry instrument name syntax.
  71. // See the Instrument Name section of the package documentation for more
  72. // information.
  73. Int64Gauge(name string, options ...Int64GaugeOption) (Int64Gauge, error)
  74. // Int64ObservableCounter returns a new Int64ObservableCounter identified
  75. // by name and configured with options. The instrument is used to
  76. // asynchronously record increasing int64 measurements once per a
  77. // measurement collection cycle.
  78. //
  79. // Measurements for the returned instrument are made via a callback. Use
  80. // the WithInt64Callback option to register the callback here, or use the
  81. // RegisterCallback method of this Meter to register one later. See the
  82. // Measurements section of the package documentation for more information.
  83. //
  84. // The name needs to conform to the OpenTelemetry instrument name syntax.
  85. // See the Instrument Name section of the package documentation for more
  86. // information.
  87. Int64ObservableCounter(name string, options ...Int64ObservableCounterOption) (Int64ObservableCounter, error)
  88. // Int64ObservableUpDownCounter returns a new Int64ObservableUpDownCounter
  89. // instrument identified by name and configured with options. The
  90. // instrument is used to asynchronously record int64 measurements once per
  91. // a measurement collection cycle.
  92. //
  93. // Measurements for the returned instrument are made via a callback. Use
  94. // the WithInt64Callback option to register the callback here, or use the
  95. // RegisterCallback method of this Meter to register one later. See the
  96. // Measurements section of the package documentation for more information.
  97. //
  98. // The name needs to conform to the OpenTelemetry instrument name syntax.
  99. // See the Instrument Name section of the package documentation for more
  100. // information.
  101. Int64ObservableUpDownCounter(name string, options ...Int64ObservableUpDownCounterOption) (Int64ObservableUpDownCounter, error)
  102. // Int64ObservableGauge returns a new Int64ObservableGauge instrument
  103. // identified by name and configured with options. The instrument is used
  104. // to asynchronously record instantaneous int64 measurements once per a
  105. // measurement collection cycle.
  106. //
  107. // Measurements for the returned instrument are made via a callback. Use
  108. // the WithInt64Callback option to register the callback here, or use the
  109. // RegisterCallback method of this Meter to register one later. See the
  110. // Measurements section of the package documentation for more information.
  111. //
  112. // The name needs to conform to the OpenTelemetry instrument name syntax.
  113. // See the Instrument Name section of the package documentation for more
  114. // information.
  115. Int64ObservableGauge(name string, options ...Int64ObservableGaugeOption) (Int64ObservableGauge, error)
  116. // Float64Counter returns a new Float64Counter instrument identified by
  117. // name and configured with options. The instrument is used to
  118. // synchronously record increasing float64 measurements during a
  119. // computational operation.
  120. //
  121. // The name needs to conform to the OpenTelemetry instrument name syntax.
  122. // See the Instrument Name section of the package documentation for more
  123. // information.
  124. Float64Counter(name string, options ...Float64CounterOption) (Float64Counter, error)
  125. // Float64UpDownCounter returns a new Float64UpDownCounter instrument
  126. // identified by name and configured with options. The instrument is used
  127. // to synchronously record float64 measurements during a computational
  128. // operation.
  129. //
  130. // The name needs to conform to the OpenTelemetry instrument name syntax.
  131. // See the Instrument Name section of the package documentation for more
  132. // information.
  133. Float64UpDownCounter(name string, options ...Float64UpDownCounterOption) (Float64UpDownCounter, error)
  134. // Float64Histogram returns a new Float64Histogram instrument identified by
  135. // name and configured with options. The instrument is used to
  136. // synchronously record the distribution of float64 measurements during a
  137. // computational operation.
  138. //
  139. // The name needs to conform to the OpenTelemetry instrument name syntax.
  140. // See the Instrument Name section of the package documentation for more
  141. // information.
  142. Float64Histogram(name string, options ...Float64HistogramOption) (Float64Histogram, error)
  143. // Float64Gauge returns a new Float64Gauge instrument identified by name and
  144. // configured with options. The instrument is used to synchronously record
  145. // instantaneous float64 measurements during a computational operation.
  146. //
  147. // The name needs to conform to the OpenTelemetry instrument name syntax.
  148. // See the Instrument Name section of the package documentation for more
  149. // information.
  150. Float64Gauge(name string, options ...Float64GaugeOption) (Float64Gauge, error)
  151. // Float64ObservableCounter returns a new Float64ObservableCounter
  152. // instrument identified by name and configured with options. The
  153. // instrument is used to asynchronously record increasing float64
  154. // measurements once per a measurement collection cycle.
  155. //
  156. // Measurements for the returned instrument are made via a callback. Use
  157. // the WithFloat64Callback option to register the callback here, or use the
  158. // RegisterCallback method of this Meter to register one later. See the
  159. // Measurements section of the package documentation for more information.
  160. //
  161. // The name needs to conform to the OpenTelemetry instrument name syntax.
  162. // See the Instrument Name section of the package documentation for more
  163. // information.
  164. Float64ObservableCounter(name string, options ...Float64ObservableCounterOption) (Float64ObservableCounter, error)
  165. // Float64ObservableUpDownCounter returns a new
  166. // Float64ObservableUpDownCounter instrument identified by name and
  167. // configured with options. The instrument is used to asynchronously record
  168. // float64 measurements once per a measurement collection cycle.
  169. //
  170. // Measurements for the returned instrument are made via a callback. Use
  171. // the WithFloat64Callback option to register the callback here, or use the
  172. // RegisterCallback method of this Meter to register one later. See the
  173. // Measurements section of the package documentation for more information.
  174. //
  175. // The name needs to conform to the OpenTelemetry instrument name syntax.
  176. // See the Instrument Name section of the package documentation for more
  177. // information.
  178. Float64ObservableUpDownCounter(name string, options ...Float64ObservableUpDownCounterOption) (Float64ObservableUpDownCounter, error)
  179. // Float64ObservableGauge returns a new Float64ObservableGauge instrument
  180. // identified by name and configured with options. The instrument is used
  181. // to asynchronously record instantaneous float64 measurements once per a
  182. // measurement collection cycle.
  183. //
  184. // Measurements for the returned instrument are made via a callback. Use
  185. // the WithFloat64Callback option to register the callback here, or use the
  186. // RegisterCallback method of this Meter to register one later. See the
  187. // Measurements section of the package documentation for more information.
  188. //
  189. // The name needs to conform to the OpenTelemetry instrument name syntax.
  190. // See the Instrument Name section of the package documentation for more
  191. // information.
  192. Float64ObservableGauge(name string, options ...Float64ObservableGaugeOption) (Float64ObservableGauge, error)
  193. // RegisterCallback registers f to be called during the collection of a
  194. // measurement cycle.
  195. //
  196. // If Unregister of the returned Registration is called, f needs to be
  197. // unregistered and not called during collection.
  198. //
  199. // The instruments f is registered with are the only instruments that f may
  200. // observe values for.
  201. //
  202. // If no instruments are passed, f should not be registered nor called
  203. // during collection.
  204. //
  205. // The function f needs to be concurrent safe.
  206. RegisterCallback(f Callback, instruments ...Observable) (Registration, error)
  207. }
  208. // Callback is a function registered with a Meter that makes observations for
  209. // the set of instruments it is registered with. The Observer parameter is used
  210. // to record measurement observations for these instruments.
  211. //
  212. // The function needs to complete in a finite amount of time and the deadline
  213. // of the passed context is expected to be honored.
  214. //
  215. // The function needs to make unique observations across all registered
  216. // Callbacks. Meaning, it should not report measurements for an instrument with
  217. // the same attributes as another Callback will report.
  218. //
  219. // The function needs to be concurrent safe.
  220. type Callback func(context.Context, Observer) error
  221. // Observer records measurements for multiple instruments in a Callback.
  222. //
  223. // Warning: Methods may be added to this interface in minor releases. See
  224. // package documentation on API implementation for information on how to set
  225. // default behavior for unimplemented methods.
  226. type Observer interface {
  227. // Users of the interface can ignore this. This embedded type is only used
  228. // by implementations of this interface. See the "API Implementations"
  229. // section of the package documentation for more information.
  230. embedded.Observer
  231. // ObserveFloat64 records the float64 value for obsrv.
  232. ObserveFloat64(obsrv Float64Observable, value float64, opts ...ObserveOption)
  233. // ObserveInt64 records the int64 value for obsrv.
  234. ObserveInt64(obsrv Int64Observable, value int64, opts ...ObserveOption)
  235. }
  236. // Registration is an token representing the unique registration of a callback
  237. // for a set of instruments with a Meter.
  238. //
  239. // Warning: Methods may be added to this interface in minor releases. See
  240. // package documentation on API implementation for information on how to set
  241. // default behavior for unimplemented methods.
  242. type Registration interface {
  243. // Users of the interface can ignore this. This embedded type is only used
  244. // by implementations of this interface. See the "API Implementations"
  245. // section of the package documentation for more information.
  246. embedded.Registration
  247. // Unregister removes the callback registration from a Meter.
  248. //
  249. // This method needs to be idempotent and concurrent safe.
  250. Unregister() error
  251. }