Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
This matches the returned type and fixes misuse of the term metric. (#1240)
- Move test harness from the `go.opentelemetry.io/otel/api/apitest` package into `go.opentelemetry.io/otel/oteltest`. (#1241)
- Rename `MergeItererator` to `MergeIterator` in the `go.opentelemetry.io/otel/label` package. (#1244)
- Move the `go.opentelemetry.io/otel/api/metric` and `go.opentelemetry.io/otel/api/metric/metrictest` packages into `go.opentelemetry.io/otel` as part of #964. (#1252)
- Move the `go.opentelemetry.io/otel/api/metric/metrictest` package into `go.opentelemetry.io/oteltest` as part of #964. (#1252)
- Move the `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric` as part of #1303. (#1321)
- Move the `go.opentelemetry.io/otel/api/metric/registry` package into `go.opentelemetry.io/otel/metric/registry as a part of #1303. (#1316)
- Move the `Number` type (together with related functions) from `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric/number` as a part of #1303. (#1316)
- The function signature of the Span `AddEvent` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required name and a variable number of `EventOption`s. (#1254)
Expand Down
9 changes: 5 additions & 4 deletions example/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/otel/exporters/stdout"
"go.opentelemetry.io/otel/global"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagators"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
Expand Down Expand Up @@ -68,14 +69,14 @@ func main() {

commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}

oneMetricCB := func(_ context.Context, result otel.Float64ObserverResult) {
oneMetricCB := func(_ context.Context, result metric.Float64ObserverResult) {
result.Observe(1, commonLabels...)
}
_ = otel.Must(meter).NewFloat64ValueObserver("ex.com.one", oneMetricCB,
otel.WithDescription("A ValueObserver set to 1.0"),
_ = metric.Must(meter).NewFloat64ValueObserver("ex.com.one", oneMetricCB,
metric.WithDescription("A ValueObserver set to 1.0"),
)

valuerecorderTwo := otel.Must(meter).NewFloat64ValueRecorder("ex.com.two")
valuerecorderTwo := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")

ctx := context.Background()
ctx = otel.ContextWithBaggageValues(ctx, fooKey.String("foo1"), barKey.String("bar1"))
Expand Down
6 changes: 3 additions & 3 deletions example/otel-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (

"google.golang.org/grpc"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/global"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagators"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/processor/basic"
Expand Down Expand Up @@ -111,10 +111,10 @@ func main() {
}

// Recorder metric example
valuerecorder := otel.Must(meter).
valuerecorder := metric.Must(meter).
NewFloat64Counter(
"an_important_metric",
otel.WithDescription("Measures the cumulative epicness of the app"),
metric.WithDescription("Measures the cumulative epicness of the app"),
).Bind(commonLabels...)
defer valuerecorder.Unbind()

Expand Down
12 changes: 6 additions & 6 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"sync"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/global"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
)

var (
Expand All @@ -52,19 +52,19 @@ func main() {
observerLock := new(sync.RWMutex)
observerValueToReport := new(float64)
observerLabelsToReport := new([]label.KeyValue)
cb := func(_ context.Context, result otel.Float64ObserverResult) {
cb := func(_ context.Context, result metric.Float64ObserverResult) {
(*observerLock).RLock()
value := *observerValueToReport
labels := *observerLabelsToReport
(*observerLock).RUnlock()
result.Observe(value, labels...)
}
_ = otel.Must(meter).NewFloat64ValueObserver("ex.com.one", cb,
otel.WithDescription("A ValueObserver set to 1.0"),
_ = metric.Must(meter).NewFloat64ValueObserver("ex.com.one", cb,
metric.WithDescription("A ValueObserver set to 1.0"),
)

valuerecorder := otel.Must(meter).NewFloat64ValueRecorder("ex.com.two")
counter := otel.Must(meter).NewFloat64Counter("ex.com.three")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("ex.com.two")
counter := metric.Must(meter).NewFloat64Counter("ex.com.three")

commonLabels := []label.KeyValue{lemonsKey.Int(10), label.String("A", "1"), label.String("B", "2"), label.String("C", "3")}
notSoCommonLabels := []label.KeyValue{lemonsKey.Int(13)}
Expand Down
10 changes: 5 additions & 5 deletions exporters/metric/prometheus/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"net/http"
"net/http/httptest"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
"go.opentelemetry.io/otel/sdk/resource"
)
Expand Down Expand Up @@ -59,13 +59,13 @@ func ExampleNewExportPipeline() {
ctx := context.Background()

// Use two instruments
counter := otel.Must(meter).NewInt64Counter(
counter := metric.Must(meter).NewInt64Counter(
"a.counter",
otel.WithDescription("Counts things"),
metric.WithDescription("Counts things"),
)
recorder := otel.Must(meter).NewInt64ValueRecorder(
recorder := metric.Must(meter).NewInt64ValueRecorder(
"a.valuerecorder",
otel.WithDescription("Records values"),
metric.WithDescription("Records values"),
)

counter.Add(ctx, 100, label.String("key", "value"))
Expand Down
6 changes: 3 additions & 3 deletions exporters/metric/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/global"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
Expand Down Expand Up @@ -156,7 +156,7 @@ func (e *Exporter) SetController(config Config, options ...pull.Option) {
}

// MeterProvider returns the MeterProvider of this exporter.
func (e *Exporter) MeterProvider() otel.MeterProvider {
func (e *Exporter) MeterProvider() metric.MeterProvider {
return e.controller.MeterProvider()
}

Expand All @@ -167,7 +167,7 @@ func (e *Exporter) Controller() *pull.Controller {
return e.controller
}

func (e *Exporter) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) export.ExportKind {
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) export.ExportKind {
// NOTE: Summary values should use Delta aggregation, then be
// combined into a sliding window, see the TODO below.
// NOTE: Prometheus also supports a "GaugeDelta" exposition format,
Expand Down
14 changes: 7 additions & 7 deletions exporters/metric/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/metric/prometheus"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric/controller/pull"
"go.opentelemetry.io/otel/sdk/resource"
)
Expand All @@ -48,9 +48,9 @@ func TestPrometheusExporter(t *testing.T) {
require.NoError(t, err)

meter := exporter.MeterProvider().Meter("test")
upDownCounter := otel.Must(meter).NewFloat64UpDownCounter("updowncounter")
counter := otel.Must(meter).NewFloat64Counter("counter")
valuerecorder := otel.Must(meter).NewFloat64ValueRecorder("valuerecorder")
upDownCounter := metric.Must(meter).NewFloat64UpDownCounter("updowncounter")
counter := metric.Must(meter).NewFloat64Counter("counter")
valuerecorder := metric.Must(meter).NewFloat64ValueRecorder("valuerecorder")

labels := []label.KeyValue{
label.Key("A").String("B"),
Expand All @@ -65,7 +65,7 @@ func TestPrometheusExporter(t *testing.T) {

expected = append(expected, `counter{A="B",C="D",R="V"} 15.3`)

_ = otel.Must(meter).NewInt64ValueObserver("intobserver", func(_ context.Context, result otel.Int64ObserverResult) {
_ = metric.Must(meter).NewInt64ValueObserver("intobserver", func(_ context.Context, result metric.Int64ObserverResult) {
result.Observe(1, labels...)
})

Expand Down Expand Up @@ -138,9 +138,9 @@ func TestPrometheusStatefulness(t *testing.T) {

ctx := context.Background()

counter := otel.Must(meter).NewInt64Counter(
counter := metric.Must(meter).NewInt64Counter(
"a.counter",
otel.WithDescription("Counts things"),
metric.WithDescription("Counts things"),
)

counter.Add(ctx, 100, label.String("key", "value"))
Expand Down
33 changes: 16 additions & 17 deletions exporters/otlp/internal/transform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import (

commonpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/common/v1"
metricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/metrics/v1"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/number"
export "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
Expand Down Expand Up @@ -102,17 +101,17 @@ func TestStringKeyValues(t *testing.T) {
}

func TestMinMaxSumCountValue(t *testing.T) {
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &otel.Descriptor{}))
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &metric.Descriptor{}))

assert.NoError(t, mmsc.Update(context.Background(), 1, &otel.Descriptor{}))
assert.NoError(t, mmsc.Update(context.Background(), 10, &otel.Descriptor{}))
assert.NoError(t, mmsc.Update(context.Background(), 1, &metric.Descriptor{}))
assert.NoError(t, mmsc.Update(context.Background(), 10, &metric.Descriptor{}))

// Prior to checkpointing ErrNoData should be returned.
_, _, _, _, err := minMaxSumCountValues(ckpt.(aggregation.MinMaxSumCount))
assert.EqualError(t, err, aggregation.ErrNoData.Error())

// Checkpoint to set non-zero values
require.NoError(t, mmsc.SynchronizedMove(ckpt, &otel.Descriptor{}))
require.NoError(t, mmsc.SynchronizedMove(ckpt, &metric.Descriptor{}))
min, max, sum, count, err := minMaxSumCountValues(ckpt.(aggregation.MinMaxSumCount))
if assert.NoError(t, err) {
assert.Equal(t, min, number.NewInt64Number(1))
Expand All @@ -123,7 +122,7 @@ func TestMinMaxSumCountValue(t *testing.T) {
}

func TestMinMaxSumCountDatapoints(t *testing.T) {
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet()
mmsc, ckpt := metrictest.Unslice2(minmaxsumcount.New(2, &desc))

Expand Down Expand Up @@ -155,14 +154,14 @@ func TestMinMaxSumCountPropagatesErrors(t *testing.T) {
// ErrNoData should be returned by both the Min and Max values of
// a MinMaxSumCount Aggregator. Use this fact to check the error is
// correctly returned.
mmsc := &minmaxsumcount.New(1, &otel.Descriptor{})[0]
mmsc := &minmaxsumcount.New(1, &metric.Descriptor{})[0]
_, _, _, _, err := minMaxSumCountValues(mmsc)
assert.Error(t, err)
assert.Equal(t, aggregation.ErrNoData, err)
}

func TestSumIntDataPoints(t *testing.T) {
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet()
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.Number(1), &desc))
Expand Down Expand Up @@ -190,7 +189,7 @@ func TestSumIntDataPoints(t *testing.T) {
}

func TestSumFloatDataPoints(t *testing.T) {
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Float64Kind)
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Float64Kind)
labels := label.NewSet()
s, ckpt := metrictest.Unslice2(sumAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.NewFloat64Number(1), &desc))
Expand Down Expand Up @@ -219,7 +218,7 @@ func TestSumFloatDataPoints(t *testing.T) {
}

func TestLastValueIntDataPoints(t *testing.T) {
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Int64Kind)
labels := label.NewSet()
s, ckpt := metrictest.Unslice2(lvAgg.New(2))
assert.NoError(t, s.Update(context.Background(), number.Number(100), &desc))
Expand All @@ -245,7 +244,7 @@ func TestLastValueIntDataPoints(t *testing.T) {
}

func TestSumErrUnknownValueType(t *testing.T) {
desc := otel.NewDescriptor("", otel.ValueRecorderInstrumentKind, number.Kind(-1))
desc := metric.NewDescriptor("", metric.ValueRecorderInstrumentKind, number.Kind(-1))
labels := label.NewSet()
s := &sumAgg.New(1)[0]
record := export.NewRecord(&desc, &labels, nil, s, intervalStart, intervalEnd)
Expand Down Expand Up @@ -274,13 +273,13 @@ func (t *testAgg) Aggregation() aggregation.Aggregation {

// None of these three are used:

func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *otel.Descriptor) error {
func (t *testAgg) Update(ctx context.Context, number number.Number, descriptor *metric.Descriptor) error {
return nil
}
func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *otel.Descriptor) error {
func (t *testAgg) SynchronizedMove(destination export.Aggregator, descriptor *metric.Descriptor) error {
return nil
}
func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *otel.Descriptor) error {
func (t *testAgg) Merge(aggregator export.Aggregator, descriptor *metric.Descriptor) error {
return nil
}

Expand Down Expand Up @@ -330,7 +329,7 @@ var _ aggregation.MinMaxSumCount = &testErrMinMaxSumCount{}

func TestRecordAggregatorIncompatibleErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := otel.NewDescriptor("things", otel.CounterInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
labels := label.NewSet()
res := resource.Empty()
test := &testAgg{
Expand Down Expand Up @@ -367,7 +366,7 @@ func TestRecordAggregatorIncompatibleErrors(t *testing.T) {

func TestRecordAggregatorUnexpectedErrors(t *testing.T) {
makeMpb := func(kind aggregation.Kind, agg aggregation.Aggregation) (*metricpb.Metric, error) {
desc := otel.NewDescriptor("things", otel.CounterInstrumentKind, number.Int64Kind)
desc := metric.NewDescriptor("things", metric.CounterInstrumentKind, number.Int64Kind)
labels := label.NewSet()
res := resource.Empty()
return Record(export.CumulativeExportKindSelector(), export.NewRecord(&desc, &labels, res, agg, intervalStart, intervalEnd))
Expand Down
5 changes: 2 additions & 3 deletions exporters/otlp/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"

"go.opentelemetry.io/otel"
colmetricpb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/collector/metrics/v1"
coltracepb "go.opentelemetry.io/otel/exporters/otlp/internal/opentelemetry-proto-gen/collector/trace/v1"

"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
"go.opentelemetry.io/otel/metric"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
tracesdk "go.opentelemetry.io/otel/sdk/export/trace"
Expand Down Expand Up @@ -289,7 +288,7 @@ func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) e

// ExportKindFor reports back to the OpenTelemetry SDK sending this Exporter
// metric telemetry that it needs to be provided in a cumulative format.
func (e *Exporter) ExportKindFor(desc *otel.Descriptor, kind aggregation.Kind) metricsdk.ExportKind {
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) metricsdk.ExportKind {
return e.c.exportKindSelector.ExportKindFor(desc, kind)
}

Expand Down
Loading