blob: c88e050a38f9ca77d0657f330c2408bdccb7aa1a [file] [log] [blame]
Joey Armstronge8c091f2023-01-17 16:56:26 -05001// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package metric
16
17// MeterMust is a wrapper for Meter interfaces that panics when any
18// instrument constructor encounters an error.
19type MeterMust struct {
20 meter Meter
21}
22
23// BatchObserverMust is a wrapper for BatchObserver that panics when
24// any instrument constructor encounters an error.
25type BatchObserverMust struct {
26 batch BatchObserver
27}
28
29// Must constructs a MeterMust implementation from a Meter, allowing
30// the application to panic when any instrument constructor yields an
31// error.
32func Must(meter Meter) MeterMust {
33 return MeterMust{meter: meter}
34}
35
36// NewInt64Counter calls `Meter.NewInt64Counter` and returns the
37// instrument, panicking if it encounters an error.
38func (mm MeterMust) NewInt64Counter(name string, cos ...InstrumentOption) Int64Counter {
39 if inst, err := mm.meter.NewInt64Counter(name, cos...); err != nil {
40 panic(err)
41 } else {
42 return inst
43 }
44}
45
46// NewFloat64Counter calls `Meter.NewFloat64Counter` and returns the
47// instrument, panicking if it encounters an error.
48func (mm MeterMust) NewFloat64Counter(name string, cos ...InstrumentOption) Float64Counter {
49 if inst, err := mm.meter.NewFloat64Counter(name, cos...); err != nil {
50 panic(err)
51 } else {
52 return inst
53 }
54}
55
56// NewInt64UpDownCounter calls `Meter.NewInt64UpDownCounter` and returns the
57// instrument, panicking if it encounters an error.
58func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...InstrumentOption) Int64UpDownCounter {
59 if inst, err := mm.meter.NewInt64UpDownCounter(name, cos...); err != nil {
60 panic(err)
61 } else {
62 return inst
63 }
64}
65
66// NewFloat64UpDownCounter calls `Meter.NewFloat64UpDownCounter` and returns the
67// instrument, panicking if it encounters an error.
68func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...InstrumentOption) Float64UpDownCounter {
69 if inst, err := mm.meter.NewFloat64UpDownCounter(name, cos...); err != nil {
70 panic(err)
71 } else {
72 return inst
73 }
74}
75
76// NewInt64ValueRecorder calls `Meter.NewInt64ValueRecorder` and returns the
77// instrument, panicking if it encounters an error.
78func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...InstrumentOption) Int64ValueRecorder {
79 if inst, err := mm.meter.NewInt64ValueRecorder(name, mos...); err != nil {
80 panic(err)
81 } else {
82 return inst
83 }
84}
85
86// NewFloat64ValueRecorder calls `Meter.NewFloat64ValueRecorder` and returns the
87// instrument, panicking if it encounters an error.
88func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...InstrumentOption) Float64ValueRecorder {
89 if inst, err := mm.meter.NewFloat64ValueRecorder(name, mos...); err != nil {
90 panic(err)
91 } else {
92 return inst
93 }
94}
95
96// NewInt64ValueObserver calls `Meter.NewInt64ValueObserver` and
97// returns the instrument, panicking if it encounters an error.
98func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64ValueObserver {
99 if inst, err := mm.meter.NewInt64ValueObserver(name, callback, oos...); err != nil {
100 panic(err)
101 } else {
102 return inst
103 }
104}
105
106// NewFloat64ValueObserver calls `Meter.NewFloat64ValueObserver` and
107// returns the instrument, panicking if it encounters an error.
108func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64ValueObserver {
109 if inst, err := mm.meter.NewFloat64ValueObserver(name, callback, oos...); err != nil {
110 panic(err)
111 } else {
112 return inst
113 }
114}
115
116// NewInt64SumObserver calls `Meter.NewInt64SumObserver` and
117// returns the instrument, panicking if it encounters an error.
118func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64SumObserver {
119 if inst, err := mm.meter.NewInt64SumObserver(name, callback, oos...); err != nil {
120 panic(err)
121 } else {
122 return inst
123 }
124}
125
126// NewFloat64SumObserver calls `Meter.NewFloat64SumObserver` and
127// returns the instrument, panicking if it encounters an error.
128func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64SumObserver {
129 if inst, err := mm.meter.NewFloat64SumObserver(name, callback, oos...); err != nil {
130 panic(err)
131 } else {
132 return inst
133 }
134}
135
136// NewInt64UpDownSumObserver calls `Meter.NewInt64UpDownSumObserver` and
137// returns the instrument, panicking if it encounters an error.
138func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64UpDownSumObserver {
139 if inst, err := mm.meter.NewInt64UpDownSumObserver(name, callback, oos...); err != nil {
140 panic(err)
141 } else {
142 return inst
143 }
144}
145
146// NewFloat64UpDownSumObserver calls `Meter.NewFloat64UpDownSumObserver` and
147// returns the instrument, panicking if it encounters an error.
148func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64UpDownSumObserver {
149 if inst, err := mm.meter.NewFloat64UpDownSumObserver(name, callback, oos...); err != nil {
150 panic(err)
151 } else {
152 return inst
153 }
154}
155
156// NewBatchObserver returns a wrapper around BatchObserver that panics
157// when any instrument constructor returns an error.
158func (mm MeterMust) NewBatchObserver(callback BatchObserverFunc) BatchObserverMust {
159 return BatchObserverMust{
160 batch: mm.meter.NewBatchObserver(callback),
161 }
162}
163
164// NewInt64ValueObserver calls `BatchObserver.NewInt64ValueObserver` and
165// returns the instrument, panicking if it encounters an error.
166func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...InstrumentOption) Int64ValueObserver {
167 if inst, err := bm.batch.NewInt64ValueObserver(name, oos...); err != nil {
168 panic(err)
169 } else {
170 return inst
171 }
172}
173
174// NewFloat64ValueObserver calls `BatchObserver.NewFloat64ValueObserver` and
175// returns the instrument, panicking if it encounters an error.
176func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...InstrumentOption) Float64ValueObserver {
177 if inst, err := bm.batch.NewFloat64ValueObserver(name, oos...); err != nil {
178 panic(err)
179 } else {
180 return inst
181 }
182}
183
184// NewInt64SumObserver calls `BatchObserver.NewInt64SumObserver` and
185// returns the instrument, panicking if it encounters an error.
186func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...InstrumentOption) Int64SumObserver {
187 if inst, err := bm.batch.NewInt64SumObserver(name, oos...); err != nil {
188 panic(err)
189 } else {
190 return inst
191 }
192}
193
194// NewFloat64SumObserver calls `BatchObserver.NewFloat64SumObserver` and
195// returns the instrument, panicking if it encounters an error.
196func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...InstrumentOption) Float64SumObserver {
197 if inst, err := bm.batch.NewFloat64SumObserver(name, oos...); err != nil {
198 panic(err)
199 } else {
200 return inst
201 }
202}
203
204// NewInt64UpDownSumObserver calls `BatchObserver.NewInt64UpDownSumObserver` and
205// returns the instrument, panicking if it encounters an error.
206func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...InstrumentOption) Int64UpDownSumObserver {
207 if inst, err := bm.batch.NewInt64UpDownSumObserver(name, oos...); err != nil {
208 panic(err)
209 } else {
210 return inst
211 }
212}
213
214// NewFloat64UpDownSumObserver calls `BatchObserver.NewFloat64UpDownSumObserver` and
215// returns the instrument, panicking if it encounters an error.
216func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...InstrumentOption) Float64UpDownSumObserver {
217 if inst, err := bm.batch.NewFloat64UpDownSumObserver(name, oos...); err != nil {
218 panic(err)
219 } else {
220 return inst
221 }
222}