You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
sdk/metric: Record measurements when context is done (#4671)
This commit is contained in:
@@ -168,6 +168,10 @@ func TestCallbackUnregisterConcurrency(t *testing.T) {
|
||||
|
||||
// Instruments should produce correct ResourceMetrics.
|
||||
func TestMeterCreatesInstruments(t *testing.T) {
|
||||
// The synchronous measurement methods must ignore the context cancelation.
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
attrs := attribute.NewSet(attribute.String("name", "alice"))
|
||||
opt := metric.WithAttributeSet(attrs)
|
||||
testCases := []struct {
|
||||
@@ -340,7 +344,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
ctr, err := m.Int64Counter("sint")
|
||||
assert.NoError(t, err)
|
||||
|
||||
ctr.Add(context.Background(), 3)
|
||||
ctr.Add(ctx, 3)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "sint",
|
||||
@@ -359,7 +363,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
ctr, err := m.Int64UpDownCounter("sint")
|
||||
assert.NoError(t, err)
|
||||
|
||||
ctr.Add(context.Background(), 11)
|
||||
ctr.Add(ctx, 11)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "sint",
|
||||
@@ -378,7 +382,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
gauge, err := m.Int64Histogram("histogram")
|
||||
assert.NoError(t, err)
|
||||
|
||||
gauge.Record(context.Background(), 7)
|
||||
gauge.Record(ctx, 7)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "histogram",
|
||||
@@ -404,7 +408,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
ctr, err := m.Float64Counter("sfloat")
|
||||
assert.NoError(t, err)
|
||||
|
||||
ctr.Add(context.Background(), 3)
|
||||
ctr.Add(ctx, 3)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "sfloat",
|
||||
@@ -423,7 +427,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
ctr, err := m.Float64UpDownCounter("sfloat")
|
||||
assert.NoError(t, err)
|
||||
|
||||
ctr.Add(context.Background(), 11)
|
||||
ctr.Add(ctx, 11)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "sfloat",
|
||||
@@ -442,7 +446,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
|
||||
gauge, err := m.Float64Histogram("histogram")
|
||||
assert.NoError(t, err)
|
||||
|
||||
gauge.Record(context.Background(), 7)
|
||||
gauge.Record(ctx, 7)
|
||||
},
|
||||
want: metricdata.Metrics{
|
||||
Name: "histogram",
|
||||
|
||||
Reference in New Issue
Block a user