...
1
2
3
4 package otelgrpc
5
6 import (
7 "context"
8 "testing"
9
10 "github.com/stretchr/testify/assert"
11
12 "go.opentelemetry.io/otel/metric"
13 "go.opentelemetry.io/otel/metric/embedded"
14 )
15
16 func TestNilInstruments(t *testing.T) {
17 mp := meterProvider{}
18 c := newConfig([]Option{WithMeterProvider(mp)}, "test")
19
20 ctx := context.Background()
21 assert.NotPanics(t, func() { c.rpcDuration.Record(ctx, 0) }, "rpcDuration")
22 assert.NotPanics(t, func() { c.rpcRequestSize.Record(ctx, 0) }, "rpcRequestSize")
23 assert.NotPanics(t, func() { c.rpcResponseSize.Record(ctx, 0) }, "rpcResponseSize")
24 assert.NotPanics(t, func() { c.rpcRequestsPerRPC.Record(ctx, 0) }, "rpcRequestsPerRPC")
25 assert.NotPanics(t, func() { c.rpcResponsesPerRPC.Record(ctx, 0) }, "rpcResponsesPerRPC")
26 }
27
28 type meterProvider struct {
29 embedded.MeterProvider
30 }
31
32 func (meterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
33 return meter{}
34 }
35
36 type meter struct {
37
38 metric.Meter
39 }
40
41 func (meter) Int64Histogram(string, ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
42 return nil, assert.AnError
43 }
44
45 func (meter) Float64Histogram(string, ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
46 return nil, assert.AnError
47 }
48
View as plain text