Skip to content

Commit 1ee8d7b

Browse files
committed
updated the doc comment and renamed the package
1 parent 128b385 commit 1ee8d7b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ import (
99
"go.opentelemetry.io/otel/sdk/metric/metricdata"
1010
)
1111

12-
// FindMetricVal returns the current value of a [metricName] from the [ManualReader].
13-
func FindMetricVal[V int64 | float64](ctx context.Context, r *otsdkmetric.ManualReader, metricName string, kvs attribute.Set) (V, error) {
12+
// FindVal is a testing utility to find the value of a specific metric
13+
// collected by the sdk metric.ManualReader.
14+
//
15+
// It searches for a metric matching the provided metricName and attribute.Set.
16+
// The type parameter V specifies the expected value type, which must be
17+
// either int64 or float64.
18+
//
19+
// An error is returned if a metric matching the name and attributes is not found,
20+
// or if the found metric's value type does not match V.
21+
func FindVal[V int64 | float64](ctx context.Context, r *otsdkmetric.ManualReader, metricName string, kvs attribute.Set) (V, error) {
1422
var zv V
1523
res := metricdata.ResourceMetrics{}
1624
if err := r.Collect(ctx, &res); err != nil {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestFindMetricVal(t *testing.T) {
2525
}
2626
counter.Add(ctx, 2, metric.WithAttributeSet(attrSet))
2727

28-
counterVal, counterValErr := FindMetricVal[int64](ctx, r, "a_counter_int", attrSet)
28+
counterVal, counterValErr := FindVal[int64](ctx, r, "a_counter_int", attrSet)
2929
if counterValErr != nil {
3030
t.Errorf("failed to fetch counter metric value: %s", counterValErr)
3131
}
@@ -40,7 +40,7 @@ func TestFindMetricVal(t *testing.T) {
4040
}
4141
gauge.Record(ctx, 3, metric.WithAttributeSet(attrSet))
4242

43-
gaugeVal, gaugeValErr := FindMetricVal[int64](ctx, r, "a_gauge_int", attrSet)
43+
gaugeVal, gaugeValErr := FindVal[int64](ctx, r, "a_gauge_int", attrSet)
4444
if gaugeValErr != nil {
4545
t.Errorf("failed to fetch gauge metric value: %s", gaugeValErr)
4646
}

0 commit comments

Comments
 (0)