| 1 | // Copyright 2021 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package otel_test |
| 6 | |
| 7 | import ( |
| 8 | "context" |
| 9 | "testing" |
| 10 | "time" |
| 11 | |
| 12 | "go.opentelemetry.io/otel/attribute" |
| 13 | "golang.org/x/exp/event" |
| 14 | ) |
| 15 | |
| 16 | func TestMeter(t *testing.T) { |
| 17 | t.Skip("package go.opentelemetry.io/otel/metric/metrictest removed") |
| 18 | |
| 19 | // ctx := context.Background() |
| 20 | // mp := metrictest.NewMeterProvider() |
| 21 | // mh := otel.NewMetricHandler(mp.Meter("test")) |
| 22 | // ctx = event.WithExporter(ctx, event.NewExporter(mh, nil)) |
| 23 | // recordMetrics(ctx) |
| 24 | |
| 25 | // lib := metrictest.Library{InstrumentationName: "test"} |
| 26 | // emptyLabels := map[attribute.Key]attribute.Value{} |
| 27 | // got := metrictest.AsStructs(mp.MeasurementBatches) |
| 28 | // want := []metrictest.Measured{ |
| 29 | // { |
| 30 | // Name: "golang.org/x/exp/event/otel_test/hits", |
| 31 | // Number: number.NewInt64Number(8), |
| 32 | // Labels: emptyLabels, |
| 33 | // Library: lib, |
| 34 | // }, |
| 35 | // { |
| 36 | // Name: "golang.org/x/exp/event/otel_test/temp", |
| 37 | // Number: number.NewFloat64Number(-100), |
| 38 | // Labels: map[attribute.Key]attribute.Value{"location": attribute.StringValue("Mare Imbrium")}, |
| 39 | // Library: lib, |
| 40 | // }, |
| 41 | // { |
| 42 | // Name: "golang.org/x/exp/event/otel_test/latency", |
| 43 | // Number: number.NewInt64Number(int64(1248 * time.Millisecond)), |
| 44 | // Labels: emptyLabels, |
| 45 | // Library: lib, |
| 46 | // }, |
| 47 | // { |
| 48 | // Name: "golang.org/x/exp/event/otel_test/latency", |
| 49 | // Number: number.NewInt64Number(int64(1255 * time.Millisecond)), |
| 50 | // Labels: emptyLabels, |
| 51 | // Library: lib, |
| 52 | // }, |
| 53 | // } |
| 54 | |
| 55 | // if diff := cmp.Diff(want, got, cmp.Comparer(valuesEqual)); diff != "" { |
| 56 | // t.Errorf("mismatch (-want, got):\n%s", diff) |
| 57 | // } |
| 58 | } |
| 59 | |
| 60 | func valuesEqual(v1, v2 attribute.Value) bool { |
| 61 | return v1.AsInterface() == v2.AsInterface() |
| 62 | } |
| 63 | |
| 64 | func recordMetrics(ctx context.Context) { |
| 65 | c := event.NewCounter("hits", &event.MetricOptions{Description: "Earth meteorite hits"}) |
| 66 | g := event.NewFloatGauge("temp", &event.MetricOptions{Description: "moon surface temperature in Kelvin"}) |
| 67 | d := event.NewDuration("latency", &event.MetricOptions{Description: "Earth-moon comms lag, milliseconds"}) |
| 68 | |
| 69 | c.Record(ctx, 8) |
| 70 | g.Record(ctx, -100, event.String("location", "Mare Imbrium")) |
| 71 | d.Record(ctx, 1248*time.Millisecond) |
| 72 | d.Record(ctx, 1255*time.Millisecond) |
| 73 | } |