@@ -30,10 +30,38 @@ def initialize
3030 @instrument_registry = { }
3131 end
3232
33+ # {https://opentelemetry.io/docs/specs/otel/metrics/api/#counter Counter} is a synchronous Instrument which supports non-negative increments.
34+ #
35+ # With this api call:
36+ #
37+ # exception_counter = meter.create_counter("exceptions",
38+ # description: "number of exceptions caught",
39+ # unit: 's')
40+ #
41+ # @param name [String] the name of the counter
42+ # @param unit [optional String] an optional string provided by user.
43+ # @param description [optional String] an optional free-form text provided by user.
44+ #
45+ # @return [nil] after creation of counter, it will be stored in instrument_registry
3346 def create_counter ( name , unit : nil , description : nil )
3447 create_instrument ( :counter , name , unit , description , nil ) { COUNTER }
3548 end
3649
50+ # Histogram is a synchronous Instrument which can be used to report arbitrary values that are likely
51+ # to be statistically meaningful. It is intended for statistics such as histograms,
52+ # summaries, and percentiles.
53+ #
54+ # With this api call:
55+ #
56+ # http_server_duration = meter.create_histogram("http.server.duration",
57+ # description: "measures the duration of the inbound HTTP request",
58+ # unit: "s")
59+ #
60+ # @param name [String] the name of the histogram
61+ # @param unit [optional String] an optional string provided by user.
62+ # @param description [optional String] an optional free-form text provided by user.
63+ #
64+ # @return [nil] after creation of histogram, it will be stored in instrument_registry
3765 def create_histogram ( name , unit : nil , description : nil )
3866 create_instrument ( :histogram , name , unit , description , nil ) { HISTOGRAM }
3967 end
@@ -56,18 +84,87 @@ def create_gauge(name, unit: nil, description: nil)
5684 create_instrument ( :gauge , name , unit , description , nil ) { GAUGE }
5785 end
5886
87+ # UpDownCounter is a synchronous Instrument which supports increments and decrements.
88+ #
89+ # With this api call:
90+ #
91+ # items_counter = meter.create_up_down_counter("store.inventory",
92+ # description: "the number of the items available",
93+ # unit: "s")
94+ #
95+ # @param name [String] the name of the up_down_counter
96+ # @param unit [optional String] an optional string provided by user.
97+ # @param description [optional String] an optional free-form text provided by user.
98+ #
99+ # @return [nil] after creation of up_down_counter, it will be stored in instrument_registry
59100 def create_up_down_counter ( name , unit : nil , description : nil )
60101 create_instrument ( :up_down_counter , name , unit , description , nil ) { UP_DOWN_COUNTER }
61102 end
62103
104+ # ObservableCounter is an asynchronous Instrument which reports monotonically
105+ # increasing value(s) when the instrument is being observed.
106+ #
107+ # With this api call:
108+ #
109+ # pf_callback = -> { # collect metrics here }
110+ # meter.create_observable_counter("PF",
111+ # pf_callback,
112+ # description: "process page faults",
113+ # unit: 'ms')
114+ #
115+ #
116+ # @param name [String] the name of the observable_counter
117+ # @param callback [Proc] the callback function that used to collect metrics
118+ # @param unit [optional String] an optional string provided by user.
119+ # @param description [optional String] an optional free-form text provided by user.
120+ #
121+ # @return [nil] after creation of observable_counter, it will be stored in instrument_registry
63122 def create_observable_counter ( name , callback :, unit : nil , description : nil )
64123 create_instrument ( :observable_counter , name , unit , description , callback ) { OBSERVABLE_COUNTER }
65124 end
66125
126+ # ObservableGauge is an asynchronous Instrument which reports non-additive value(s)
127+ # (e.g. the room temperature - it makes no sense to report the temperature value
128+ # from multiple rooms and sum them up) when the instrument is being observed.
129+ #
130+ # With this api call:
131+ #
132+ # pf_callback = -> { # collect metrics here }
133+ # meter.create_observable_counter("cpu.frequency",
134+ # pf_callback,
135+ # description: "the real-time CPU clock speed",
136+ # unit: 'ms')
137+ #
138+ #
139+ # @param name [String] the name of the observable_gauge
140+ # @param callback [Proc] the callback function that used to collect metrics
141+ # @param unit [optional String] an optional string provided by user.
142+ # @param description [optional String] an optional free-form text provided by user.
143+ #
144+ # @return [nil] after creation of observable_gauge, it will be stored in instrument_registry
67145 def create_observable_gauge ( name , callback :, unit : nil , description : nil )
68146 create_instrument ( :observable_gauge , name , unit , description , callback ) { OBSERVABLE_GAUGE }
69147 end
70148
149+ # ObservableUpDownCounter is an asynchronous Instrument which reports additive value(s)
150+ # (e.g. the process heap size - it makes sense to report the heap size from multiple processes
151+ # and sum them up, so we get the total heap usage) when the instrument is being observed.
152+ #
153+ # With this api call:
154+ #
155+ # pf_callback = -> { # collect metrics here }
156+ # meter.create_observable_up_down_counter("process.workingset",
157+ # pf_callback,
158+ # description: "process working set",
159+ # unit: 'KB')
160+ #
161+ #
162+ # @param name [String] the name of the observable_up_down_counter
163+ # @param callback [Proc] the callback function that used to collect metrics
164+ # @param unit [optional String] an optional string provided by user.
165+ # @param description [optional String] an optional free-form text provided by user.
166+ #
167+ # @return [nil] after creation of observable_up_down_counter, it will be stored in instrument_registry
71168 def create_observable_up_down_counter ( name , callback :, unit : nil , description : nil )
72169 create_instrument ( :observable_up_down_counter , name , unit , description , callback ) { OBSERVABLE_UP_DOWN_COUNTER }
73170 end
0 commit comments