Debian Codegraph @

semconv/v1.36.0/faasconv/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 faasconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "faas" namespace.
8 package faasconv
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 // TriggerAttr is an attribute conforming to the faas.trigger semantic
25 // conventions. It represents the type of the trigger which caused this function
26 // invocation.
27 type TriggerAttr string
28
29 var (
30 // TriggerDatasource is a response to some data source operation such as a
31 // database or filesystem read/write.
32 TriggerDatasource TriggerAttr = "datasource"
33 // TriggerHTTP is the to provide an answer to an inbound HTTP request.
34 TriggerHTTP TriggerAttr = "http"
35 // TriggerPubSub is a function is set to be executed when messages are sent to a
36 // messaging system.
37 TriggerPubSub TriggerAttr = "pubsub"
38 // TriggerTimer is a function is scheduled to be executed regularly.
39 TriggerTimer TriggerAttr = "timer"
40 // TriggerOther is the if none of the others apply.
41 TriggerOther TriggerAttr = "other"
42 )
43
44 // Coldstarts is an instrument used to record metric values conforming to the
45 // "faas.coldstarts" semantic conventions. It represents the number of invocation
46 // cold starts.
47 type Coldstarts struct {
48 metric.Int64Counter
49 }
50
51 // NewColdstarts returns a new Coldstarts instrument.
52 func NewColdstarts(
53 m metric.Meter,
54 opt ...metric.Int64CounterOption,
55 ) (Coldstarts, error) {
56 // Check if the meter is nil.
57 if m == nil {
58 return Coldstarts{noop.Int64Counter{}}, nil
59 }
60
61 i, err := m.Int64Counter(
62 "faas.coldstarts",
63 append([]metric.Int64CounterOption{
64 metric.WithDescription("Number of invocation cold starts"),
65 metric.WithUnit("{coldstart}"),
66 }, opt...)...,
67 )
68 if err != nil {
69 return Coldstarts{noop.Int64Counter{}}, err
70 }
71 return Coldstarts{i}, nil
72 }
73
74 // Inst returns the underlying metric instrument.
75 func (m Coldstarts) Inst() metric.Int64Counter {
76 return m.Int64Counter
77 }
78
79 // Name returns the semantic convention name of the instrument.
80 func (Coldstarts) Name() string {
81 return "faas.coldstarts"
82 }
83
84 // Unit returns the semantic convention unit of the instrument
85 func (Coldstarts) Unit() string {
86 return "{coldstart}"
87 }
88
89 // Description returns the semantic convention description of the instrument
90 func (Coldstarts) Description() string {
91 return "Number of invocation cold starts"
92 }
93
94 // Add adds incr to the existing count for attrs.
95 //
96 // All additional attrs passed are included in the recorded value.
97 func (m Coldstarts) Add(
98 ctx context.Context,
99 incr int64,
100 attrs ...attribute.KeyValue,
101 ) {
102 if len(attrs) == 0 {
103 m.Int64Counter.Add(ctx, incr)
104 return
105 }
106
107 o := addOptPool.Get().(*[]metric.AddOption)
108 defer func() {
109 *o = (*o)[:0]
110 addOptPool.Put(o)
111 }()
112
113 *o = append(
114 *o,
115 metric.WithAttributes(
116 attrs...,
117 ),
118 )
119
120 m.Int64Counter.Add(ctx, incr, *o...)
121 }
122
123 // AddSet adds incr to the existing count for set.
124 func (m Coldstarts) AddSet(ctx context.Context, incr int64, set attribute.Set) {
125 if set.Len() == 0 {
126 m.Int64Counter.Add(ctx, incr)
127 return
128 }
129
130 o := addOptPool.Get().(*[]metric.AddOption)
131 defer func() {
132 *o = (*o)[:0]
133 addOptPool.Put(o)
134 }()
135
136 *o = append(*o, metric.WithAttributeSet(set))
137 m.Int64Counter.Add(ctx, incr, *o...)
138 }
139
140 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
141 // convention. It represents the type of the trigger which caused this function
142 // invocation.
143 func (Coldstarts) AttrTrigger(val TriggerAttr) attribute.KeyValue {
144 return attribute.String("faas.trigger", string(val))
145 }
146
147 // CPUUsage is an instrument used to record metric values conforming to the
148 // "faas.cpu_usage" semantic conventions. It represents the distribution of CPU
149 // usage per invocation.
150 type CPUUsage struct {
151 metric.Float64Histogram
152 }
153
154 // NewCPUUsage returns a new CPUUsage instrument.
155 func NewCPUUsage(
156 m metric.Meter,
157 opt ...metric.Float64HistogramOption,
158 ) (CPUUsage, error) {
159 // Check if the meter is nil.
160 if m == nil {
161 return CPUUsage{noop.Float64Histogram{}}, nil
162 }
163
164 i, err := m.Float64Histogram(
165 "faas.cpu_usage",
166 append([]metric.Float64HistogramOption{
167 metric.WithDescription("Distribution of CPU usage per invocation"),
168 metric.WithUnit("s"),
169 }, opt...)...,
170 )
171 if err != nil {
172 return CPUUsage{noop.Float64Histogram{}}, err
173 }
174 return CPUUsage{i}, nil
175 }
176
177 // Inst returns the underlying metric instrument.
178 func (m CPUUsage) Inst() metric.Float64Histogram {
179 return m.Float64Histogram
180 }
181
182 // Name returns the semantic convention name of the instrument.
183 func (CPUUsage) Name() string {
184 return "faas.cpu_usage"
185 }
186
187 // Unit returns the semantic convention unit of the instrument
188 func (CPUUsage) Unit() string {
189 return "s"
190 }
191
192 // Description returns the semantic convention description of the instrument
193 func (CPUUsage) Description() string {
194 return "Distribution of CPU usage per invocation"
195 }
196
197 // Record records val to the current distribution for attrs.
198 //
199 // All additional attrs passed are included in the recorded value.
200 func (m CPUUsage) Record(
201 ctx context.Context,
202 val float64,
203 attrs ...attribute.KeyValue,
204 ) {
205 if len(attrs) == 0 {
206 m.Float64Histogram.Record(ctx, val)
207 return
208 }
209
210 o := recOptPool.Get().(*[]metric.RecordOption)
211 defer func() {
212 *o = (*o)[:0]
213 recOptPool.Put(o)
214 }()
215
216 *o = append(
217 *o,
218 metric.WithAttributes(
219 attrs...,
220 ),
221 )
222
223 m.Float64Histogram.Record(ctx, val, *o...)
224 }
225
226 // RecordSet records val to the current distribution for set.
227 func (m CPUUsage) RecordSet(ctx context.Context, val float64, set attribute.Set) {
228 if set.Len() == 0 {
229 m.Float64Histogram.Record(ctx, val)
230 return
231 }
232
233 o := recOptPool.Get().(*[]metric.RecordOption)
234 defer func() {
235 *o = (*o)[:0]
236 recOptPool.Put(o)
237 }()
238
239 *o = append(*o, metric.WithAttributeSet(set))
240 m.Float64Histogram.Record(ctx, val, *o...)
241 }
242
243 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
244 // convention. It represents the type of the trigger which caused this function
245 // invocation.
246 func (CPUUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue {
247 return attribute.String("faas.trigger", string(val))
248 }
249
250 // Errors is an instrument used to record metric values conforming to the
251 // "faas.errors" semantic conventions. It represents the number of invocation
252 // errors.
253 type Errors struct {
254 metric.Int64Counter
255 }
256
257 // NewErrors returns a new Errors instrument.
258 func NewErrors(
259 m metric.Meter,
260 opt ...metric.Int64CounterOption,
261 ) (Errors, error) {
262 // Check if the meter is nil.
263 if m == nil {
264 return Errors{noop.Int64Counter{}}, nil
265 }
266
267 i, err := m.Int64Counter(
268 "faas.errors",
269 append([]metric.Int64CounterOption{
270 metric.WithDescription("Number of invocation errors"),
271 metric.WithUnit("{error}"),
272 }, opt...)...,
273 )
274 if err != nil {
275 return Errors{noop.Int64Counter{}}, err
276 }
277 return Errors{i}, nil
278 }
279
280 // Inst returns the underlying metric instrument.
281 func (m Errors) Inst() metric.Int64Counter {
282 return m.Int64Counter
283 }
284
285 // Name returns the semantic convention name of the instrument.
286 func (Errors) Name() string {
287 return "faas.errors"
288 }
289
290 // Unit returns the semantic convention unit of the instrument
291 func (Errors) Unit() string {
292 return "{error}"
293 }
294
295 // Description returns the semantic convention description of the instrument
296 func (Errors) Description() string {
297 return "Number of invocation errors"
298 }
299
300 // Add adds incr to the existing count for attrs.
301 //
302 // All additional attrs passed are included in the recorded value.
303 func (m Errors) Add(
304 ctx context.Context,
305 incr int64,
306 attrs ...attribute.KeyValue,
307 ) {
308 if len(attrs) == 0 {
309 m.Int64Counter.Add(ctx, incr)
310 return
311 }
312
313 o := addOptPool.Get().(*[]metric.AddOption)
314 defer func() {
315 *o = (*o)[:0]
316 addOptPool.Put(o)
317 }()
318
319 *o = append(
320 *o,
321 metric.WithAttributes(
322 attrs...,
323 ),
324 )
325
326 m.Int64Counter.Add(ctx, incr, *o...)
327 }
328
329 // AddSet adds incr to the existing count for set.
330 func (m Errors) AddSet(ctx context.Context, incr int64, set attribute.Set) {
331 if set.Len() == 0 {
332 m.Int64Counter.Add(ctx, incr)
333 return
334 }
335
336 o := addOptPool.Get().(*[]metric.AddOption)
337 defer func() {
338 *o = (*o)[:0]
339 addOptPool.Put(o)
340 }()
341
342 *o = append(*o, metric.WithAttributeSet(set))
343 m.Int64Counter.Add(ctx, incr, *o...)
344 }
345
346 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
347 // convention. It represents the type of the trigger which caused this function
348 // invocation.
349 func (Errors) AttrTrigger(val TriggerAttr) attribute.KeyValue {
350 return attribute.String("faas.trigger", string(val))
351 }
352
353 // InitDuration is an instrument used to record metric values conforming to the
354 // "faas.init_duration" semantic conventions. It represents the measures the
355 // duration of the function's initialization, such as a cold start.
356 type InitDuration struct {
357 metric.Float64Histogram
358 }
359
360 // NewInitDuration returns a new InitDuration instrument.
361 func NewInitDuration(
362 m metric.Meter,
363 opt ...metric.Float64HistogramOption,
364 ) (InitDuration, error) {
365 // Check if the meter is nil.
366 if m == nil {
367 return InitDuration{noop.Float64Histogram{}}, nil
368 }
369
370 i, err := m.Float64Histogram(
371 "faas.init_duration",
372 append([]metric.Float64HistogramOption{
373 metric.WithDescription("Measures the duration of the function's initialization, such as a cold start"),
374 metric.WithUnit("s"),
375 }, opt...)...,
376 )
377 if err != nil {
378 return InitDuration{noop.Float64Histogram{}}, err
379 }
380 return InitDuration{i}, nil
381 }
382
383 // Inst returns the underlying metric instrument.
384 func (m InitDuration) Inst() metric.Float64Histogram {
385 return m.Float64Histogram
386 }
387
388 // Name returns the semantic convention name of the instrument.
389 func (InitDuration) Name() string {
390 return "faas.init_duration"
391 }
392
393 // Unit returns the semantic convention unit of the instrument
394 func (InitDuration) Unit() string {
395 return "s"
396 }
397
398 // Description returns the semantic convention description of the instrument
399 func (InitDuration) Description() string {
400 return "Measures the duration of the function's initialization, such as a cold start"
401 }
402
403 // Record records val to the current distribution for attrs.
404 //
405 // All additional attrs passed are included in the recorded value.
406 func (m InitDuration) Record(
407 ctx context.Context,
408 val float64,
409 attrs ...attribute.KeyValue,
410 ) {
411 if len(attrs) == 0 {
412 m.Float64Histogram.Record(ctx, val)
413 return
414 }
415
416 o := recOptPool.Get().(*[]metric.RecordOption)
417 defer func() {
418 *o = (*o)[:0]
419 recOptPool.Put(o)
420 }()
421
422 *o = append(
423 *o,
424 metric.WithAttributes(
425 attrs...,
426 ),
427 )
428
429 m.Float64Histogram.Record(ctx, val, *o...)
430 }
431
432 // RecordSet records val to the current distribution for set.
433 func (m InitDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
434 if set.Len() == 0 {
435 m.Float64Histogram.Record(ctx, val)
436 return
437 }
438
439 o := recOptPool.Get().(*[]metric.RecordOption)
440 defer func() {
441 *o = (*o)[:0]
442 recOptPool.Put(o)
443 }()
444
445 *o = append(*o, metric.WithAttributeSet(set))
446 m.Float64Histogram.Record(ctx, val, *o...)
447 }
448
449 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
450 // convention. It represents the type of the trigger which caused this function
451 // invocation.
452 func (InitDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue {
453 return attribute.String("faas.trigger", string(val))
454 }
455
456 // Invocations is an instrument used to record metric values conforming to the
457 // "faas.invocations" semantic conventions. It represents the number of
458 // successful invocations.
459 type Invocations struct {
460 metric.Int64Counter
461 }
462
463 // NewInvocations returns a new Invocations instrument.
464 func NewInvocations(
465 m metric.Meter,
466 opt ...metric.Int64CounterOption,
467 ) (Invocations, error) {
468 // Check if the meter is nil.
469 if m == nil {
470 return Invocations{noop.Int64Counter{}}, nil
471 }
472
473 i, err := m.Int64Counter(
474 "faas.invocations",
475 append([]metric.Int64CounterOption{
476 metric.WithDescription("Number of successful invocations"),
477 metric.WithUnit("{invocation}"),
478 }, opt...)...,
479 )
480 if err != nil {
481 return Invocations{noop.Int64Counter{}}, err
482 }
483 return Invocations{i}, nil
484 }
485
486 // Inst returns the underlying metric instrument.
487 func (m Invocations) Inst() metric.Int64Counter {
488 return m.Int64Counter
489 }
490
491 // Name returns the semantic convention name of the instrument.
492 func (Invocations) Name() string {
493 return "faas.invocations"
494 }
495
496 // Unit returns the semantic convention unit of the instrument
497 func (Invocations) Unit() string {
498 return "{invocation}"
499 }
500
501 // Description returns the semantic convention description of the instrument
502 func (Invocations) Description() string {
503 return "Number of successful invocations"
504 }
505
506 // Add adds incr to the existing count for attrs.
507 //
508 // All additional attrs passed are included in the recorded value.
509 func (m Invocations) Add(
510 ctx context.Context,
511 incr int64,
512 attrs ...attribute.KeyValue,
513 ) {
514 if len(attrs) == 0 {
515 m.Int64Counter.Add(ctx, incr)
516 return
517 }
518
519 o := addOptPool.Get().(*[]metric.AddOption)
520 defer func() {
521 *o = (*o)[:0]
522 addOptPool.Put(o)
523 }()
524
525 *o = append(
526 *o,
527 metric.WithAttributes(
528 attrs...,
529 ),
530 )
531
532 m.Int64Counter.Add(ctx, incr, *o...)
533 }
534
535 // AddSet adds incr to the existing count for set.
536 func (m Invocations) AddSet(ctx context.Context, incr int64, set attribute.Set) {
537 if set.Len() == 0 {
538 m.Int64Counter.Add(ctx, incr)
539 return
540 }
541
542 o := addOptPool.Get().(*[]metric.AddOption)
543 defer func() {
544 *o = (*o)[:0]
545 addOptPool.Put(o)
546 }()
547
548 *o = append(*o, metric.WithAttributeSet(set))
549 m.Int64Counter.Add(ctx, incr, *o...)
550 }
551
552 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
553 // convention. It represents the type of the trigger which caused this function
554 // invocation.
555 func (Invocations) AttrTrigger(val TriggerAttr) attribute.KeyValue {
556 return attribute.String("faas.trigger", string(val))
557 }
558
559 // InvokeDuration is an instrument used to record metric values conforming to the
560 // "faas.invoke_duration" semantic conventions. It represents the measures the
561 // duration of the function's logic execution.
562 type InvokeDuration struct {
563 metric.Float64Histogram
564 }
565
566 // NewInvokeDuration returns a new InvokeDuration instrument.
567 func NewInvokeDuration(
568 m metric.Meter,
569 opt ...metric.Float64HistogramOption,
570 ) (InvokeDuration, error) {
571 // Check if the meter is nil.
572 if m == nil {
573 return InvokeDuration{noop.Float64Histogram{}}, nil
574 }
575
576 i, err := m.Float64Histogram(
577 "faas.invoke_duration",
578 append([]metric.Float64HistogramOption{
579 metric.WithDescription("Measures the duration of the function's logic execution"),
580 metric.WithUnit("s"),
581 }, opt...)...,
582 )
583 if err != nil {
584 return InvokeDuration{noop.Float64Histogram{}}, err
585 }
586 return InvokeDuration{i}, nil
587 }
588
589 // Inst returns the underlying metric instrument.
590 func (m InvokeDuration) Inst() metric.Float64Histogram {
591 return m.Float64Histogram
592 }
593
594 // Name returns the semantic convention name of the instrument.
595 func (InvokeDuration) Name() string {
596 return "faas.invoke_duration"
597 }
598
599 // Unit returns the semantic convention unit of the instrument
600 func (InvokeDuration) Unit() string {
601 return "s"
602 }
603
604 // Description returns the semantic convention description of the instrument
605 func (InvokeDuration) Description() string {
606 return "Measures the duration of the function's logic execution"
607 }
608
609 // Record records val to the current distribution for attrs.
610 //
611 // All additional attrs passed are included in the recorded value.
612 func (m InvokeDuration) Record(
613 ctx context.Context,
614 val float64,
615 attrs ...attribute.KeyValue,
616 ) {
617 if len(attrs) == 0 {
618 m.Float64Histogram.Record(ctx, val)
619 return
620 }
621
622 o := recOptPool.Get().(*[]metric.RecordOption)
623 defer func() {
624 *o = (*o)[:0]
625 recOptPool.Put(o)
626 }()
627
628 *o = append(
629 *o,
630 metric.WithAttributes(
631 attrs...,
632 ),
633 )
634
635 m.Float64Histogram.Record(ctx, val, *o...)
636 }
637
638 // RecordSet records val to the current distribution for set.
639 func (m InvokeDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
640 if set.Len() == 0 {
641 m.Float64Histogram.Record(ctx, val)
642 return
643 }
644
645 o := recOptPool.Get().(*[]metric.RecordOption)
646 defer func() {
647 *o = (*o)[:0]
648 recOptPool.Put(o)
649 }()
650
651 *o = append(*o, metric.WithAttributeSet(set))
652 m.Float64Histogram.Record(ctx, val, *o...)
653 }
654
655 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
656 // convention. It represents the type of the trigger which caused this function
657 // invocation.
658 func (InvokeDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue {
659 return attribute.String("faas.trigger", string(val))
660 }
661
662 // MemUsage is an instrument used to record metric values conforming to the
663 // "faas.mem_usage" semantic conventions. It represents the distribution of max
664 // memory usage per invocation.
665 type MemUsage struct {
666 metric.Int64Histogram
667 }
668
669 // NewMemUsage returns a new MemUsage instrument.
670 func NewMemUsage(
671 m metric.Meter,
672 opt ...metric.Int64HistogramOption,
673 ) (MemUsage, error) {
674 // Check if the meter is nil.
675 if m == nil {
676 return MemUsage{noop.Int64Histogram{}}, nil
677 }
678
679 i, err := m.Int64Histogram(
680 "faas.mem_usage",
681 append([]metric.Int64HistogramOption{
682 metric.WithDescription("Distribution of max memory usage per invocation"),
683 metric.WithUnit("By"),
684 }, opt...)...,
685 )
686 if err != nil {
687 return MemUsage{noop.Int64Histogram{}}, err
688 }
689 return MemUsage{i}, nil
690 }
691
692 // Inst returns the underlying metric instrument.
693 func (m MemUsage) Inst() metric.Int64Histogram {
694 return m.Int64Histogram
695 }
696
697 // Name returns the semantic convention name of the instrument.
698 func (MemUsage) Name() string {
699 return "faas.mem_usage"
700 }
701
702 // Unit returns the semantic convention unit of the instrument
703 func (MemUsage) Unit() string {
704 return "By"
705 }
706
707 // Description returns the semantic convention description of the instrument
708 func (MemUsage) Description() string {
709 return "Distribution of max memory usage per invocation"
710 }
711
712 // Record records val to the current distribution for attrs.
713 //
714 // All additional attrs passed are included in the recorded value.
715 func (m MemUsage) Record(
716 ctx context.Context,
717 val int64,
718 attrs ...attribute.KeyValue,
719 ) {
720 if len(attrs) == 0 {
721 m.Int64Histogram.Record(ctx, val)
722 return
723 }
724
725 o := recOptPool.Get().(*[]metric.RecordOption)
726 defer func() {
727 *o = (*o)[:0]
728 recOptPool.Put(o)
729 }()
730
731 *o = append(
732 *o,
733 metric.WithAttributes(
734 attrs...,
735 ),
736 )
737
738 m.Int64Histogram.Record(ctx, val, *o...)
739 }
740
741 // RecordSet records val to the current distribution for set.
742 func (m MemUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
743 if set.Len() == 0 {
744 m.Int64Histogram.Record(ctx, val)
745 return
746 }
747
748 o := recOptPool.Get().(*[]metric.RecordOption)
749 defer func() {
750 *o = (*o)[:0]
751 recOptPool.Put(o)
752 }()
753
754 *o = append(*o, metric.WithAttributeSet(set))
755 m.Int64Histogram.Record(ctx, val, *o...)
756 }
757
758 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
759 // convention. It represents the type of the trigger which caused this function
760 // invocation.
761 func (MemUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue {
762 return attribute.String("faas.trigger", string(val))
763 }
764
765 // NetIO is an instrument used to record metric values conforming to the
766 // "faas.net_io" semantic conventions. It represents the distribution of net I/O
767 // usage per invocation.
768 type NetIO struct {
769 metric.Int64Histogram
770 }
771
772 // NewNetIO returns a new NetIO instrument.
773 func NewNetIO(
774 m metric.Meter,
775 opt ...metric.Int64HistogramOption,
776 ) (NetIO, error) {
777 // Check if the meter is nil.
778 if m == nil {
779 return NetIO{noop.Int64Histogram{}}, nil
780 }
781
782 i, err := m.Int64Histogram(
783 "faas.net_io",
784 append([]metric.Int64HistogramOption{
785 metric.WithDescription("Distribution of net I/O usage per invocation"),
786 metric.WithUnit("By"),
787 }, opt...)...,
788 )
789 if err != nil {
790 return NetIO{noop.Int64Histogram{}}, err
791 }
792 return NetIO{i}, nil
793 }
794
795 // Inst returns the underlying metric instrument.
796 func (m NetIO) Inst() metric.Int64Histogram {
797 return m.Int64Histogram
798 }
799
800 // Name returns the semantic convention name of the instrument.
801 func (NetIO) Name() string {
802 return "faas.net_io"
803 }
804
805 // Unit returns the semantic convention unit of the instrument
806 func (NetIO) Unit() string {
807 return "By"
808 }
809
810 // Description returns the semantic convention description of the instrument
811 func (NetIO) Description() string {
812 return "Distribution of net I/O usage per invocation"
813 }
814
815 // Record records val to the current distribution for attrs.
816 //
817 // All additional attrs passed are included in the recorded value.
818 func (m NetIO) Record(
819 ctx context.Context,
820 val int64,
821 attrs ...attribute.KeyValue,
822 ) {
823 if len(attrs) == 0 {
824 m.Int64Histogram.Record(ctx, val)
825 return
826 }
827
828 o := recOptPool.Get().(*[]metric.RecordOption)
829 defer func() {
830 *o = (*o)[:0]
831 recOptPool.Put(o)
832 }()
833
834 *o = append(
835 *o,
836 metric.WithAttributes(
837 attrs...,
838 ),
839 )
840
841 m.Int64Histogram.Record(ctx, val, *o...)
842 }
843
844 // RecordSet records val to the current distribution for set.
845 func (m NetIO) RecordSet(ctx context.Context, val int64, set attribute.Set) {
846 if set.Len() == 0 {
847 m.Int64Histogram.Record(ctx, val)
848 return
849 }
850
851 o := recOptPool.Get().(*[]metric.RecordOption)
852 defer func() {
853 *o = (*o)[:0]
854 recOptPool.Put(o)
855 }()
856
857 *o = append(*o, metric.WithAttributeSet(set))
858 m.Int64Histogram.Record(ctx, val, *o...)
859 }
860
861 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
862 // convention. It represents the type of the trigger which caused this function
863 // invocation.
864 func (NetIO) AttrTrigger(val TriggerAttr) attribute.KeyValue {
865 return attribute.String("faas.trigger", string(val))
866 }
867
868 // Timeouts is an instrument used to record metric values conforming to the
869 // "faas.timeouts" semantic conventions. It represents the number of invocation
870 // timeouts.
871 type Timeouts struct {
872 metric.Int64Counter
873 }
874
875 // NewTimeouts returns a new Timeouts instrument.
876 func NewTimeouts(
877 m metric.Meter,
878 opt ...metric.Int64CounterOption,
879 ) (Timeouts, error) {
880 // Check if the meter is nil.
881 if m == nil {
882 return Timeouts{noop.Int64Counter{}}, nil
883 }
884
885 i, err := m.Int64Counter(
886 "faas.timeouts",
887 append([]metric.Int64CounterOption{
888 metric.WithDescription("Number of invocation timeouts"),
889 metric.WithUnit("{timeout}"),
890 }, opt...)...,
891 )
892 if err != nil {
893 return Timeouts{noop.Int64Counter{}}, err
894 }
895 return Timeouts{i}, nil
896 }
897
898 // Inst returns the underlying metric instrument.
899 func (m Timeouts) Inst() metric.Int64Counter {
900 return m.Int64Counter
901 }
902
903 // Name returns the semantic convention name of the instrument.
904 func (Timeouts) Name() string {
905 return "faas.timeouts"
906 }
907
908 // Unit returns the semantic convention unit of the instrument
909 func (Timeouts) Unit() string {
910 return "{timeout}"
911 }
912
913 // Description returns the semantic convention description of the instrument
914 func (Timeouts) Description() string {
915 return "Number of invocation timeouts"
916 }
917
918 // Add adds incr to the existing count for attrs.
919 //
920 // All additional attrs passed are included in the recorded value.
921 func (m Timeouts) Add(
922 ctx context.Context,
923 incr int64,
924 attrs ...attribute.KeyValue,
925 ) {
926 if len(attrs) == 0 {
927 m.Int64Counter.Add(ctx, incr)
928 return
929 }
930
931 o := addOptPool.Get().(*[]metric.AddOption)
932 defer func() {
933 *o = (*o)[:0]
934 addOptPool.Put(o)
935 }()
936
937 *o = append(
938 *o,
939 metric.WithAttributes(
940 attrs...,
941 ),
942 )
943
944 m.Int64Counter.Add(ctx, incr, *o...)
945 }
946
947 // AddSet adds incr to the existing count for set.
948 func (m Timeouts) AddSet(ctx context.Context, incr int64, set attribute.Set) {
949 if set.Len() == 0 {
950 m.Int64Counter.Add(ctx, incr)
951 return
952 }
953
954 o := addOptPool.Get().(*[]metric.AddOption)
955 defer func() {
956 *o = (*o)[:0]
957 addOptPool.Put(o)
958 }()
959
960 *o = append(*o, metric.WithAttributeSet(set))
961 m.Int64Counter.Add(ctx, incr, *o...)
962 }
963
964 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
965 // convention. It represents the type of the trigger which caused this function
966 // invocation.
967 func (Timeouts) AttrTrigger(val TriggerAttr) attribute.KeyValue {
968 return attribute.String("faas.trigger", string(val))
969 }