...

Source file src/go.opentelemetry.io/otel/metric/syncint64.go

Documentation: go.opentelemetry.io/otel/metric

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

View as plain text