Debian Codegraph @

semconv/v1.39.0/processconv/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 processconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "process" namespace.
8 package processconv
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 // CPUModeAttr is an attribute conforming to the cpu.mode semantic conventions.
25 // It represents a process SHOULD be characterized *either* by data points with
26 // no `mode` labels, *or only* data points with `mode` labels.
27 type CPUModeAttr string
28
29 var (
30 // CPUModeUser is the user.
31 CPUModeUser CPUModeAttr = "user"
32 // CPUModeSystem is the system.
33 CPUModeSystem CPUModeAttr = "system"
34 // CPUModeNice is the nice.
35 CPUModeNice CPUModeAttr = "nice"
36 // CPUModeIdle is the idle.
37 CPUModeIdle CPUModeAttr = "idle"
38 // CPUModeIOWait is the IO Wait.
39 CPUModeIOWait CPUModeAttr = "iowait"
40 // CPUModeInterrupt is the interrupt.
41 CPUModeInterrupt CPUModeAttr = "interrupt"
42 // CPUModeSteal is the steal.
43 CPUModeSteal CPUModeAttr = "steal"
44 // CPUModeKernel is the kernel.
45 CPUModeKernel CPUModeAttr = "kernel"
46 )
47
48 // DiskIODirectionAttr is an attribute conforming to the disk.io.direction
49 // semantic conventions. It represents the disk IO operation direction.
50 type DiskIODirectionAttr string
51
52 var (
53 // DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr.
54 DiskIODirectionRead DiskIODirectionAttr = "read"
55 // DiskIODirectionWrite is the standardized value "write" of
56 // DiskIODirectionAttr.
57 DiskIODirectionWrite DiskIODirectionAttr = "write"
58 )
59
60 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
61 // semantic conventions. It represents the network IO operation direction.
62 type NetworkIODirectionAttr string
63
64 var (
65 // NetworkIODirectionTransmit is the standardized value "transmit" of
66 // NetworkIODirectionAttr.
67 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
68 // NetworkIODirectionReceive is the standardized value "receive" of
69 // NetworkIODirectionAttr.
70 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
71 )
72
73 // ContextSwitchTypeAttr is an attribute conforming to the
74 // process.context_switch.type semantic conventions. It represents the specifies
75 // whether the context switches for this data point were voluntary or
76 // involuntary.
77 type ContextSwitchTypeAttr string
78
79 var (
80 // ContextSwitchTypeVoluntary is the standardized value "voluntary" of
81 // ContextSwitchTypeAttr.
82 ContextSwitchTypeVoluntary ContextSwitchTypeAttr = "voluntary"
83 // ContextSwitchTypeInvoluntary is the standardized value "involuntary" of
84 // ContextSwitchTypeAttr.
85 ContextSwitchTypeInvoluntary ContextSwitchTypeAttr = "involuntary"
86 )
87
88 // SystemPagingFaultTypeAttr is an attribute conforming to the
89 // system.paging.fault.type semantic conventions. It represents the paging fault
90 // type.
91 type SystemPagingFaultTypeAttr string
92
93 var (
94 // SystemPagingFaultTypeMajor is the standardized value "major" of
95 // SystemPagingFaultTypeAttr.
96 SystemPagingFaultTypeMajor SystemPagingFaultTypeAttr = "major"
97 // SystemPagingFaultTypeMinor is the standardized value "minor" of
98 // SystemPagingFaultTypeAttr.
99 SystemPagingFaultTypeMinor SystemPagingFaultTypeAttr = "minor"
100 )
101
102 // ContextSwitches is an instrument used to record metric values conforming to
103 // the "process.context_switches" semantic conventions. It represents the number
104 // of times the process has been context switched.
105 type ContextSwitches struct {
106 metric.Int64Counter
107 }
108
109 var newContextSwitchesOpts = []metric.Int64CounterOption{
110 metric.WithDescription("Number of times the process has been context switched."),
111 metric.WithUnit("{context_switch}"),
112 }
113
114 // NewContextSwitches returns a new ContextSwitches instrument.
115 func NewContextSwitches(
116 m metric.Meter,
117 opt ...metric.Int64CounterOption,
118 ) (ContextSwitches, error) {
119 // Check if the meter is nil.
120 if m == nil {
121 return ContextSwitches{noop.Int64Counter{}}, nil
122 }
123
124 if len(opt) == 0 {
125 opt = newContextSwitchesOpts
126 } else {
127 opt = append(opt, newContextSwitchesOpts...)
128 }
129
130 i, err := m.Int64Counter(
131 "process.context_switches",
132 opt...,
133 )
134 if err != nil {
135 return ContextSwitches{noop.Int64Counter{}}, err
136 }
137 return ContextSwitches{i}, nil
138 }
139
140 // Inst returns the underlying metric instrument.
141 func (m ContextSwitches) Inst() metric.Int64Counter {
142 return m.Int64Counter
143 }
144
145 // Name returns the semantic convention name of the instrument.
146 func (ContextSwitches) Name() string {
147 return "process.context_switches"
148 }
149
150 // Unit returns the semantic convention unit of the instrument
151 func (ContextSwitches) Unit() string {
152 return "{context_switch}"
153 }
154
155 // Description returns the semantic convention description of the instrument
156 func (ContextSwitches) Description() string {
157 return "Number of times the process has been context switched."
158 }
159
160 // Add adds incr to the existing count for attrs.
161 //
162 // All additional attrs passed are included in the recorded value.
163 func (m ContextSwitches) Add(
164 ctx context.Context,
165 incr int64,
166 attrs ...attribute.KeyValue,
167 ) {
168 if len(attrs) == 0 {
169 m.Int64Counter.Add(ctx, incr)
170 return
171 }
172
173 o := addOptPool.Get().(*[]metric.AddOption)
174 defer func() {
175 *o = (*o)[:0]
176 addOptPool.Put(o)
177 }()
178
179 *o = append(
180 *o,
181 metric.WithAttributes(
182 attrs...,
183 ),
184 )
185
186 m.Int64Counter.Add(ctx, incr, *o...)
187 }
188
189 // AddSet adds incr to the existing count for set.
190 func (m ContextSwitches) AddSet(ctx context.Context, incr int64, set attribute.Set) {
191 if set.Len() == 0 {
192 m.Int64Counter.Add(ctx, incr)
193 return
194 }
195
196 o := addOptPool.Get().(*[]metric.AddOption)
197 defer func() {
198 *o = (*o)[:0]
199 addOptPool.Put(o)
200 }()
201
202 *o = append(*o, metric.WithAttributeSet(set))
203 m.Int64Counter.Add(ctx, incr, *o...)
204 }
205
206 // AttrContextSwitchType returns an optional attribute for the
207 // "process.context_switch.type" semantic convention. It represents the specifies
208 // whether the context switches for this data point were voluntary or
209 // involuntary.
210 func (ContextSwitches) AttrContextSwitchType(val ContextSwitchTypeAttr) attribute.KeyValue {
211 return attribute.String("process.context_switch.type", string(val))
212 }
213
214 // CPUTime is an instrument used to record metric values conforming to the
215 // "process.cpu.time" semantic conventions. It represents the total CPU seconds
216 // broken down by different states.
217 type CPUTime struct {
218 metric.Float64ObservableCounter
219 }
220
221 var newCPUTimeOpts = []metric.Float64ObservableCounterOption{
222 metric.WithDescription("Total CPU seconds broken down by different states."),
223 metric.WithUnit("s"),
224 }
225
226 // NewCPUTime returns a new CPUTime instrument.
227 func NewCPUTime(
228 m metric.Meter,
229 opt ...metric.Float64ObservableCounterOption,
230 ) (CPUTime, error) {
231 // Check if the meter is nil.
232 if m == nil {
233 return CPUTime{noop.Float64ObservableCounter{}}, nil
234 }
235
236 if len(opt) == 0 {
237 opt = newCPUTimeOpts
238 } else {
239 opt = append(opt, newCPUTimeOpts...)
240 }
241
242 i, err := m.Float64ObservableCounter(
243 "process.cpu.time",
244 opt...,
245 )
246 if err != nil {
247 return CPUTime{noop.Float64ObservableCounter{}}, err
248 }
249 return CPUTime{i}, nil
250 }
251
252 // Inst returns the underlying metric instrument.
253 func (m CPUTime) Inst() metric.Float64ObservableCounter {
254 return m.Float64ObservableCounter
255 }
256
257 // Name returns the semantic convention name of the instrument.
258 func (CPUTime) Name() string {
259 return "process.cpu.time"
260 }
261
262 // Unit returns the semantic convention unit of the instrument
263 func (CPUTime) Unit() string {
264 return "s"
265 }
266
267 // Description returns the semantic convention description of the instrument
268 func (CPUTime) Description() string {
269 return "Total CPU seconds broken down by different states."
270 }
271
272 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
273 // convention. It represents a process SHOULD be characterized *either* by data
274 // points with no `mode` labels, *or only* data points with `mode` labels.
275 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
276 return attribute.String("cpu.mode", string(val))
277 }
278
279 // CPUUtilization is an instrument used to record metric values conforming to the
280 // "process.cpu.utilization" semantic conventions. It represents the difference
281 // in process.cpu.time since the last measurement, divided by the elapsed time
282 // and number of CPUs available to the process.
283 type CPUUtilization struct {
284 metric.Int64Gauge
285 }
286
287 var newCPUUtilizationOpts = []metric.Int64GaugeOption{
288 metric.WithDescription("Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process."),
289 metric.WithUnit("1"),
290 }
291
292 // NewCPUUtilization returns a new CPUUtilization instrument.
293 func NewCPUUtilization(
294 m metric.Meter,
295 opt ...metric.Int64GaugeOption,
296 ) (CPUUtilization, error) {
297 // Check if the meter is nil.
298 if m == nil {
299 return CPUUtilization{noop.Int64Gauge{}}, nil
300 }
301
302 if len(opt) == 0 {
303 opt = newCPUUtilizationOpts
304 } else {
305 opt = append(opt, newCPUUtilizationOpts...)
306 }
307
308 i, err := m.Int64Gauge(
309 "process.cpu.utilization",
310 opt...,
311 )
312 if err != nil {
313 return CPUUtilization{noop.Int64Gauge{}}, err
314 }
315 return CPUUtilization{i}, nil
316 }
317
318 // Inst returns the underlying metric instrument.
319 func (m CPUUtilization) Inst() metric.Int64Gauge {
320 return m.Int64Gauge
321 }
322
323 // Name returns the semantic convention name of the instrument.
324 func (CPUUtilization) Name() string {
325 return "process.cpu.utilization"
326 }
327
328 // Unit returns the semantic convention unit of the instrument
329 func (CPUUtilization) Unit() string {
330 return "1"
331 }
332
333 // Description returns the semantic convention description of the instrument
334 func (CPUUtilization) Description() string {
335 return "Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process."
336 }
337
338 // Record records val to the current distribution for attrs.
339 //
340 // All additional attrs passed are included in the recorded value.
341 func (m CPUUtilization) Record(
342 ctx context.Context,
343 val int64,
344 attrs ...attribute.KeyValue,
345 ) {
346 if len(attrs) == 0 {
347 m.Int64Gauge.Record(ctx, val)
348 return
349 }
350
351 o := recOptPool.Get().(*[]metric.RecordOption)
352 defer func() {
353 *o = (*o)[:0]
354 recOptPool.Put(o)
355 }()
356
357 *o = append(
358 *o,
359 metric.WithAttributes(
360 attrs...,
361 ),
362 )
363
364 m.Int64Gauge.Record(ctx, val, *o...)
365 }
366
367 // RecordSet records val to the current distribution for set.
368 func (m CPUUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) {
369 if set.Len() == 0 {
370 m.Int64Gauge.Record(ctx, val)
371 return
372 }
373
374 o := recOptPool.Get().(*[]metric.RecordOption)
375 defer func() {
376 *o = (*o)[:0]
377 recOptPool.Put(o)
378 }()
379
380 *o = append(*o, metric.WithAttributeSet(set))
381 m.Int64Gauge.Record(ctx, val, *o...)
382 }
383
384 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
385 // convention. It represents a process SHOULD be characterized *either* by data
386 // points with no `mode` labels, *or only* data points with `mode` labels.
387 func (CPUUtilization) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
388 return attribute.String("cpu.mode", string(val))
389 }
390
391 // DiskIO is an instrument used to record metric values conforming to the
392 // "process.disk.io" semantic conventions. It represents the disk bytes
393 // transferred.
394 type DiskIO struct {
395 metric.Int64Counter
396 }
397
398 var newDiskIOOpts = []metric.Int64CounterOption{
399 metric.WithDescription("Disk bytes transferred."),
400 metric.WithUnit("By"),
401 }
402
403 // NewDiskIO returns a new DiskIO instrument.
404 func NewDiskIO(
405 m metric.Meter,
406 opt ...metric.Int64CounterOption,
407 ) (DiskIO, error) {
408 // Check if the meter is nil.
409 if m == nil {
410 return DiskIO{noop.Int64Counter{}}, nil
411 }
412
413 if len(opt) == 0 {
414 opt = newDiskIOOpts
415 } else {
416 opt = append(opt, newDiskIOOpts...)
417 }
418
419 i, err := m.Int64Counter(
420 "process.disk.io",
421 opt...,
422 )
423 if err != nil {
424 return DiskIO{noop.Int64Counter{}}, err
425 }
426 return DiskIO{i}, nil
427 }
428
429 // Inst returns the underlying metric instrument.
430 func (m DiskIO) Inst() metric.Int64Counter {
431 return m.Int64Counter
432 }
433
434 // Name returns the semantic convention name of the instrument.
435 func (DiskIO) Name() string {
436 return "process.disk.io"
437 }
438
439 // Unit returns the semantic convention unit of the instrument
440 func (DiskIO) Unit() string {
441 return "By"
442 }
443
444 // Description returns the semantic convention description of the instrument
445 func (DiskIO) Description() string {
446 return "Disk bytes transferred."
447 }
448
449 // Add adds incr to the existing count for attrs.
450 //
451 // All additional attrs passed are included in the recorded value.
452 func (m DiskIO) Add(
453 ctx context.Context,
454 incr int64,
455 attrs ...attribute.KeyValue,
456 ) {
457 if len(attrs) == 0 {
458 m.Int64Counter.Add(ctx, incr)
459 return
460 }
461
462 o := addOptPool.Get().(*[]metric.AddOption)
463 defer func() {
464 *o = (*o)[:0]
465 addOptPool.Put(o)
466 }()
467
468 *o = append(
469 *o,
470 metric.WithAttributes(
471 attrs...,
472 ),
473 )
474
475 m.Int64Counter.Add(ctx, incr, *o...)
476 }
477
478 // AddSet adds incr to the existing count for set.
479 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
480 if set.Len() == 0 {
481 m.Int64Counter.Add(ctx, incr)
482 return
483 }
484
485 o := addOptPool.Get().(*[]metric.AddOption)
486 defer func() {
487 *o = (*o)[:0]
488 addOptPool.Put(o)
489 }()
490
491 *o = append(*o, metric.WithAttributeSet(set))
492 m.Int64Counter.Add(ctx, incr, *o...)
493 }
494
495 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
496 // semantic convention. It represents the disk IO operation direction.
497 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
498 return attribute.String("disk.io.direction", string(val))
499 }
500
501 // MemoryUsage is an instrument used to record metric values conforming to the
502 // "process.memory.usage" semantic conventions. It represents the amount of
503 // physical memory in use.
504 type MemoryUsage struct {
505 metric.Int64UpDownCounter
506 }
507
508 var newMemoryUsageOpts = []metric.Int64UpDownCounterOption{
509 metric.WithDescription("The amount of physical memory in use."),
510 metric.WithUnit("By"),
511 }
512
513 // NewMemoryUsage returns a new MemoryUsage instrument.
514 func NewMemoryUsage(
515 m metric.Meter,
516 opt ...metric.Int64UpDownCounterOption,
517 ) (MemoryUsage, error) {
518 // Check if the meter is nil.
519 if m == nil {
520 return MemoryUsage{noop.Int64UpDownCounter{}}, nil
521 }
522
523 if len(opt) == 0 {
524 opt = newMemoryUsageOpts
525 } else {
526 opt = append(opt, newMemoryUsageOpts...)
527 }
528
529 i, err := m.Int64UpDownCounter(
530 "process.memory.usage",
531 opt...,
532 )
533 if err != nil {
534 return MemoryUsage{noop.Int64UpDownCounter{}}, err
535 }
536 return MemoryUsage{i}, nil
537 }
538
539 // Inst returns the underlying metric instrument.
540 func (m MemoryUsage) Inst() metric.Int64UpDownCounter {
541 return m.Int64UpDownCounter
542 }
543
544 // Name returns the semantic convention name of the instrument.
545 func (MemoryUsage) Name() string {
546 return "process.memory.usage"
547 }
548
549 // Unit returns the semantic convention unit of the instrument
550 func (MemoryUsage) Unit() string {
551 return "By"
552 }
553
554 // Description returns the semantic convention description of the instrument
555 func (MemoryUsage) Description() string {
556 return "The amount of physical memory in use."
557 }
558
559 // Add adds incr to the existing count for attrs.
560 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
561 if len(attrs) == 0 {
562 m.Int64UpDownCounter.Add(ctx, incr)
563 return
564 }
565
566 o := addOptPool.Get().(*[]metric.AddOption)
567 defer func() {
568 *o = (*o)[:0]
569 addOptPool.Put(o)
570 }()
571
572 *o = append(*o, metric.WithAttributes(attrs...))
573 m.Int64UpDownCounter.Add(ctx, incr, *o...)
574 }
575
576 // AddSet adds incr to the existing count for set.
577 func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
578 if set.Len() == 0 {
579 m.Int64UpDownCounter.Add(ctx, incr)
580 return
581 }
582
583 o := addOptPool.Get().(*[]metric.AddOption)
584 defer func() {
585 *o = (*o)[:0]
586 addOptPool.Put(o)
587 }()
588
589 *o = append(*o, metric.WithAttributeSet(set))
590 m.Int64UpDownCounter.Add(ctx, incr, *o...)
591 }
592
593 // MemoryVirtual is an instrument used to record metric values conforming to the
594 // "process.memory.virtual" semantic conventions. It represents the amount of
595 // committed virtual memory.
596 type MemoryVirtual struct {
597 metric.Int64UpDownCounter
598 }
599
600 var newMemoryVirtualOpts = []metric.Int64UpDownCounterOption{
601 metric.WithDescription("The amount of committed virtual memory."),
602 metric.WithUnit("By"),
603 }
604
605 // NewMemoryVirtual returns a new MemoryVirtual instrument.
606 func NewMemoryVirtual(
607 m metric.Meter,
608 opt ...metric.Int64UpDownCounterOption,
609 ) (MemoryVirtual, error) {
610 // Check if the meter is nil.
611 if m == nil {
612 return MemoryVirtual{noop.Int64UpDownCounter{}}, nil
613 }
614
615 if len(opt) == 0 {
616 opt = newMemoryVirtualOpts
617 } else {
618 opt = append(opt, newMemoryVirtualOpts...)
619 }
620
621 i, err := m.Int64UpDownCounter(
622 "process.memory.virtual",
623 opt...,
624 )
625 if err != nil {
626 return MemoryVirtual{noop.Int64UpDownCounter{}}, err
627 }
628 return MemoryVirtual{i}, nil
629 }
630
631 // Inst returns the underlying metric instrument.
632 func (m MemoryVirtual) Inst() metric.Int64UpDownCounter {
633 return m.Int64UpDownCounter
634 }
635
636 // Name returns the semantic convention name of the instrument.
637 func (MemoryVirtual) Name() string {
638 return "process.memory.virtual"
639 }
640
641 // Unit returns the semantic convention unit of the instrument
642 func (MemoryVirtual) Unit() string {
643 return "By"
644 }
645
646 // Description returns the semantic convention description of the instrument
647 func (MemoryVirtual) Description() string {
648 return "The amount of committed virtual memory."
649 }
650
651 // Add adds incr to the existing count for attrs.
652 func (m MemoryVirtual) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
653 if len(attrs) == 0 {
654 m.Int64UpDownCounter.Add(ctx, incr)
655 return
656 }
657
658 o := addOptPool.Get().(*[]metric.AddOption)
659 defer func() {
660 *o = (*o)[:0]
661 addOptPool.Put(o)
662 }()
663
664 *o = append(*o, metric.WithAttributes(attrs...))
665 m.Int64UpDownCounter.Add(ctx, incr, *o...)
666 }
667
668 // AddSet adds incr to the existing count for set.
669 func (m MemoryVirtual) AddSet(ctx context.Context, incr int64, set attribute.Set) {
670 if set.Len() == 0 {
671 m.Int64UpDownCounter.Add(ctx, incr)
672 return
673 }
674
675 o := addOptPool.Get().(*[]metric.AddOption)
676 defer func() {
677 *o = (*o)[:0]
678 addOptPool.Put(o)
679 }()
680
681 *o = append(*o, metric.WithAttributeSet(set))
682 m.Int64UpDownCounter.Add(ctx, incr, *o...)
683 }
684
685 // NetworkIO is an instrument used to record metric values conforming to the
686 // "process.network.io" semantic conventions. It represents the network bytes
687 // transferred.
688 type NetworkIO struct {
689 metric.Int64Counter
690 }
691
692 var newNetworkIOOpts = []metric.Int64CounterOption{
693 metric.WithDescription("Network bytes transferred."),
694 metric.WithUnit("By"),
695 }
696
697 // NewNetworkIO returns a new NetworkIO instrument.
698 func NewNetworkIO(
699 m metric.Meter,
700 opt ...metric.Int64CounterOption,
701 ) (NetworkIO, error) {
702 // Check if the meter is nil.
703 if m == nil {
704 return NetworkIO{noop.Int64Counter{}}, nil
705 }
706
707 if len(opt) == 0 {
708 opt = newNetworkIOOpts
709 } else {
710 opt = append(opt, newNetworkIOOpts...)
711 }
712
713 i, err := m.Int64Counter(
714 "process.network.io",
715 opt...,
716 )
717 if err != nil {
718 return NetworkIO{noop.Int64Counter{}}, err
719 }
720 return NetworkIO{i}, nil
721 }
722
723 // Inst returns the underlying metric instrument.
724 func (m NetworkIO) Inst() metric.Int64Counter {
725 return m.Int64Counter
726 }
727
728 // Name returns the semantic convention name of the instrument.
729 func (NetworkIO) Name() string {
730 return "process.network.io"
731 }
732
733 // Unit returns the semantic convention unit of the instrument
734 func (NetworkIO) Unit() string {
735 return "By"
736 }
737
738 // Description returns the semantic convention description of the instrument
739 func (NetworkIO) Description() string {
740 return "Network bytes transferred."
741 }
742
743 // Add adds incr to the existing count for attrs.
744 //
745 // All additional attrs passed are included in the recorded value.
746 func (m NetworkIO) Add(
747 ctx context.Context,
748 incr int64,
749 attrs ...attribute.KeyValue,
750 ) {
751 if len(attrs) == 0 {
752 m.Int64Counter.Add(ctx, incr)
753 return
754 }
755
756 o := addOptPool.Get().(*[]metric.AddOption)
757 defer func() {
758 *o = (*o)[:0]
759 addOptPool.Put(o)
760 }()
761
762 *o = append(
763 *o,
764 metric.WithAttributes(
765 attrs...,
766 ),
767 )
768
769 m.Int64Counter.Add(ctx, incr, *o...)
770 }
771
772 // AddSet adds incr to the existing count for set.
773 func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
774 if set.Len() == 0 {
775 m.Int64Counter.Add(ctx, incr)
776 return
777 }
778
779 o := addOptPool.Get().(*[]metric.AddOption)
780 defer func() {
781 *o = (*o)[:0]
782 addOptPool.Put(o)
783 }()
784
785 *o = append(*o, metric.WithAttributeSet(set))
786 m.Int64Counter.Add(ctx, incr, *o...)
787 }
788
789 // AttrNetworkIODirection returns an optional attribute for the
790 // "network.io.direction" semantic convention. It represents the network IO
791 // operation direction.
792 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
793 return attribute.String("network.io.direction", string(val))
794 }
795
796 // PagingFaults is an instrument used to record metric values conforming to the
797 // "process.paging.faults" semantic conventions. It represents the number of page
798 // faults the process has made.
799 type PagingFaults struct {
800 metric.Int64Counter
801 }
802
803 var newPagingFaultsOpts = []metric.Int64CounterOption{
804 metric.WithDescription("Number of page faults the process has made."),
805 metric.WithUnit("{fault}"),
806 }
807
808 // NewPagingFaults returns a new PagingFaults instrument.
809 func NewPagingFaults(
810 m metric.Meter,
811 opt ...metric.Int64CounterOption,
812 ) (PagingFaults, error) {
813 // Check if the meter is nil.
814 if m == nil {
815 return PagingFaults{noop.Int64Counter{}}, nil
816 }
817
818 if len(opt) == 0 {
819 opt = newPagingFaultsOpts
820 } else {
821 opt = append(opt, newPagingFaultsOpts...)
822 }
823
824 i, err := m.Int64Counter(
825 "process.paging.faults",
826 opt...,
827 )
828 if err != nil {
829 return PagingFaults{noop.Int64Counter{}}, err
830 }
831 return PagingFaults{i}, nil
832 }
833
834 // Inst returns the underlying metric instrument.
835 func (m PagingFaults) Inst() metric.Int64Counter {
836 return m.Int64Counter
837 }
838
839 // Name returns the semantic convention name of the instrument.
840 func (PagingFaults) Name() string {
841 return "process.paging.faults"
842 }
843
844 // Unit returns the semantic convention unit of the instrument
845 func (PagingFaults) Unit() string {
846 return "{fault}"
847 }
848
849 // Description returns the semantic convention description of the instrument
850 func (PagingFaults) Description() string {
851 return "Number of page faults the process has made."
852 }
853
854 // Add adds incr to the existing count for attrs.
855 //
856 // All additional attrs passed are included in the recorded value.
857 func (m PagingFaults) Add(
858 ctx context.Context,
859 incr int64,
860 attrs ...attribute.KeyValue,
861 ) {
862 if len(attrs) == 0 {
863 m.Int64Counter.Add(ctx, incr)
864 return
865 }
866
867 o := addOptPool.Get().(*[]metric.AddOption)
868 defer func() {
869 *o = (*o)[:0]
870 addOptPool.Put(o)
871 }()
872
873 *o = append(
874 *o,
875 metric.WithAttributes(
876 attrs...,
877 ),
878 )
879
880 m.Int64Counter.Add(ctx, incr, *o...)
881 }
882
883 // AddSet adds incr to the existing count for set.
884 func (m PagingFaults) AddSet(ctx context.Context, incr int64, set attribute.Set) {
885 if set.Len() == 0 {
886 m.Int64Counter.Add(ctx, incr)
887 return
888 }
889
890 o := addOptPool.Get().(*[]metric.AddOption)
891 defer func() {
892 *o = (*o)[:0]
893 addOptPool.Put(o)
894 }()
895
896 *o = append(*o, metric.WithAttributeSet(set))
897 m.Int64Counter.Add(ctx, incr, *o...)
898 }
899
900 // AttrSystemPagingFaultType returns an optional attribute for the
901 // "system.paging.fault.type" semantic convention. It represents the paging fault
902 // type.
903 func (PagingFaults) AttrSystemPagingFaultType(val SystemPagingFaultTypeAttr) attribute.KeyValue {
904 return attribute.String("system.paging.fault.type", string(val))
905 }
906
907 // ThreadCount is an instrument used to record metric values conforming to the
908 // "process.thread.count" semantic conventions. It represents the process threads
909 // count.
910 type ThreadCount struct {
911 metric.Int64UpDownCounter
912 }
913
914 var newThreadCountOpts = []metric.Int64UpDownCounterOption{
915 metric.WithDescription("Process threads count."),
916 metric.WithUnit("{thread}"),
917 }
918
919 // NewThreadCount returns a new ThreadCount instrument.
920 func NewThreadCount(
921 m metric.Meter,
922 opt ...metric.Int64UpDownCounterOption,
923 ) (ThreadCount, error) {
924 // Check if the meter is nil.
925 if m == nil {
926 return ThreadCount{noop.Int64UpDownCounter{}}, nil
927 }
928
929 if len(opt) == 0 {
930 opt = newThreadCountOpts
931 } else {
932 opt = append(opt, newThreadCountOpts...)
933 }
934
935 i, err := m.Int64UpDownCounter(
936 "process.thread.count",
937 opt...,
938 )
939 if err != nil {
940 return ThreadCount{noop.Int64UpDownCounter{}}, err
941 }
942 return ThreadCount{i}, nil
943 }
944
945 // Inst returns the underlying metric instrument.
946 func (m ThreadCount) Inst() metric.Int64UpDownCounter {
947 return m.Int64UpDownCounter
948 }
949
950 // Name returns the semantic convention name of the instrument.
951 func (ThreadCount) Name() string {
952 return "process.thread.count"
953 }
954
955 // Unit returns the semantic convention unit of the instrument
956 func (ThreadCount) Unit() string {
957 return "{thread}"
958 }
959
960 // Description returns the semantic convention description of the instrument
961 func (ThreadCount) Description() string {
962 return "Process threads count."
963 }
964
965 // Add adds incr to the existing count for attrs.
966 func (m ThreadCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
967 if len(attrs) == 0 {
968 m.Int64UpDownCounter.Add(ctx, incr)
969 return
970 }
971
972 o := addOptPool.Get().(*[]metric.AddOption)
973 defer func() {
974 *o = (*o)[:0]
975 addOptPool.Put(o)
976 }()
977
978 *o = append(*o, metric.WithAttributes(attrs...))
979 m.Int64UpDownCounter.Add(ctx, incr, *o...)
980 }
981
982 // AddSet adds incr to the existing count for set.
983 func (m ThreadCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
984 if set.Len() == 0 {
985 m.Int64UpDownCounter.Add(ctx, incr)
986 return
987 }
988
989 o := addOptPool.Get().(*[]metric.AddOption)
990 defer func() {
991 *o = (*o)[:0]
992 addOptPool.Put(o)
993 }()
994
995 *o = append(*o, metric.WithAttributeSet(set))
996 m.Int64UpDownCounter.Add(ctx, incr, *o...)
997 }
998
999 // UnixFileDescriptorCount is an instrument used to record metric values
1000 // conforming to the "process.unix.file_descriptor.count" semantic conventions.
1001 // It represents the number of unix file descriptors in use by the process.
1002 type UnixFileDescriptorCount struct {
1003 metric.Int64UpDownCounter
1004 }
1005
1006 var newUnixFileDescriptorCountOpts = []metric.Int64UpDownCounterOption{
1007 metric.WithDescription("Number of unix file descriptors in use by the process."),
1008 metric.WithUnit("{file_descriptor}"),
1009 }
1010
1011 // NewUnixFileDescriptorCount returns a new UnixFileDescriptorCount instrument.
1012 func NewUnixFileDescriptorCount(
1013 m metric.Meter,
1014 opt ...metric.Int64UpDownCounterOption,
1015 ) (UnixFileDescriptorCount, error) {
1016 // Check if the meter is nil.
1017 if m == nil {
1018 return UnixFileDescriptorCount{noop.Int64UpDownCounter{}}, nil
1019 }
1020
1021 if len(opt) == 0 {
1022 opt = newUnixFileDescriptorCountOpts
1023 } else {
1024 opt = append(opt, newUnixFileDescriptorCountOpts...)
1025 }
1026
1027 i, err := m.Int64UpDownCounter(
1028 "process.unix.file_descriptor.count",
1029 opt...,
1030 )
1031 if err != nil {
1032 return UnixFileDescriptorCount{noop.Int64UpDownCounter{}}, err
1033 }
1034 return UnixFileDescriptorCount{i}, nil
1035 }
1036
1037 // Inst returns the underlying metric instrument.
1038 func (m UnixFileDescriptorCount) Inst() metric.Int64UpDownCounter {
1039 return m.Int64UpDownCounter
1040 }
1041
1042 // Name returns the semantic convention name of the instrument.
1043 func (UnixFileDescriptorCount) Name() string {
1044 return "process.unix.file_descriptor.count"
1045 }
1046
1047 // Unit returns the semantic convention unit of the instrument
1048 func (UnixFileDescriptorCount) Unit() string {
1049 return "{file_descriptor}"
1050 }
1051
1052 // Description returns the semantic convention description of the instrument
1053 func (UnixFileDescriptorCount) Description() string {
1054 return "Number of unix file descriptors in use by the process."
1055 }
1056
1057 // Add adds incr to the existing count for attrs.
1058 func (m UnixFileDescriptorCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1059 if len(attrs) == 0 {
1060 m.Int64UpDownCounter.Add(ctx, incr)
1061 return
1062 }
1063
1064 o := addOptPool.Get().(*[]metric.AddOption)
1065 defer func() {
1066 *o = (*o)[:0]
1067 addOptPool.Put(o)
1068 }()
1069
1070 *o = append(*o, metric.WithAttributes(attrs...))
1071 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1072 }
1073
1074 // AddSet adds incr to the existing count for set.
1075 func (m UnixFileDescriptorCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1076 if set.Len() == 0 {
1077 m.Int64UpDownCounter.Add(ctx, incr)
1078 return
1079 }
1080
1081 o := addOptPool.Get().(*[]metric.AddOption)
1082 defer func() {
1083 *o = (*o)[:0]
1084 addOptPool.Put(o)
1085 }()
1086
1087 *o = append(*o, metric.WithAttributeSet(set))
1088 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1089 }
1090
1091 // Uptime is an instrument used to record metric values conforming to the
1092 // "process.uptime" semantic conventions. It represents the time the process has
1093 // been running.
1094 type Uptime struct {
1095 metric.Float64Gauge
1096 }
1097
1098 var newUptimeOpts = []metric.Float64GaugeOption{
1099 metric.WithDescription("The time the process has been running."),
1100 metric.WithUnit("s"),
1101 }
1102
1103 // NewUptime returns a new Uptime instrument.
1104 func NewUptime(
1105 m metric.Meter,
1106 opt ...metric.Float64GaugeOption,
1107 ) (Uptime, error) {
1108 // Check if the meter is nil.
1109 if m == nil {
1110 return Uptime{noop.Float64Gauge{}}, nil
1111 }
1112
1113 if len(opt) == 0 {
1114 opt = newUptimeOpts
1115 } else {
1116 opt = append(opt, newUptimeOpts...)
1117 }
1118
1119 i, err := m.Float64Gauge(
1120 "process.uptime",
1121 opt...,
1122 )
1123 if err != nil {
1124 return Uptime{noop.Float64Gauge{}}, err
1125 }
1126 return Uptime{i}, nil
1127 }
1128
1129 // Inst returns the underlying metric instrument.
1130 func (m Uptime) Inst() metric.Float64Gauge {
1131 return m.Float64Gauge
1132 }
1133
1134 // Name returns the semantic convention name of the instrument.
1135 func (Uptime) Name() string {
1136 return "process.uptime"
1137 }
1138
1139 // Unit returns the semantic convention unit of the instrument
1140 func (Uptime) Unit() string {
1141 return "s"
1142 }
1143
1144 // Description returns the semantic convention description of the instrument
1145 func (Uptime) Description() string {
1146 return "The time the process has been running."
1147 }
1148
1149 // Record records val to the current distribution for attrs.
1150 //
1151 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1152 // seconds as a floating point number with the highest precision available.
1153 // The actual accuracy would depend on the instrumentation and operating system.
1154 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
1155 if len(attrs) == 0 {
1156 m.Float64Gauge.Record(ctx, val)
1157 return
1158 }
1159
1160 o := recOptPool.Get().(*[]metric.RecordOption)
1161 defer func() {
1162 *o = (*o)[:0]
1163 recOptPool.Put(o)
1164 }()
1165
1166 *o = append(*o, metric.WithAttributes(attrs...))
1167 m.Float64Gauge.Record(ctx, val, *o...)
1168 }
1169
1170 // RecordSet records val to the current distribution for set.
1171 //
1172 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1173 // seconds as a floating point number with the highest precision available.
1174 // The actual accuracy would depend on the instrumentation and operating system.
1175 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1176 if set.Len() == 0 {
1177 m.Float64Gauge.Record(ctx, val)
1178 return
1179 }
1180
1181 o := recOptPool.Get().(*[]metric.RecordOption)
1182 defer func() {
1183 *o = (*o)[:0]
1184 recOptPool.Put(o)
1185 }()
1186
1187 *o = append(*o, metric.WithAttributeSet(set))
1188 m.Float64Gauge.Record(ctx, val, *o...)
1189 }
1190
1191 // WindowsHandleCount is an instrument used to record metric values conforming to
1192 // the "process.windows.handle.count" semantic conventions. It represents the
1193 // number of handles held by the process.
1194 type WindowsHandleCount struct {
1195 metric.Int64UpDownCounter
1196 }
1197
1198 var newWindowsHandleCountOpts = []metric.Int64UpDownCounterOption{
1199 metric.WithDescription("Number of handles held by the process."),
1200 metric.WithUnit("{handle}"),
1201 }
1202
1203 // NewWindowsHandleCount returns a new WindowsHandleCount instrument.
1204 func NewWindowsHandleCount(
1205 m metric.Meter,
1206 opt ...metric.Int64UpDownCounterOption,
1207 ) (WindowsHandleCount, error) {
1208 // Check if the meter is nil.
1209 if m == nil {
1210 return WindowsHandleCount{noop.Int64UpDownCounter{}}, nil
1211 }
1212
1213 if len(opt) == 0 {
1214 opt = newWindowsHandleCountOpts
1215 } else {
1216 opt = append(opt, newWindowsHandleCountOpts...)
1217 }
1218
1219 i, err := m.Int64UpDownCounter(
1220 "process.windows.handle.count",
1221 opt...,
1222 )
1223 if err != nil {
1224 return WindowsHandleCount{noop.Int64UpDownCounter{}}, err
1225 }
1226 return WindowsHandleCount{i}, nil
1227 }
1228
1229 // Inst returns the underlying metric instrument.
1230 func (m WindowsHandleCount) Inst() metric.Int64UpDownCounter {
1231 return m.Int64UpDownCounter
1232 }
1233
1234 // Name returns the semantic convention name of the instrument.
1235 func (WindowsHandleCount) Name() string {
1236 return "process.windows.handle.count"
1237 }
1238
1239 // Unit returns the semantic convention unit of the instrument
1240 func (WindowsHandleCount) Unit() string {
1241 return "{handle}"
1242 }
1243
1244 // Description returns the semantic convention description of the instrument
1245 func (WindowsHandleCount) Description() string {
1246 return "Number of handles held by the process."
1247 }
1248
1249 // Add adds incr to the existing count for attrs.
1250 func (m WindowsHandleCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1251 if len(attrs) == 0 {
1252 m.Int64UpDownCounter.Add(ctx, incr)
1253 return
1254 }
1255
1256 o := addOptPool.Get().(*[]metric.AddOption)
1257 defer func() {
1258 *o = (*o)[:0]
1259 addOptPool.Put(o)
1260 }()
1261
1262 *o = append(*o, metric.WithAttributes(attrs...))
1263 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1264 }
1265
1266 // AddSet adds incr to the existing count for set.
1267 func (m WindowsHandleCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1268 if set.Len() == 0 {
1269 m.Int64UpDownCounter.Add(ctx, incr)
1270 return
1271 }
1272
1273 o := addOptPool.Get().(*[]metric.AddOption)
1274 defer func() {
1275 *o = (*o)[:0]
1276 addOptPool.Put(o)
1277 }()
1278
1279 *o = append(*o, metric.WithAttributeSet(set))
1280 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1281 }