@@ -103,6 +103,34 @@ func TestPrometheusExporter(t *testing.T) {
103103 counter .Add (ctx , 9 , attrs ... )
104104 },
105105 },
106+ {
107+ name : "invalid instruments are dropped" ,
108+ expectedFile : "testdata/gauge.txt" ,
109+ recordMetrics : func (ctx context.Context , meter otelmetric.Meter ) {
110+ attrs := []attribute.KeyValue {
111+ attribute .Key ("A" ).String ("B" ),
112+ attribute .Key ("C" ).String ("D" ),
113+ }
114+ // Valid.
115+ gauge , err := meter .SyncFloat64 ().UpDownCounter ("bar" , instrument .WithDescription ("a fun little gauge" ))
116+ require .NoError (t , err )
117+ gauge .Add (ctx , 100 , attrs ... )
118+ gauge .Add (ctx , - 25 , attrs ... )
119+
120+ // Invalid, should be dropped.
121+ gauge , err = meter .SyncFloat64 ().UpDownCounter ("invalid.gauge.name" )
122+ require .NoError (t , err )
123+ gauge .Add (ctx , 100 , attrs ... )
124+
125+ counter , err := meter .SyncFloat64 ().Counter ("invalid.counter.name" )
126+ require .NoError (t , err )
127+ counter .Add (ctx , 100 , attrs ... )
128+
129+ histogram , err := meter .SyncFloat64 ().Histogram ("invalid.hist.name" )
130+ require .NoError (t , err )
131+ histogram .Record (ctx , 23 , attrs ... )
132+ },
133+ },
106134 }
107135
108136 for _ , tc := range testCases {
0 commit comments