Debian Codegraph @

semconv/v1.32.0/goconv/metric.go

raw
1 // Code generated from semantic convention specification. DO NOT EDIT.
2
3 // Copyright The OpenTelemetry Authors
4 // SPDX-License-Identifier: Apache-2.0
5
6 // Package goconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "go" namespace.
8 package goconv
9
10 import (
11 "context"
12 "sync"
13
14 "go.opentelemetry.io/otel/attribute"
15 "go.opentelemetry.io/otel/metric"
16 "go.opentelemetry.io/otel/metric/noop"
17 )
18
19 var (
20 addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
21 recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
22 )
23
24 // MemoryTypeAttr is an attribute conforming to the go.memory.type semantic
25 // conventions. It represents the type of memory.
26 type MemoryTypeAttr string
27
28 var (
29 // MemoryTypeStack is the memory allocated from the heap that is reserved for
30 // stack space, whether or not it is currently in-use.
31 MemoryTypeStack MemoryTypeAttr = "stack"
32 // MemoryTypeOther is the memory used by the Go runtime, excluding other
33 // categories of memory usage described in this enumeration.
34 MemoryTypeOther MemoryTypeAttr = "other"
35 )
36
37 // ConfigGogc is an instrument used to record metric values conforming to the
38 // "go.config.gogc" semantic conventions. It represents the heap size target
39 // percentage configured by the user, otherwise 100.
40 type ConfigGogc struct {
41 metric.Int64ObservableUpDownCounter
42 }
43
44 // NewConfigGogc returns a new ConfigGogc instrument.
45 func NewConfigGogc(
46 m metric.Meter,
47 opt ...metric.Int64ObservableUpDownCounterOption,
48 ) (ConfigGogc, error) {
49 // Check if the meter is nil.
50 if m == nil {
51 return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, nil
52 }
53
54 i, err := m.Int64ObservableUpDownCounter(
55 "go.config.gogc",
56 append([]metric.Int64ObservableUpDownCounterOption{
57 metric.WithDescription("Heap size target percentage configured by the user, otherwise 100."),
58 metric.WithUnit("%"),
59 }, opt...)...,
60 )
61 if err != nil {
62 return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, err
63 }
64 return ConfigGogc{i}, nil
65 }
66
67 // Inst returns the underlying metric instrument.
68 func (m ConfigGogc) Inst() metric.Int64ObservableUpDownCounter {
69 return m.Int64ObservableUpDownCounter
70 }
71
72 // Name returns the semantic convention name of the instrument.
73 func (ConfigGogc) Name() string {
74 return "go.config.gogc"
75 }
76
77 // Unit returns the semantic convention unit of the instrument
78 func (ConfigGogc) Unit() string {
79 return "%"
80 }
81
82 // Description returns the semantic convention description of the instrument
83 func (ConfigGogc) Description() string {
84 return "Heap size target percentage configured by the user, otherwise 100."
85 }
86
87 // GoroutineCount is an instrument used to record metric values conforming to the
88 // "go.goroutine.count" semantic conventions. It represents the count of live
89 // goroutines.
90 type GoroutineCount struct {
91 metric.Int64ObservableUpDownCounter
92 }
93
94 // NewGoroutineCount returns a new GoroutineCount instrument.
95 func NewGoroutineCount(
96 m metric.Meter,
97 opt ...metric.Int64ObservableUpDownCounterOption,
98 ) (GoroutineCount, error) {
99 // Check if the meter is nil.
100 if m == nil {
101 return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, nil
102 }
103
104 i, err := m.Int64ObservableUpDownCounter(
105 "go.goroutine.count",
106 append([]metric.Int64ObservableUpDownCounterOption{
107 metric.WithDescription("Count of live goroutines."),
108 metric.WithUnit("{goroutine}"),
109 }, opt...)...,
110 )
111 if err != nil {
112 return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, err
113 }
114 return GoroutineCount{i}, nil
115 }
116
117 // Inst returns the underlying metric instrument.
118 func (m GoroutineCount) Inst() metric.Int64ObservableUpDownCounter {
119 return m.Int64ObservableUpDownCounter
120 }
121
122 // Name returns the semantic convention name of the instrument.
123 func (GoroutineCount) Name() string {
124 return "go.goroutine.count"
125 }
126
127 // Unit returns the semantic convention unit of the instrument
128 func (GoroutineCount) Unit() string {
129 return "{goroutine}"
130 }
131
132 // Description returns the semantic convention description of the instrument
133 func (GoroutineCount) Description() string {
134 return "Count of live goroutines."
135 }
136
137 // MemoryAllocated is an instrument used to record metric values conforming to
138 // the "go.memory.allocated" semantic conventions. It represents the memory
139 // allocated to the heap by the application.
140 type MemoryAllocated struct {
141 metric.Int64ObservableCounter
142 }
143
144 // NewMemoryAllocated returns a new MemoryAllocated instrument.
145 func NewMemoryAllocated(
146 m metric.Meter,
147 opt ...metric.Int64ObservableCounterOption,
148 ) (MemoryAllocated, error) {
149 // Check if the meter is nil.
150 if m == nil {
151 return MemoryAllocated{noop.Int64ObservableCounter{}}, nil
152 }
153
154 i, err := m.Int64ObservableCounter(
155 "go.memory.allocated",
156 append([]metric.Int64ObservableCounterOption{
157 metric.WithDescription("Memory allocated to the heap by the application."),
158 metric.WithUnit("By"),
159 }, opt...)...,
160 )
161 if err != nil {
162 return MemoryAllocated{noop.Int64ObservableCounter{}}, err
163 }
164 return MemoryAllocated{i}, nil
165 }
166
167 // Inst returns the underlying metric instrument.
168 func (m MemoryAllocated) Inst() metric.Int64ObservableCounter {
169 return m.Int64ObservableCounter
170 }
171
172 // Name returns the semantic convention name of the instrument.
173 func (MemoryAllocated) Name() string {
174 return "go.memory.allocated"
175 }
176
177 // Unit returns the semantic convention unit of the instrument
178 func (MemoryAllocated) Unit() string {
179 return "By"
180 }
181
182 // Description returns the semantic convention description of the instrument
183 func (MemoryAllocated) Description() string {
184 return "Memory allocated to the heap by the application."
185 }
186
187 // MemoryAllocations is an instrument used to record metric values conforming to
188 // the "go.memory.allocations" semantic conventions. It represents the count of
189 // allocations to the heap by the application.
190 type MemoryAllocations struct {
191 metric.Int64ObservableCounter
192 }
193
194 // NewMemoryAllocations returns a new MemoryAllocations instrument.
195 func NewMemoryAllocations(
196 m metric.Meter,
197 opt ...metric.Int64ObservableCounterOption,
198 ) (MemoryAllocations, error) {
199 // Check if the meter is nil.
200 if m == nil {
201 return MemoryAllocations{noop.Int64ObservableCounter{}}, nil
202 }
203
204 i, err := m.Int64ObservableCounter(
205 "go.memory.allocations",
206 append([]metric.Int64ObservableCounterOption{
207 metric.WithDescription("Count of allocations to the heap by the application."),
208 metric.WithUnit("{allocation}"),
209 }, opt...)...,
210 )
211 if err != nil {
212 return MemoryAllocations{noop.Int64ObservableCounter{}}, err
213 }
214 return MemoryAllocations{i}, nil
215 }
216
217 // Inst returns the underlying metric instrument.
218 func (m MemoryAllocations) Inst() metric.Int64ObservableCounter {
219 return m.Int64ObservableCounter
220 }
221
222 // Name returns the semantic convention name of the instrument.
223 func (MemoryAllocations) Name() string {
224 return "go.memory.allocations"
225 }
226
227 // Unit returns the semantic convention unit of the instrument
228 func (MemoryAllocations) Unit() string {
229 return "{allocation}"
230 }
231
232 // Description returns the semantic convention description of the instrument
233 func (MemoryAllocations) Description() string {
234 return "Count of allocations to the heap by the application."
235 }
236
237 // MemoryGCGoal is an instrument used to record metric values conforming to the
238 // "go.memory.gc.goal" semantic conventions. It represents the heap size target
239 // for the end of the GC cycle.
240 type MemoryGCGoal struct {
241 metric.Int64ObservableUpDownCounter
242 }
243
244 // NewMemoryGCGoal returns a new MemoryGCGoal instrument.
245 func NewMemoryGCGoal(
246 m metric.Meter,
247 opt ...metric.Int64ObservableUpDownCounterOption,
248 ) (MemoryGCGoal, error) {
249 // Check if the meter is nil.
250 if m == nil {
251 return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, nil
252 }
253
254 i, err := m.Int64ObservableUpDownCounter(
255 "go.memory.gc.goal",
256 append([]metric.Int64ObservableUpDownCounterOption{
257 metric.WithDescription("Heap size target for the end of the GC cycle."),
258 metric.WithUnit("By"),
259 }, opt...)...,
260 )
261 if err != nil {
262 return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, err
263 }
264 return MemoryGCGoal{i}, nil
265 }
266
267 // Inst returns the underlying metric instrument.
268 func (m MemoryGCGoal) Inst() metric.Int64ObservableUpDownCounter {
269 return m.Int64ObservableUpDownCounter
270 }
271
272 // Name returns the semantic convention name of the instrument.
273 func (MemoryGCGoal) Name() string {
274 return "go.memory.gc.goal"
275 }
276
277 // Unit returns the semantic convention unit of the instrument
278 func (MemoryGCGoal) Unit() string {
279 return "By"
280 }
281
282 // Description returns the semantic convention description of the instrument
283 func (MemoryGCGoal) Description() string {
284 return "Heap size target for the end of the GC cycle."
285 }
286
287 // MemoryLimit is an instrument used to record metric values conforming to the
288 // "go.memory.limit" semantic conventions. It represents the go runtime memory
289 // limit configured by the user, if a limit exists.
290 type MemoryLimit struct {
291 metric.Int64ObservableUpDownCounter
292 }
293
294 // NewMemoryLimit returns a new MemoryLimit instrument.
295 func NewMemoryLimit(
296 m metric.Meter,
297 opt ...metric.Int64ObservableUpDownCounterOption,
298 ) (MemoryLimit, error) {
299 // Check if the meter is nil.
300 if m == nil {
301 return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, nil
302 }
303
304 i, err := m.Int64ObservableUpDownCounter(
305 "go.memory.limit",
306 append([]metric.Int64ObservableUpDownCounterOption{
307 metric.WithDescription("Go runtime memory limit configured by the user, if a limit exists."),
308 metric.WithUnit("By"),
309 }, opt...)...,
310 )
311 if err != nil {
312 return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, err
313 }
314 return MemoryLimit{i}, nil
315 }
316
317 // Inst returns the underlying metric instrument.
318 func (m MemoryLimit) Inst() metric.Int64ObservableUpDownCounter {
319 return m.Int64ObservableUpDownCounter
320 }
321
322 // Name returns the semantic convention name of the instrument.
323 func (MemoryLimit) Name() string {
324 return "go.memory.limit"
325 }
326
327 // Unit returns the semantic convention unit of the instrument
328 func (MemoryLimit) Unit() string {
329 return "By"
330 }
331
332 // Description returns the semantic convention description of the instrument
333 func (MemoryLimit) Description() string {
334 return "Go runtime memory limit configured by the user, if a limit exists."
335 }
336
337 // MemoryUsed is an instrument used to record metric values conforming to the
338 // "go.memory.used" semantic conventions. It represents the memory used by the Go
339 // runtime.
340 type MemoryUsed struct {
341 metric.Int64ObservableCounter
342 }
343
344 // NewMemoryUsed returns a new MemoryUsed instrument.
345 func NewMemoryUsed(
346 m metric.Meter,
347 opt ...metric.Int64ObservableCounterOption,
348 ) (MemoryUsed, error) {
349 // Check if the meter is nil.
350 if m == nil {
351 return MemoryUsed{noop.Int64ObservableCounter{}}, nil
352 }
353
354 i, err := m.Int64ObservableCounter(
355 "go.memory.used",
356 append([]metric.Int64ObservableCounterOption{
357 metric.WithDescription("Memory used by the Go runtime."),
358 metric.WithUnit("By"),
359 }, opt...)...,
360 )
361 if err != nil {
362 return MemoryUsed{noop.Int64ObservableCounter{}}, err
363 }
364 return MemoryUsed{i}, nil
365 }
366
367 // Inst returns the underlying metric instrument.
368 func (m MemoryUsed) Inst() metric.Int64ObservableCounter {
369 return m.Int64ObservableCounter
370 }
371
372 // Name returns the semantic convention name of the instrument.
373 func (MemoryUsed) Name() string {
374 return "go.memory.used"
375 }
376
377 // Unit returns the semantic convention unit of the instrument
378 func (MemoryUsed) Unit() string {
379 return "By"
380 }
381
382 // Description returns the semantic convention description of the instrument
383 func (MemoryUsed) Description() string {
384 return "Memory used by the Go runtime."
385 }
386
387 // AttrMemoryType returns an optional attribute for the "go.memory.type" semantic
388 // convention. It represents the type of memory.
389 func (MemoryUsed) AttrMemoryType(val MemoryTypeAttr) attribute.KeyValue {
390 return attribute.String("go.memory.type", string(val))
391 }
392
393 // ProcessorLimit is an instrument used to record metric values conforming to the
394 // "go.processor.limit" semantic conventions. It represents the number of OS
395 // threads that can execute user-level Go code simultaneously.
396 type ProcessorLimit struct {
397 metric.Int64ObservableUpDownCounter
398 }
399
400 // NewProcessorLimit returns a new ProcessorLimit instrument.
401 func NewProcessorLimit(
402 m metric.Meter,
403 opt ...metric.Int64ObservableUpDownCounterOption,
404 ) (ProcessorLimit, error) {
405 // Check if the meter is nil.
406 if m == nil {
407 return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, nil
408 }
409
410 i, err := m.Int64ObservableUpDownCounter(
411 "go.processor.limit",
412 append([]metric.Int64ObservableUpDownCounterOption{
413 metric.WithDescription("The number of OS threads that can execute user-level Go code simultaneously."),
414 metric.WithUnit("{thread}"),
415 }, opt...)...,
416 )
417 if err != nil {
418 return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, err
419 }
420 return ProcessorLimit{i}, nil
421 }
422
423 // Inst returns the underlying metric instrument.
424 func (m ProcessorLimit) Inst() metric.Int64ObservableUpDownCounter {
425 return m.Int64ObservableUpDownCounter
426 }
427
428 // Name returns the semantic convention name of the instrument.
429 func (ProcessorLimit) Name() string {
430 return "go.processor.limit"
431 }
432
433 // Unit returns the semantic convention unit of the instrument
434 func (ProcessorLimit) Unit() string {
435 return "{thread}"
436 }
437
438 // Description returns the semantic convention description of the instrument
439 func (ProcessorLimit) Description() string {
440 return "The number of OS threads that can execute user-level Go code simultaneously."
441 }
442
443 // ScheduleDuration is an instrument used to record metric values conforming to
444 // the "go.schedule.duration" semantic conventions. It represents the time
445 // goroutines have spent in the scheduler in a runnable state before actually
446 // running.
447 type ScheduleDuration struct {
448 metric.Float64Histogram
449 }
450
451 // NewScheduleDuration returns a new ScheduleDuration instrument.
452 func NewScheduleDuration(
453 m metric.Meter,
454 opt ...metric.Float64HistogramOption,
455 ) (ScheduleDuration, error) {
456 // Check if the meter is nil.
457 if m == nil {
458 return ScheduleDuration{noop.Float64Histogram{}}, nil
459 }
460
461 i, err := m.Float64Histogram(
462 "go.schedule.duration",
463 append([]metric.Float64HistogramOption{
464 metric.WithDescription("The time goroutines have spent in the scheduler in a runnable state before actually running."),
465 metric.WithUnit("s"),
466 }, opt...)...,
467 )
468 if err != nil {
469 return ScheduleDuration{noop.Float64Histogram{}}, err
470 }
471 return ScheduleDuration{i}, nil
472 }
473
474 // Inst returns the underlying metric instrument.
475 func (m ScheduleDuration) Inst() metric.Float64Histogram {
476 return m.Float64Histogram
477 }
478
479 // Name returns the semantic convention name of the instrument.
480 func (ScheduleDuration) Name() string {
481 return "go.schedule.duration"
482 }
483
484 // Unit returns the semantic convention unit of the instrument
485 func (ScheduleDuration) Unit() string {
486 return "s"
487 }
488
489 // Description returns the semantic convention description of the instrument
490 func (ScheduleDuration) Description() string {
491 return "The time goroutines have spent in the scheduler in a runnable state before actually running."
492 }
493
494 // Record records val to the current distribution.
495 //
496 // Computed from `/sched/latencies:seconds`. Bucket boundaries are provided by
497 // the runtime, and are subject to change.
498 func (m ScheduleDuration) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
499 if len(attrs) == 0 {
500 m.Float64Histogram.Record(ctx, val)
501 }
502
503 o := recOptPool.Get().(*[]metric.RecordOption)
504 defer func() {
505 *o = (*o)[:0]
506 recOptPool.Put(o)
507 }()
508
509 *o = append(*o, metric.WithAttributes(attrs...))
510 m.Float64Histogram.Record(ctx, val, *o...)
511 }