Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hstan committed Dec 14, 2020
1 parent a22e258 commit 6dab82e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions sdk/metric/controller/pull/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"testing"
"time"

"go.opentelemetry.io/otel/baggage"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/label"
Expand Down Expand Up @@ -120,30 +122,30 @@ func TestPullWithCache(t *testing.T) {

func TestPullWithMetricsLabelEnricher(t *testing.T) {
metricsLabelsEnricher := func(ctx context.Context, kvs []label.KeyValue) ([]label.KeyValue, error) {
baggage := otel.Baggage(ctx)
baggage := baggage.Set(ctx)
kvs = append(baggage.ToSlice(), kvs...)
return kvs, nil
}

puller := pull.New(
basic.New(
selector.NewWithExactDistribution(),
export.CumulativeExporter,
export.CumulativeExportKindSelector(),
basic.WithMemory(true),
),
pull.WithCachePeriod(0),
pull.WithMetricsLabelsEnricher(metricsLabelsEnricher),
)

ctx := otel.ContextWithBaggageValues(context.Background(), label.String("A", "B"))
ctx := baggage.ContextWithValues(context.Background(), label.String("A", "B"))
meter := puller.MeterProvider().Meter("withLabelEnricher")
counter := otel.Must(meter).NewInt64Counter("counter.sum")
counter := metric.Must(meter).NewInt64Counter("counter.sum")

counter.Add(ctx, 10)

require.NoError(t, puller.Collect(context.Background()))
records := processortest.NewOutput(label.DefaultEncoder())
require.NoError(t, puller.ForEach(export.CumulativeExporter, records.AddRecord))
require.NoError(t, puller.ForEach(export.CumulativeExportKindSelector(), records.AddRecord))

require.EqualValues(t, map[string]float64{
"counter.sum/A=B/": 10,
Expand Down
8 changes: 5 additions & 3 deletions sdk/metric/controller/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"
"time"

"go.opentelemetry.io/otel/baggage"

"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -228,7 +230,7 @@ func TestWithMetricsLabelsEnricher(t *testing.T) {
exporter := newExporter()
checkpointer := newCheckpointer()
metricsLabelsEnricher := func(ctx context.Context, kvs []label.KeyValue) ([]label.KeyValue, error) {
baggage := otel.Baggage(ctx)
baggage := baggage.Set(ctx)
kvs = append(baggage.ToSlice(), kvs...)
return kvs, nil
}
Expand All @@ -243,11 +245,11 @@ func TestWithMetricsLabelsEnricher(t *testing.T) {
mock := controllertest.NewMockClock()
p.SetClock(mock)

counter := otel.Must(meter).NewInt64Counter("counter.sum")
counter := metric.Must(meter).NewInt64Counter("counter.sum")

p.Start()

ctx := otel.ContextWithBaggageValues(context.Background(), label.String("A", "B"))
ctx := baggage.ContextWithValues(context.Background(), label.String("A", "B"))
counter.Add(ctx, 1)

require.EqualValues(t, map[string]float64{}, exporter.Values())
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (s *syncInstrument) RecordOne(ctx context.Context, num number.Number, kvs [
var err error
kvs, err = s.meter.metricsLabelsEnricher(ctx, kvs)
if err != nil {
global.Handle(err)
otel.Handle(err)
return
}
}
Expand Down

0 comments on commit 6dab82e

Please sign in to comment.