2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-12-24 09:03:04 +02:00
|
|
|
package internal_test
|
|
|
|
|
|
|
|
import (
|
2020-04-30 01:13:55 +02:00
|
|
|
"bytes"
|
2019-12-24 09:03:04 +02:00
|
|
|
"context"
|
2020-03-11 20:57:57 +02:00
|
|
|
"errors"
|
2019-12-24 09:03:04 +02:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2020-05-14 01:06:03 +02:00
|
|
|
"go.opentelemetry.io/otel/api/kv/value"
|
|
|
|
|
2019-12-24 09:03:04 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/api/global"
|
|
|
|
"go.opentelemetry.io/otel/api/global/internal"
|
2020-05-14 01:06:03 +02:00
|
|
|
"go.opentelemetry.io/otel/api/kv"
|
2020-03-05 22:15:30 +02:00
|
|
|
"go.opentelemetry.io/otel/api/metric"
|
2020-03-02 23:54:57 +02:00
|
|
|
"go.opentelemetry.io/otel/exporters/metric/stdout"
|
2019-12-24 09:03:04 +02:00
|
|
|
metrictest "go.opentelemetry.io/otel/internal/metric"
|
|
|
|
)
|
|
|
|
|
2020-03-24 19:54:08 +02:00
|
|
|
// Note: Maybe this should be factored into ../../../internal/metric?
|
|
|
|
type measured struct {
|
|
|
|
Name string
|
|
|
|
LibraryName string
|
2020-05-14 01:06:03 +02:00
|
|
|
Labels map[kv.Key]value.Value
|
2020-05-11 08:44:42 +02:00
|
|
|
Number metric.Number
|
2020-03-24 19:54:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func asStructs(batches []metrictest.Batch) []measured {
|
|
|
|
var r []measured
|
|
|
|
for _, batch := range batches {
|
|
|
|
for _, m := range batch.Measurements {
|
|
|
|
r = append(r, measured{
|
|
|
|
Name: m.Instrument.Descriptor().Name(),
|
|
|
|
LibraryName: m.Instrument.Descriptor().LibraryName(),
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(batch.Labels...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: m.Number,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2020-05-14 01:06:03 +02:00
|
|
|
func asMap(kvs ...kv.KeyValue) map[kv.Key]value.Value {
|
|
|
|
m := map[kv.Key]value.Value{}
|
2020-03-24 19:54:08 +02:00
|
|
|
for _, kv := range kvs {
|
|
|
|
m[kv.Key] = kv.Value
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
var asInt = metric.NewInt64Number
|
|
|
|
var asFloat = metric.NewFloat64Number
|
2020-03-24 19:54:08 +02:00
|
|
|
|
2019-12-24 09:03:04 +02:00
|
|
|
func TestDirect(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-03-11 17:23:32 +02:00
|
|
|
meter1 := global.Meter("test1")
|
|
|
|
meter2 := global.Meter("test2")
|
2020-05-14 01:06:03 +02:00
|
|
|
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
|
|
|
labels2 := []kv.KeyValue{kv.String("C", "D")}
|
|
|
|
labels3 := []kv.KeyValue{kv.String("E", "F")}
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := Must(meter1).NewInt64Counter("test.counter")
|
2020-03-27 23:06:48 +02:00
|
|
|
counter.Add(ctx, 1, labels1...)
|
|
|
|
counter.Add(ctx, 1, labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
valuerecorder := Must(meter1).NewFloat64ValueRecorder("test.valuerecorder")
|
|
|
|
valuerecorder.Record(ctx, 1, labels1...)
|
|
|
|
valuerecorder.Record(ctx, 2, labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-05-20 06:33:10 +02:00
|
|
|
_ = Must(meter1).RegisterFloat64ValueObserver("test.valueobserver.float", func(_ context.Context, result metric.Float64ObserverResult) {
|
2020-03-27 23:06:48 +02:00
|
|
|
result.Observe(1., labels1...)
|
|
|
|
result.Observe(2., labels2...)
|
2020-03-05 22:15:30 +02:00
|
|
|
})
|
|
|
|
|
2020-05-20 06:33:10 +02:00
|
|
|
_ = Must(meter1).RegisterInt64ValueObserver("test.valueobserver.int", func(_ context.Context, result metric.Int64ObserverResult) {
|
2020-03-27 23:06:48 +02:00
|
|
|
result.Observe(1, labels1...)
|
|
|
|
result.Observe(2, labels2...)
|
2020-03-05 22:15:30 +02:00
|
|
|
})
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
second := Must(meter2).NewFloat64ValueRecorder("test.second")
|
2020-03-27 23:06:48 +02:00
|
|
|
second.Record(ctx, 1, labels3...)
|
|
|
|
second.Record(ctx, 2, labels3...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-24 19:54:08 +02:00
|
|
|
mock, provider := metrictest.NewProvider()
|
|
|
|
global.SetMeterProvider(provider)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-27 23:06:48 +02:00
|
|
|
counter.Add(ctx, 1, labels1...)
|
2020-05-16 07:11:12 +02:00
|
|
|
valuerecorder.Record(ctx, 3, labels1...)
|
2020-03-27 23:06:48 +02:00
|
|
|
second.Record(ctx, 3, labels3...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-19 21:02:46 +02:00
|
|
|
mock.RunAsyncInstruments()
|
2020-03-24 19:54:08 +02:00
|
|
|
|
|
|
|
measurements := asStructs(mock.MeasurementBatches)
|
|
|
|
|
|
|
|
require.EqualValues(t,
|
|
|
|
[]measured{
|
|
|
|
{
|
|
|
|
Name: "test.counter",
|
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asInt(1),
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 07:11:12 +02:00
|
|
|
Name: "test.valuerecorder",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asFloat(3),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "test.second",
|
|
|
|
LibraryName: "test2",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels3...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asFloat(3),
|
|
|
|
},
|
|
|
|
{
|
2020-05-18 20:03:43 +02:00
|
|
|
Name: "test.valueobserver.float",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asFloat(1),
|
|
|
|
},
|
|
|
|
{
|
2020-05-18 20:03:43 +02:00
|
|
|
Name: "test.valueobserver.float",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels2...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asFloat(2),
|
|
|
|
},
|
|
|
|
{
|
2020-05-18 20:03:43 +02:00
|
|
|
Name: "test.valueobserver.int",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asInt(1),
|
|
|
|
},
|
|
|
|
{
|
2020-05-18 20:03:43 +02:00
|
|
|
Name: "test.valueobserver.int",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test1",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels2...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asInt(2),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
measurements,
|
|
|
|
)
|
2019-12-24 09:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBound(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
2020-03-03 00:50:53 +02:00
|
|
|
// Note: this test uses opposite Float64/Int64 number kinds
|
2019-12-24 09:03:04 +02:00
|
|
|
// vs. the above, to cover all the instruments.
|
|
|
|
ctx := context.Background()
|
2020-03-11 17:23:32 +02:00
|
|
|
glob := global.Meter("test")
|
2020-05-14 01:06:03 +02:00
|
|
|
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := Must(glob).NewFloat64Counter("test.counter")
|
2020-03-27 23:06:48 +02:00
|
|
|
boundC := counter.Bind(labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
boundC.Add(ctx, 1)
|
|
|
|
boundC.Add(ctx, 1)
|
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
valuerecorder := Must(glob).NewInt64ValueRecorder("test.valuerecorder")
|
|
|
|
boundM := valuerecorder.Bind(labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
boundM.Record(ctx, 1)
|
|
|
|
boundM.Record(ctx, 2)
|
|
|
|
|
2020-03-24 19:54:08 +02:00
|
|
|
mock, provider := metrictest.NewProvider()
|
|
|
|
global.SetMeterProvider(provider)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
|
|
|
boundC.Add(ctx, 1)
|
|
|
|
boundM.Record(ctx, 3)
|
|
|
|
|
2020-03-24 19:54:08 +02:00
|
|
|
require.EqualValues(t,
|
|
|
|
[]measured{
|
|
|
|
{
|
|
|
|
Name: "test.counter",
|
|
|
|
LibraryName: "test",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asFloat(1),
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 07:11:12 +02:00
|
|
|
Name: "test.valuerecorder",
|
2020-03-24 19:54:08 +02:00
|
|
|
LibraryName: "test",
|
2020-03-27 23:06:48 +02:00
|
|
|
Labels: asMap(labels1...),
|
2020-03-24 19:54:08 +02:00
|
|
|
Number: asInt(3),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
asStructs(mock.MeasurementBatches))
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
boundC.Unbind()
|
|
|
|
boundM.Unbind()
|
2019-12-24 09:03:04 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
func TestUnbind(t *testing.T) {
|
|
|
|
// Tests Unbind with SDK never installed.
|
2019-12-24 09:03:04 +02:00
|
|
|
internal.ResetForTest()
|
|
|
|
|
2020-03-11 17:23:32 +02:00
|
|
|
glob := global.Meter("test")
|
2020-05-14 01:06:03 +02:00
|
|
|
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := Must(glob).NewFloat64Counter("test.counter")
|
2020-03-27 23:06:48 +02:00
|
|
|
boundC := counter.Bind(labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-05-16 07:11:12 +02:00
|
|
|
valuerecorder := Must(glob).NewInt64ValueRecorder("test.valuerecorder")
|
|
|
|
boundM := valuerecorder.Bind(labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2019-12-28 02:30:19 +02:00
|
|
|
boundC.Unbind()
|
|
|
|
boundM.Unbind()
|
2019-12-24 09:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSDK(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-03-11 17:23:32 +02:00
|
|
|
meter1 := global.Meter("builtin")
|
2020-05-14 01:06:03 +02:00
|
|
|
labels1 := []kv.KeyValue{kv.String("A", "B")}
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := Must(meter1).NewInt64Counter("test.builtin")
|
2020-03-27 23:06:48 +02:00
|
|
|
counter.Add(ctx, 1, labels1...)
|
|
|
|
counter.Add(ctx, 1, labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
|
|
|
in, out := io.Pipe()
|
2020-01-03 19:48:45 +02:00
|
|
|
pusher, err := stdout.InstallNewPipeline(stdout.Config{
|
2020-01-02 18:40:37 +02:00
|
|
|
Writer: out,
|
2019-12-24 09:03:04 +02:00
|
|
|
DoNotPrintTime: true,
|
|
|
|
})
|
2020-01-02 20:41:21 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-12-24 09:03:04 +02:00
|
|
|
|
2020-03-27 23:06:48 +02:00
|
|
|
counter.Add(ctx, 1, labels1...)
|
2019-12-24 09:03:04 +02:00
|
|
|
|
|
|
|
ch := make(chan string)
|
|
|
|
go func() {
|
|
|
|
data, _ := ioutil.ReadAll(in)
|
|
|
|
ch <- string(data)
|
|
|
|
}()
|
|
|
|
|
2020-01-02 20:41:21 +02:00
|
|
|
pusher.Stop()
|
2019-12-24 09:03:04 +02:00
|
|
|
out.Close()
|
|
|
|
|
2020-01-24 15:51:58 +02:00
|
|
|
require.Equal(t, `{"updates":[{"name":"test.builtin{A=B}","sum":1}]}
|
2019-12-24 09:03:04 +02:00
|
|
|
`, <-ch)
|
|
|
|
}
|
2020-02-20 23:05:19 +02:00
|
|
|
|
|
|
|
func TestUnbindThenRecordOne(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2020-03-24 19:54:08 +02:00
|
|
|
mock, provider := metrictest.NewProvider()
|
2020-03-11 20:57:57 +02:00
|
|
|
|
2020-03-11 17:23:32 +02:00
|
|
|
meter := global.Meter("test")
|
2020-03-11 20:57:57 +02:00
|
|
|
counter := Must(meter).NewInt64Counter("test.counter")
|
2020-03-27 23:06:48 +02:00
|
|
|
boundC := counter.Bind()
|
2020-03-24 19:54:08 +02:00
|
|
|
global.SetMeterProvider(provider)
|
2020-02-20 23:05:19 +02:00
|
|
|
boundC.Unbind()
|
|
|
|
|
|
|
|
require.NotPanics(t, func() {
|
|
|
|
boundC.Add(ctx, 1)
|
|
|
|
})
|
|
|
|
require.Equal(t, 0, len(mock.MeasurementBatches))
|
|
|
|
}
|
2020-03-11 20:57:57 +02:00
|
|
|
|
|
|
|
type meterProviderWithConstructorError struct {
|
|
|
|
metric.Provider
|
|
|
|
}
|
|
|
|
|
|
|
|
type meterWithConstructorError struct {
|
2020-05-12 05:29:06 +02:00
|
|
|
metric.MeterImpl
|
2020-03-11 20:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *meterProviderWithConstructorError) Meter(name string) metric.Meter {
|
2020-05-12 05:29:06 +02:00
|
|
|
return metric.WrapMeterImpl(&meterWithConstructorError{m.Provider.Meter(name).MeterImpl()}, name)
|
2020-03-11 20:57:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-12 05:29:06 +02:00
|
|
|
func (m *meterWithConstructorError) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl, error) {
|
|
|
|
return metric.NoopSync{}, errors.New("constructor error")
|
2020-03-11 20:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrorInDeferredConstructor(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
meter := global.MeterProvider().Meter("builtin")
|
|
|
|
|
|
|
|
c1 := Must(meter).NewInt64Counter("test")
|
|
|
|
c2 := Must(meter).NewInt64Counter("test")
|
|
|
|
|
2020-03-24 19:54:08 +02:00
|
|
|
_, provider := metrictest.NewProvider()
|
|
|
|
sdk := &meterProviderWithConstructorError{provider}
|
2020-03-11 20:57:57 +02:00
|
|
|
|
|
|
|
require.Panics(t, func() {
|
|
|
|
global.SetMeterProvider(sdk)
|
|
|
|
})
|
|
|
|
|
2020-03-27 23:06:48 +02:00
|
|
|
c1.Add(ctx, 1)
|
|
|
|
c2.Add(ctx, 2)
|
2020-03-11 20:57:57 +02:00
|
|
|
}
|
2020-03-19 21:02:46 +02:00
|
|
|
|
|
|
|
func TestImplementationIndirection(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
// Test that Implementation() does the proper indirection, i.e.,
|
|
|
|
// returns the implementation interface not the global, after
|
|
|
|
// registered.
|
|
|
|
|
|
|
|
meter1 := global.Meter("test1")
|
|
|
|
|
|
|
|
// Sync: no SDK yet
|
|
|
|
counter := Must(meter1).NewInt64Counter("interface.counter")
|
|
|
|
|
|
|
|
ival := counter.Measurement(1).SyncImpl().Implementation()
|
|
|
|
require.NotNil(t, ival)
|
|
|
|
|
|
|
|
_, ok := ival.(*metrictest.Sync)
|
|
|
|
require.False(t, ok)
|
|
|
|
|
|
|
|
// Async: no SDK yet
|
2020-05-18 20:03:43 +02:00
|
|
|
valueobserver := Must(meter1).RegisterFloat64ValueObserver(
|
|
|
|
"interface.valueobserver",
|
2020-05-20 06:33:10 +02:00
|
|
|
func(_ context.Context, result metric.Float64ObserverResult) {},
|
2020-03-19 21:02:46 +02:00
|
|
|
)
|
|
|
|
|
2020-05-18 20:03:43 +02:00
|
|
|
ival = valueobserver.AsyncImpl().Implementation()
|
2020-03-19 21:02:46 +02:00
|
|
|
require.NotNil(t, ival)
|
|
|
|
|
|
|
|
_, ok = ival.(*metrictest.Async)
|
|
|
|
require.False(t, ok)
|
|
|
|
|
|
|
|
// Register the SDK
|
2020-03-24 19:54:08 +02:00
|
|
|
_, provider := metrictest.NewProvider()
|
|
|
|
global.SetMeterProvider(provider)
|
2020-03-19 21:02:46 +02:00
|
|
|
|
|
|
|
// Repeat the above tests
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
ival = counter.Measurement(1).SyncImpl().Implementation()
|
|
|
|
require.NotNil(t, ival)
|
|
|
|
|
|
|
|
_, ok = ival.(*metrictest.Sync)
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
// Async
|
2020-05-18 20:03:43 +02:00
|
|
|
ival = valueobserver.AsyncImpl().Implementation()
|
2020-03-19 21:02:46 +02:00
|
|
|
require.NotNil(t, ival)
|
|
|
|
|
|
|
|
_, ok = ival.(*metrictest.Async)
|
|
|
|
require.True(t, ok)
|
|
|
|
}
|
2020-04-30 01:13:55 +02:00
|
|
|
|
|
|
|
func TestRecordBatchMock(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
meter := global.MeterProvider().Meter("builtin")
|
|
|
|
|
|
|
|
counter := Must(meter).NewInt64Counter("test.counter")
|
|
|
|
|
|
|
|
meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
|
|
|
|
|
|
|
|
mock, provider := metrictest.NewProvider()
|
|
|
|
global.SetMeterProvider(provider)
|
|
|
|
|
|
|
|
meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
|
|
|
|
|
|
|
|
require.EqualValues(t,
|
|
|
|
[]measured{
|
|
|
|
{
|
|
|
|
Name: "test.counter",
|
|
|
|
LibraryName: "builtin",
|
|
|
|
Labels: asMap(),
|
|
|
|
Number: asInt(1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
asStructs(mock.MeasurementBatches))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRecordBatchRealSDK(t *testing.T) {
|
|
|
|
internal.ResetForTest()
|
|
|
|
|
|
|
|
meter := global.MeterProvider().Meter("builtin")
|
|
|
|
|
|
|
|
counter := Must(meter).NewInt64Counter("test.counter")
|
|
|
|
|
|
|
|
meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
|
|
|
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
pusher, err := stdout.InstallNewPipeline(stdout.Config{
|
|
|
|
Writer: &buf,
|
|
|
|
DoNotPrintTime: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-05-18 19:48:58 +02:00
|
|
|
global.SetMeterProvider(pusher.Provider())
|
2020-04-30 01:13:55 +02:00
|
|
|
|
|
|
|
meter.RecordBatch(context.Background(), nil, counter.Measurement(1))
|
|
|
|
pusher.Stop()
|
|
|
|
|
|
|
|
require.Equal(t, `{"updates":[{"name":"test.counter","sum":1}]}
|
|
|
|
`, buf.String())
|
|
|
|
}
|