| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package runtime // import "go.opentelemetry.io/contrib/instrumentation/runtime" |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
"go.opentelemetry.io/otel/sdk/instrumentation" |
| 12 |
"go.opentelemetry.io/otel/sdk/metric" |
| 13 |
"go.opentelemetry.io/otel/sdk/metric/metricdata" |
| 14 |
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" |
| 15 |
) |
| 16 |
|
| 17 |
func TestNewProducer(t *testing.T) { |
| 18 |
reader := metric.NewManualReader(metric.WithProducer(NewProducer())) |
| 19 |
_ = metric.NewMeterProvider(metric.WithReader(reader)) |
| 20 |
rm := metricdata.ResourceMetrics{} |
| 21 |
err := reader.Collect(t.Context(), &rm) |
| 22 |
assert.NoError(t, err) |
| 23 |
require.Len(t, rm.ScopeMetrics, 1) |
| 24 |
require.Len(t, rm.ScopeMetrics[0].Metrics, 1) |
| 25 |
|
| 26 |
expectedScopeMetric := metricdata.ScopeMetrics{ |
| 27 |
Scope: instrumentation.Scope{ |
| 28 |
Name: "go.opentelemetry.io/contrib/instrumentation/runtime", |
| 29 |
Version: Version, |
| 30 |
}, |
| 31 |
Metrics: []metricdata.Metrics{ |
| 32 |
{ |
| 33 |
Name: "go.schedule.duration", |
| 34 |
Description: "The time goroutines have spent in the scheduler in a runnable state before actually running.", |
| 35 |
Unit: "s", |
| 36 |
Data: metricdata.Histogram[float64]{ |
| 37 |
Temporality: metricdata.CumulativeTemporality, |
| 38 |
DataPoints: []metricdata.HistogramDataPoint[float64]{ |
| 39 |
{}, |
| 40 |
}, |
| 41 |
}, |
| 42 |
}, |
| 43 |
}, |
| 44 |
} |
| 45 |
metricdatatest.AssertEqual(t, expectedScopeMetric, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue()) |
| 46 |
} |