Skip to content

Commit

Permalink
change(metric): metric instruments & instrument provider enhanced wit…
Browse files Browse the repository at this point in the history
…h generics
  • Loading branch information
Woobin Lee authored and Woobin Lee committed Oct 28, 2022
1 parent 3dd4e81 commit edb3716
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 416 deletions.
4 changes: 2 additions & 2 deletions metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric/unit"
)

Expand Down Expand Up @@ -110,4 +109,5 @@ func ExampleMeter_asynchronous_multiple() {
}

// This is just an example, see the the contrib runtime instrumentation for real implementation.
func computeGCPauses(ctx context.Context, recorder syncfloat64.Histogram, pauseBuff []uint64) {}
func computeGCPauses(ctx context.Context, recorder instrument.SyncHistogram[float64], pauseBuff []uint64) {
}
72 changes: 0 additions & 72 deletions metric/instrument/asyncfloat64/asyncfloat64.go

This file was deleted.

72 changes: 0 additions & 72 deletions metric/instrument/asyncint64/asyncint64.go

This file was deleted.

56 changes: 0 additions & 56 deletions metric/instrument/syncfloat64/syncfloat64.go

This file was deleted.

56 changes: 0 additions & 56 deletions metric/instrument/syncint64/syncint64.go

This file was deleted.

79 changes: 79 additions & 0 deletions metric/instrument/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package instrument

import (
"context"

"go.opentelemetry.io/otel/attribute"
)

// SyncInstrumentProvider provides access to synchronous instruments.
type SyncInstrumentProvider[T int64 | float64] interface {
// Counter creates an instrument for recording increasing values.
Counter(name string, opts ...Option) (SyncCounter[T], error)
// UpDownCounter creates an instrument for recording changes of a value.
UpDownCounter(name string, opts ...Option) (SyncUpDownCounter[T], error)
// Histogram creates an instrument for recording a distribution of values.
Histogram(name string, opts ...Option) (SyncHistogram[T], error)
}

// Counter is an instrument that records increasing values.
type SyncCounter[T int64 | float64] interface {
// Add records a change to the counter.
Add(ctx context.Context, incr T, attrs ...attribute.KeyValue)

Synchronous
}

// UpDownCounter is an instrument that records increasing or decreasing values.
type SyncUpDownCounter[T int64 | float64] interface {
// Add records a change to the counter.
Add(ctx context.Context, incr T, attrs ...attribute.KeyValue)

Synchronous
}

// Histogram is an instrument that records a distribution of values.
type SyncHistogram[T int64 | float64] interface {
// Record adds an additional value to the distribution.
Record(ctx context.Context, incr T, attrs ...attribute.KeyValue)

Synchronous
}

// AsyncInstrumentProvider provides access to asynchronous instruments.
type AsyncInstrumentProvider[T int64 | float64] interface {
// Counter creates an instrument for recording increasing values.
Counter(name string, opts ...Option) (AsyncCounter[T], error)
// UpDownCounter creates an instrument for recording changes of a value.
UpDownCounter(name string, opts ...Option) (AsyncUpDownCounter[T], error)
// Histogram creates an instrument for recording a distribution of values.
Gauge(name string, opts ...Option) (AsyncGauge[T], error)
}

// Counter is an instrument that records increasing values.
type AsyncCounter[T int64 | float64] interface {
// Add records a change to the counter.
Observe(ctx context.Context, x T, attrs ...attribute.KeyValue)

Asynchronous
}

// UpDownCounter is an instrument that records increasing or decreasing values.
type AsyncUpDownCounter[T int64 | float64] interface {
// Add records a change to the counter.
Observe(ctx context.Context, x T, attrs ...attribute.KeyValue)

Asynchronous
}

// Gauge is an instrument that records independent readings.
type AsyncGauge[T int64 | float64] interface {
// Observe records the state of the instrument to be x.
//
// It is only valid to call this within a callback. If called outside of the
// registered callback it should have no effect on the instrument, and an
// error will be reported via the error handler.
Observe(ctx context.Context, x T, attrs ...attribute.KeyValue)

Asynchronous
}

0 comments on commit edb3716

Please sign in to comment.