syncint64.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. // Int64Counter is an instrument that records increasing int64 values.
  20. //
  21. // Warning: Methods may be added to this interface in minor releases. See
  22. // package documentation on API implementation for information on how to set
  23. // default behavior for unimplemented methods.
  24. type Int64Counter interface {
  25. // Users of the interface can ignore this. This embedded type is only used
  26. // by implementations of this interface. See the "API Implementations"
  27. // section of the package documentation for more information.
  28. embedded.Int64Counter
  29. // Add records a change to the counter.
  30. //
  31. // Use the WithAttributeSet (or, if performance is not a concern,
  32. // the WithAttributes) option to include measurement attributes.
  33. Add(ctx context.Context, incr int64, options ...AddOption)
  34. }
  35. // Int64CounterConfig contains options for synchronous counter instruments that
  36. // record int64 values.
  37. type Int64CounterConfig struct {
  38. description string
  39. unit string
  40. }
  41. // NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts
  42. // applied.
  43. func NewInt64CounterConfig(opts ...Int64CounterOption) Int64CounterConfig {
  44. var config Int64CounterConfig
  45. for _, o := range opts {
  46. config = o.applyInt64Counter(config)
  47. }
  48. return config
  49. }
  50. // Description returns the configured description.
  51. func (c Int64CounterConfig) Description() string {
  52. return c.description
  53. }
  54. // Unit returns the configured unit.
  55. func (c Int64CounterConfig) Unit() string {
  56. return c.unit
  57. }
  58. // Int64CounterOption applies options to a [Int64CounterConfig]. See
  59. // [InstrumentOption] for other options that can be used as an
  60. // Int64CounterOption.
  61. type Int64CounterOption interface {
  62. applyInt64Counter(Int64CounterConfig) Int64CounterConfig
  63. }
  64. // Int64UpDownCounter is an instrument that records increasing or decreasing
  65. // int64 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 Int64UpDownCounter 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.Int64UpDownCounter
  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. Add(ctx context.Context, incr int64, options ...AddOption)
  80. }
  81. // Int64UpDownCounterConfig contains options for synchronous counter
  82. // instruments that record int64 values.
  83. type Int64UpDownCounterConfig struct {
  84. description string
  85. unit string
  86. }
  87. // NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with
  88. // all opts applied.
  89. func NewInt64UpDownCounterConfig(opts ...Int64UpDownCounterOption) Int64UpDownCounterConfig {
  90. var config Int64UpDownCounterConfig
  91. for _, o := range opts {
  92. config = o.applyInt64UpDownCounter(config)
  93. }
  94. return config
  95. }
  96. // Description returns the configured description.
  97. func (c Int64UpDownCounterConfig) Description() string {
  98. return c.description
  99. }
  100. // Unit returns the configured unit.
  101. func (c Int64UpDownCounterConfig) Unit() string {
  102. return c.unit
  103. }
  104. // Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig].
  105. // See [InstrumentOption] for other options that can be used as an
  106. // Int64UpDownCounterOption.
  107. type Int64UpDownCounterOption interface {
  108. applyInt64UpDownCounter(Int64UpDownCounterConfig) Int64UpDownCounterConfig
  109. }
  110. // Int64Histogram is an instrument that records a distribution of int64
  111. // values.
  112. //
  113. // Warning: Methods may be added to this interface in minor releases. See
  114. // package documentation on API implementation for information on how to set
  115. // default behavior for unimplemented methods.
  116. type Int64Histogram interface {
  117. // Users of the interface can ignore this. This embedded type is only used
  118. // by implementations of this interface. See the "API Implementations"
  119. // section of the package documentation for more information.
  120. embedded.Int64Histogram
  121. // Record adds an additional value to the distribution.
  122. //
  123. // Use the WithAttributeSet (or, if performance is not a concern,
  124. // the WithAttributes) option to include measurement attributes.
  125. Record(ctx context.Context, incr int64, options ...RecordOption)
  126. }
  127. // Int64HistogramConfig contains options for synchronous counter instruments
  128. // that record int64 values.
  129. type Int64HistogramConfig struct {
  130. description string
  131. unit string
  132. }
  133. // NewInt64HistogramConfig returns a new [Int64HistogramConfig] with all opts
  134. // applied.
  135. func NewInt64HistogramConfig(opts ...Int64HistogramOption) Int64HistogramConfig {
  136. var config Int64HistogramConfig
  137. for _, o := range opts {
  138. config = o.applyInt64Histogram(config)
  139. }
  140. return config
  141. }
  142. // Description returns the configured description.
  143. func (c Int64HistogramConfig) Description() string {
  144. return c.description
  145. }
  146. // Unit returns the configured unit.
  147. func (c Int64HistogramConfig) Unit() string {
  148. return c.unit
  149. }
  150. // Int64HistogramOption applies options to a [Int64HistogramConfig]. See
  151. // [InstrumentOption] for other options that can be used as an
  152. // Int64HistogramOption.
  153. type Int64HistogramOption interface {
  154. applyInt64Histogram(Int64HistogramConfig) Int64HistogramConfig
  155. }