Debian Codegraph @

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