Debian Codegraph @

semconv/v1.37.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 var newConfigGogcOpts = []metric.Int64ObservableUpDownCounterOption{
45 metric.WithDescription("Heap size target percentage configured by the user, otherwise 100."),
46 metric.WithUnit("%"),
47 }
48
49 // NewConfigGogc returns a new ConfigGogc instrument.
50 func NewConfigGogc(
51 m metric.Meter,
52 opt ...metric.Int64ObservableUpDownCounterOption,
53 ) (ConfigGogc, error) {
54 // Check if the meter is nil.
55 if m == nil {
56 return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, nil
57 }
58
59 if len(opt) == 0 {
60 opt = newConfigGogcOpts
61 } else {
62 opt = append(opt, newConfigGogcOpts...)
63 }
64
65 i, err := m.Int64ObservableUpDownCounter(
66 "go.config.gogc",
67 opt...,
68 )
69 if err != nil {
70 return ConfigGogc{noop.Int64ObservableUpDownCounter{}}, err
71 }
72 return ConfigGogc{i}, nil
73 }
74
75 // Inst returns the underlying metric instrument.
76 func (m ConfigGogc) Inst() metric.Int64ObservableUpDownCounter {
77 return m.Int64ObservableUpDownCounter
78 }
79
80 // Name returns the semantic convention name of the instrument.
81 func (ConfigGogc) Name() string {
82 return "go.config.gogc"
83 }
84
85 // Unit returns the semantic convention unit of the instrument
86 func (ConfigGogc) Unit() string {
87 return "%"
88 }
89
90 // Description returns the semantic convention description of the instrument
91 func (ConfigGogc) Description() string {
92 return "Heap size target percentage configured by the user, otherwise 100."
93 }
94
95 // GoroutineCount is an instrument used to record metric values conforming to the
96 // "go.goroutine.count" semantic conventions. It represents the count of live
97 // goroutines.
98 type GoroutineCount struct {
99 metric.Int64ObservableUpDownCounter
100 }
101
102 var newGoroutineCountOpts = []metric.Int64ObservableUpDownCounterOption{
103 metric.WithDescription("Count of live goroutines."),
104 metric.WithUnit("{goroutine}"),
105 }
106
107 // NewGoroutineCount returns a new GoroutineCount instrument.
108 func NewGoroutineCount(
109 m metric.Meter,
110 opt ...metric.Int64ObservableUpDownCounterOption,
111 ) (GoroutineCount, error) {
112 // Check if the meter is nil.
113 if m == nil {
114 return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, nil
115 }
116
117 if len(opt) == 0 {
118 opt = newGoroutineCountOpts
119 } else {
120 opt = append(opt, newGoroutineCountOpts...)
121 }
122
123 i, err := m.Int64ObservableUpDownCounter(
124 "go.goroutine.count",
125 opt...,
126 )
127 if err != nil {
128 return GoroutineCount{noop.Int64ObservableUpDownCounter{}}, err
129 }
130 return GoroutineCount{i}, nil
131 }
132
133 // Inst returns the underlying metric instrument.
134 func (m GoroutineCount) Inst() metric.Int64ObservableUpDownCounter {
135 return m.Int64ObservableUpDownCounter
136 }
137
138 // Name returns the semantic convention name of the instrument.
139 func (GoroutineCount) Name() string {
140 return "go.goroutine.count"
141 }
142
143 // Unit returns the semantic convention unit of the instrument
144 func (GoroutineCount) Unit() string {
145 return "{goroutine}"
146 }
147
148 // Description returns the semantic convention description of the instrument
149 func (GoroutineCount) Description() string {
150 return "Count of live goroutines."
151 }
152
153 // MemoryAllocated is an instrument used to record metric values conforming to
154 // the "go.memory.allocated" semantic conventions. It represents the memory
155 // allocated to the heap by the application.
156 type MemoryAllocated struct {
157 metric.Int64ObservableCounter
158 }
159
160 var newMemoryAllocatedOpts = []metric.Int64ObservableCounterOption{
161 metric.WithDescription("Memory allocated to the heap by the application."),
162 metric.WithUnit("By"),
163 }
164
165 // NewMemoryAllocated returns a new MemoryAllocated instrument.
166 func NewMemoryAllocated(
167 m metric.Meter,
168 opt ...metric.Int64ObservableCounterOption,
169 ) (MemoryAllocated, error) {
170 // Check if the meter is nil.
171 if m == nil {
172 return MemoryAllocated{noop.Int64ObservableCounter{}}, nil
173 }
174
175 if len(opt) == 0 {
176 opt = newMemoryAllocatedOpts
177 } else {
178 opt = append(opt, newMemoryAllocatedOpts...)
179 }
180
181 i, err := m.Int64ObservableCounter(
182 "go.memory.allocated",
183 opt...,
184 )
185 if err != nil {
186 return MemoryAllocated{noop.Int64ObservableCounter{}}, err
187 }
188 return MemoryAllocated{i}, nil
189 }
190
191 // Inst returns the underlying metric instrument.
192 func (m MemoryAllocated) Inst() metric.Int64ObservableCounter {
193 return m.Int64ObservableCounter
194 }
195
196 // Name returns the semantic convention name of the instrument.
197 func (MemoryAllocated) Name() string {
198 return "go.memory.allocated"
199 }
200
201 // Unit returns the semantic convention unit of the instrument
202 func (MemoryAllocated) Unit() string {
203 return "By"
204 }
205
206 // Description returns the semantic convention description of the instrument
207 func (MemoryAllocated) Description() string {
208 return "Memory allocated to the heap by the application."
209 }
210
211 // MemoryAllocations is an instrument used to record metric values conforming to
212 // the "go.memory.allocations" semantic conventions. It represents the count of
213 // allocations to the heap by the application.
214 type MemoryAllocations struct {
215 metric.Int64ObservableCounter
216 }
217
218 var newMemoryAllocationsOpts = []metric.Int64ObservableCounterOption{
219 metric.WithDescription("Count of allocations to the heap by the application."),
220 metric.WithUnit("{allocation}"),
221 }
222
223 // NewMemoryAllocations returns a new MemoryAllocations instrument.
224 func NewMemoryAllocations(
225 m metric.Meter,
226 opt ...metric.Int64ObservableCounterOption,
227 ) (MemoryAllocations, error) {
228 // Check if the meter is nil.
229 if m == nil {
230 return MemoryAllocations{noop.Int64ObservableCounter{}}, nil
231 }
232
233 if len(opt) == 0 {
234 opt = newMemoryAllocationsOpts
235 } else {
236 opt = append(opt, newMemoryAllocationsOpts...)
237 }
238
239 i, err := m.Int64ObservableCounter(
240 "go.memory.allocations",
241 opt...,
242 )
243 if err != nil {
244 return MemoryAllocations{noop.Int64ObservableCounter{}}, err
245 }
246 return MemoryAllocations{i}, nil
247 }
248
249 // Inst returns the underlying metric instrument.
250 func (m MemoryAllocations) Inst() metric.Int64ObservableCounter {
251 return m.Int64ObservableCounter
252 }
253
254 // Name returns the semantic convention name of the instrument.
255 func (MemoryAllocations) Name() string {
256 return "go.memory.allocations"
257 }
258
259 // Unit returns the semantic convention unit of the instrument
260 func (MemoryAllocations) Unit() string {
261 return "{allocation}"
262 }
263
264 // Description returns the semantic convention description of the instrument
265 func (MemoryAllocations) Description() string {
266 return "Count of allocations to the heap by the application."
267 }
268
269 // MemoryGCGoal is an instrument used to record metric values conforming to the
270 // "go.memory.gc.goal" semantic conventions. It represents the heap size target
271 // for the end of the GC cycle.
272 type MemoryGCGoal struct {
273 metric.Int64ObservableUpDownCounter
274 }
275
276 var newMemoryGCGoalOpts = []metric.Int64ObservableUpDownCounterOption{
277 metric.WithDescription("Heap size target for the end of the GC cycle."),
278 metric.WithUnit("By"),
279 }
280
281 // NewMemoryGCGoal returns a new MemoryGCGoal instrument.
282 func NewMemoryGCGoal(
283 m metric.Meter,
284 opt ...metric.Int64ObservableUpDownCounterOption,
285 ) (MemoryGCGoal, error) {
286 // Check if the meter is nil.
287 if m == nil {
288 return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, nil
289 }
290
291 if len(opt) == 0 {
292 opt = newMemoryGCGoalOpts
293 } else {
294 opt = append(opt, newMemoryGCGoalOpts...)
295 }
296
297 i, err := m.Int64ObservableUpDownCounter(
298 "go.memory.gc.goal",
299 opt...,
300 )
301 if err != nil {
302 return MemoryGCGoal{noop.Int64ObservableUpDownCounter{}}, err
303 }
304 return MemoryGCGoal{i}, nil
305 }
306
307 // Inst returns the underlying metric instrument.
308 func (m MemoryGCGoal) Inst() metric.Int64ObservableUpDownCounter {
309 return m.Int64ObservableUpDownCounter
310 }
311
312 // Name returns the semantic convention name of the instrument.
313 func (MemoryGCGoal) Name() string {
314 return "go.memory.gc.goal"
315 }
316
317 // Unit returns the semantic convention unit of the instrument
318 func (MemoryGCGoal) Unit() string {
319 return "By"
320 }
321
322 // Description returns the semantic convention description of the instrument
323 func (MemoryGCGoal) Description() string {
324 return "Heap size target for the end of the GC cycle."
325 }
326
327 // MemoryLimit is an instrument used to record metric values conforming to the
328 // "go.memory.limit" semantic conventions. It represents the go runtime memory
329 // limit configured by the user, if a limit exists.
330 type MemoryLimit struct {
331 metric.Int64ObservableUpDownCounter
332 }
333
334 var newMemoryLimitOpts = []metric.Int64ObservableUpDownCounterOption{
335 metric.WithDescription("Go runtime memory limit configured by the user, if a limit exists."),
336 metric.WithUnit("By"),
337 }
338
339 // NewMemoryLimit returns a new MemoryLimit instrument.
340 func NewMemoryLimit(
341 m metric.Meter,
342 opt ...metric.Int64ObservableUpDownCounterOption,
343 ) (MemoryLimit, error) {
344 // Check if the meter is nil.
345 if m == nil {
346 return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, nil
347 }
348
349 if len(opt) == 0 {
350 opt = newMemoryLimitOpts
351 } else {
352 opt = append(opt, newMemoryLimitOpts...)
353 }
354
355 i, err := m.Int64ObservableUpDownCounter(
356 "go.memory.limit",
357 opt...,
358 )
359 if err != nil {
360 return MemoryLimit{noop.Int64ObservableUpDownCounter{}}, err
361 }
362 return MemoryLimit{i}, nil
363 }
364
365 // Inst returns the underlying metric instrument.
366 func (m MemoryLimit) Inst() metric.Int64ObservableUpDownCounter {
367 return m.Int64ObservableUpDownCounter
368 }
369
370 // Name returns the semantic convention name of the instrument.
371 func (MemoryLimit) Name() string {
372 return "go.memory.limit"
373 }
374
375 // Unit returns the semantic convention unit of the instrument
376 func (MemoryLimit) Unit() string {
377 return "By"
378 }
379
380 // Description returns the semantic convention description of the instrument
381 func (MemoryLimit) Description() string {
382 return "Go runtime memory limit configured by the user, if a limit exists."
383 }
384
385 // MemoryUsed is an instrument used to record metric values conforming to the
386 // "go.memory.used" semantic conventions. It represents the memory used by the Go
387 // runtime.
388 type MemoryUsed struct {
389 metric.Int64ObservableUpDownCounter
390 }
391
392 var newMemoryUsedOpts = []metric.Int64ObservableUpDownCounterOption{
393 metric.WithDescription("Memory used by the Go runtime."),
394 metric.WithUnit("By"),
395 }
396
397 // NewMemoryUsed returns a new MemoryUsed instrument.
398 func NewMemoryUsed(
399 m metric.Meter,
400 opt ...metric.Int64ObservableUpDownCounterOption,
401 ) (MemoryUsed, error) {
402 // Check if the meter is nil.
403 if m == nil {
404 return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, nil
405 }
406
407 if len(opt) == 0 {
408 opt = newMemoryUsedOpts
409 } else {
410 opt = append(opt, newMemoryUsedOpts...)
411 }
412
413 i, err := m.Int64ObservableUpDownCounter(
414 "go.memory.used",
415 opt...,
416 )
417 if err != nil {
418 return MemoryUsed{noop.Int64ObservableUpDownCounter{}}, err
419 }
420 return MemoryUsed{i}, nil
421 }
422
423 // Inst returns the underlying metric instrument.
424 func (m MemoryUsed) Inst() metric.Int64ObservableUpDownCounter {
425 return m.Int64ObservableUpDownCounter
426 }
427
428 // Name returns the semantic convention name of the instrument.
429 func (MemoryUsed) Name() string {
430 return "go.memory.used"
431 }
432
433 // Unit returns the semantic convention unit of the instrument
434 func (MemoryUsed) Unit() string {
435 return "By"
436 }
437
438 // Description returns the semantic convention description of the instrument
439 func (MemoryUsed) Description() string {
440 return "Memory used by the Go runtime."
441 }
442
443 // AttrMemoryType returns an optional attribute for the "go.memory.type" semantic
444 // convention. It represents the type of memory.
445 func (MemoryUsed) AttrMemoryType(val MemoryTypeAttr) attribute.KeyValue {
446 return attribute.String("go.memory.type", string(val))
447 }
448
449 // ProcessorLimit is an instrument used to record metric values conforming to the
450 // "go.processor.limit" semantic conventions. It represents the number of OS
451 // threads that can execute user-level Go code simultaneously.
452 type ProcessorLimit struct {
453 metric.Int64ObservableUpDownCounter
454 }
455
456 var newProcessorLimitOpts = []metric.Int64ObservableUpDownCounterOption{
457 metric.WithDescription("The number of OS threads that can execute user-level Go code simultaneously."),
458 metric.WithUnit("{thread}"),
459 }
460
461 // NewProcessorLimit returns a new ProcessorLimit instrument.
462 func NewProcessorLimit(
463 m metric.Meter,
464 opt ...metric.Int64ObservableUpDownCounterOption,
465 ) (ProcessorLimit, error) {
466 // Check if the meter is nil.
467 if m == nil {
468 return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, nil
469 }
470
471 if len(opt) == 0 {
472 opt = newProcessorLimitOpts
473 } else {
474 opt = append(opt, newProcessorLimitOpts...)
475 }
476
477 i, err := m.Int64ObservableUpDownCounter(
478 "go.processor.limit",
479 opt...,
480 )
481 if err != nil {
482 return ProcessorLimit{noop.Int64ObservableUpDownCounter{}}, err
483 }
484 return ProcessorLimit{i}, nil
485 }
486
487 // Inst returns the underlying metric instrument.
488 func (m ProcessorLimit) Inst() metric.Int64ObservableUpDownCounter {
489 return m.Int64ObservableUpDownCounter
490 }
491
492 // Name returns the semantic convention name of the instrument.
493 func (ProcessorLimit) Name() string {
494 return "go.processor.limit"
495 }
496
497 // Unit returns the semantic convention unit of the instrument
498 func (ProcessorLimit) Unit() string {
499 return "{thread}"
500 }
501
502 // Description returns the semantic convention description of the instrument
503 func (ProcessorLimit) Description() string {
504 return "The number of OS threads that can execute user-level Go code simultaneously."
505 }
506
507 // ScheduleDuration is an instrument used to record metric values conforming to
508 // the "go.schedule.duration" semantic conventions. It represents the time
509 // goroutines have spent in the scheduler in a runnable state before actually
510 // running.
511 type ScheduleDuration struct {
512 metric.Float64Histogram
513 }
514
515 var newScheduleDurationOpts = []metric.Float64HistogramOption{
516 metric.WithDescription("The time goroutines have spent in the scheduler in a runnable state before actually running."),
517 metric.WithUnit("s"),
518 }
519
520 // NewScheduleDuration returns a new ScheduleDuration instrument.
521 func NewScheduleDuration(
522 m metric.Meter,
523 opt ...metric.Float64HistogramOption,
524 ) (ScheduleDuration, error) {
525 // Check if the meter is nil.
526 if m == nil {
527 return ScheduleDuration{noop.Float64Histogram{}}, nil
528 }
529
530 if len(opt) == 0 {
531 opt = newScheduleDurationOpts
532 } else {
533 opt = append(opt, newScheduleDurationOpts...)
534 }
535
536 i, err := m.Float64Histogram(
537 "go.schedule.duration",
538 opt...,
539 )
540 if err != nil {
541 return ScheduleDuration{noop.Float64Histogram{}}, err
542 }
543 return ScheduleDuration{i}, nil
544 }
545
546 // Inst returns the underlying metric instrument.
547 func (m ScheduleDuration) Inst() metric.Float64Histogram {
548 return m.Float64Histogram
549 }
550
551 // Name returns the semantic convention name of the instrument.
552 func (ScheduleDuration) Name() string {
553 return "go.schedule.duration"
554 }
555
556 // Unit returns the semantic convention unit of the instrument
557 func (ScheduleDuration) Unit() string {
558 return "s"
559 }
560
561 // Description returns the semantic convention description of the instrument
562 func (ScheduleDuration) Description() string {
563 return "The time goroutines have spent in the scheduler in a runnable state before actually running."
564 }
565
566 // Record records val to the current distribution for attrs.
567 //
568 // Computed from `/sched/latencies:seconds`. Bucket boundaries are provided by
569 // the runtime, and are subject to change.
570 func (m ScheduleDuration) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
571 if len(attrs) == 0 {
572 m.Float64Histogram.Record(ctx, val)
573 return
574 }
575
576 o := recOptPool.Get().(*[]metric.RecordOption)
577 defer func() {
578 *o = (*o)[:0]
579 recOptPool.Put(o)
580 }()
581
582 *o = append(*o, metric.WithAttributes(attrs...))
583 m.Float64Histogram.Record(ctx, val, *o...)
584 }
585
586 // RecordSet records val to the current distribution for set.
587 //
588 // Computed from `/sched/latencies:seconds`. Bucket boundaries are provided by
589 // the runtime, and are subject to change.
590 func (m ScheduleDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
591 if set.Len() == 0 {
592 m.Float64Histogram.Record(ctx, val)
593 return
594 }
595
596 o := recOptPool.Get().(*[]metric.RecordOption)
597 defer func() {
598 *o = (*o)[:0]
599 recOptPool.Put(o)
600 }()
601
602 *o = append(*o, metric.WithAttributeSet(set))
603 m.Float64Histogram.Record(ctx, val, *o...)
604 }