meter.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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(
  102. name string,
  103. options ...Int64ObservableUpDownCounterOption,
  104. ) (Int64ObservableUpDownCounter, error)
  105. // Int64ObservableGauge returns a new Int64ObservableGauge instrument
  106. // identified by name and configured with options. The instrument is used
  107. // to asynchronously record instantaneous int64 measurements once per a
  108. // measurement collection cycle.
  109. //
  110. // Measurements for the returned instrument are made via a callback. Use
  111. // the WithInt64Callback option to register the callback here, or use the
  112. // RegisterCallback method of this Meter to register one later. See the
  113. // Measurements section of the package documentation for more information.
  114. //
  115. // The name needs to conform to the OpenTelemetry instrument name syntax.
  116. // See the Instrument Name section of the package documentation for more
  117. // information.
  118. Int64ObservableGauge(name string, options ...Int64ObservableGaugeOption) (Int64ObservableGauge, error)
  119. // Float64Counter returns a new Float64Counter instrument identified by
  120. // name and configured with options. The instrument is used to
  121. // synchronously record increasing float64 measurements during a
  122. // computational operation.
  123. //
  124. // The name needs to conform to the OpenTelemetry instrument name syntax.
  125. // See the Instrument Name section of the package documentation for more
  126. // information.
  127. Float64Counter(name string, options ...Float64CounterOption) (Float64Counter, error)
  128. // Float64UpDownCounter returns a new Float64UpDownCounter instrument
  129. // identified by name and configured with options. The instrument is used
  130. // to synchronously record float64 measurements during a computational
  131. // operation.
  132. //
  133. // The name needs to conform to the OpenTelemetry instrument name syntax.
  134. // See the Instrument Name section of the package documentation for more
  135. // information.
  136. Float64UpDownCounter(name string, options ...Float64UpDownCounterOption) (Float64UpDownCounter, error)
  137. // Float64Histogram returns a new Float64Histogram instrument identified by
  138. // name and configured with options. The instrument is used to
  139. // synchronously record the distribution of float64 measurements during a
  140. // computational operation.
  141. //
  142. // The name needs to conform to the OpenTelemetry instrument name syntax.
  143. // See the Instrument Name section of the package documentation for more
  144. // information.
  145. Float64Histogram(name string, options ...Float64HistogramOption) (Float64Histogram, error)
  146. // Float64Gauge returns a new Float64Gauge instrument identified by name and
  147. // configured with options. The instrument is used to synchronously record
  148. // instantaneous float64 measurements during a computational operation.
  149. //
  150. // The name needs to conform to the OpenTelemetry instrument name syntax.
  151. // See the Instrument Name section of the package documentation for more
  152. // information.
  153. Float64Gauge(name string, options ...Float64GaugeOption) (Float64Gauge, error)
  154. // Float64ObservableCounter returns a new Float64ObservableCounter
  155. // instrument identified by name and configured with options. The
  156. // instrument is used to asynchronously record increasing float64
  157. // measurements once per a measurement collection cycle.
  158. //
  159. // Measurements for the returned instrument are made via a callback. Use
  160. // the WithFloat64Callback option to register the callback here, or use the
  161. // RegisterCallback method of this Meter to register one later. See the
  162. // Measurements section of the package documentation for more information.
  163. //
  164. // The name needs to conform to the OpenTelemetry instrument name syntax.
  165. // See the Instrument Name section of the package documentation for more
  166. // information.
  167. Float64ObservableCounter(name string, options ...Float64ObservableCounterOption) (Float64ObservableCounter, error)
  168. // Float64ObservableUpDownCounter returns a new
  169. // Float64ObservableUpDownCounter instrument identified by name and
  170. // configured with options. The instrument is used to asynchronously record
  171. // float64 measurements once per a measurement collection cycle.
  172. //
  173. // Measurements for the returned instrument are made via a callback. Use
  174. // the WithFloat64Callback option to register the callback here, or use the
  175. // RegisterCallback method of this Meter to register one later. See the
  176. // Measurements section of the package documentation for more information.
  177. //
  178. // The name needs to conform to the OpenTelemetry instrument name syntax.
  179. // See the Instrument Name section of the package documentation for more
  180. // information.
  181. Float64ObservableUpDownCounter(
  182. name string,
  183. options ...Float64ObservableUpDownCounterOption,
  184. ) (Float64ObservableUpDownCounter, error)
  185. // Float64ObservableGauge returns a new Float64ObservableGauge instrument
  186. // identified by name and configured with options. The instrument is used
  187. // to asynchronously record instantaneous float64 measurements once per a
  188. // measurement collection cycle.
  189. //
  190. // Measurements for the returned instrument are made via a callback. Use
  191. // the WithFloat64Callback option to register the callback here, or use the
  192. // RegisterCallback method of this Meter to register one later. See the
  193. // Measurements section of the package documentation for more information.
  194. //
  195. // The name needs to conform to the OpenTelemetry instrument name syntax.
  196. // See the Instrument Name section of the package documentation for more
  197. // information.
  198. Float64ObservableGauge(name string, options ...Float64ObservableGaugeOption) (Float64ObservableGauge, error)
  199. // RegisterCallback registers f to be called during the collection of a
  200. // measurement cycle.
  201. //
  202. // If Unregister of the returned Registration is called, f needs to be
  203. // unregistered and not called during collection.
  204. //
  205. // The instruments f is registered with are the only instruments that f may
  206. // observe values for.
  207. //
  208. // If no instruments are passed, f should not be registered nor called
  209. // during collection.
  210. //
  211. // The function f needs to be concurrent safe.
  212. RegisterCallback(f Callback, instruments ...Observable) (Registration, error)
  213. }
  214. // Callback is a function registered with a Meter that makes observations for
  215. // the set of instruments it is registered with. The Observer parameter is used
  216. // to record measurement observations for these instruments.
  217. //
  218. // The function needs to complete in a finite amount of time and the deadline
  219. // of the passed context is expected to be honored.
  220. //
  221. // The function needs to make unique observations across all registered
  222. // Callbacks. Meaning, it should not report measurements for an instrument with
  223. // the same attributes as another Callback will report.
  224. //
  225. // The function needs to be concurrent safe.
  226. type Callback func(context.Context, Observer) error
  227. // Observer records measurements for multiple instruments in a Callback.
  228. //
  229. // Warning: Methods may be added to this interface in minor releases. See
  230. // package documentation on API implementation for information on how to set
  231. // default behavior for unimplemented methods.
  232. type Observer interface {
  233. // Users of the interface can ignore this. This embedded type is only used
  234. // by implementations of this interface. See the "API Implementations"
  235. // section of the package documentation for more information.
  236. embedded.Observer
  237. // ObserveFloat64 records the float64 value for obsrv.
  238. ObserveFloat64(obsrv Float64Observable, value float64, opts ...ObserveOption)
  239. // ObserveInt64 records the int64 value for obsrv.
  240. ObserveInt64(obsrv Int64Observable, value int64, opts ...ObserveOption)
  241. }
  242. // Registration is an token representing the unique registration of a callback
  243. // for a set of instruments with a Meter.
  244. //
  245. // Warning: Methods may be added to this interface in minor releases. See
  246. // package documentation on API implementation for information on how to set
  247. // default behavior for unimplemented methods.
  248. type Registration interface {
  249. // Users of the interface can ignore this. This embedded type is only used
  250. // by implementations of this interface. See the "API Implementations"
  251. // section of the package documentation for more information.
  252. embedded.Registration
  253. // Unregister removes the callback registration from a Meter.
  254. //
  255. // This method needs to be idempotent and concurrent safe.
  256. Unregister() error
  257. }