Debian Codegraph @

semconv/v1.34.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.
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 o := addOptPool.Get().(*[]metric.AddOption)
103 defer func() {
104 *o = (*o)[:0]
105 addOptPool.Put(o)
106 }()
107
108 *o = append(
109 *o,
110 metric.WithAttributes(
111 attrs...,
112 ),
113 )
114
115 m.Int64Counter.Add(ctx, incr, *o...)
116 }
117
118 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
119 // convention. It represents the type of the trigger which caused this function
120 // invocation.
121 func (Coldstarts) AttrTrigger(val TriggerAttr) attribute.KeyValue {
122 return attribute.String("faas.trigger", string(val))
123 }
124
125 // CPUUsage is an instrument used to record metric values conforming to the
126 // "faas.cpu_usage" semantic conventions. It represents the distribution of CPU
127 // usage per invocation.
128 type CPUUsage struct {
129 metric.Float64Histogram
130 }
131
132 // NewCPUUsage returns a new CPUUsage instrument.
133 func NewCPUUsage(
134 m metric.Meter,
135 opt ...metric.Float64HistogramOption,
136 ) (CPUUsage, error) {
137 // Check if the meter is nil.
138 if m == nil {
139 return CPUUsage{noop.Float64Histogram{}}, nil
140 }
141
142 i, err := m.Float64Histogram(
143 "faas.cpu_usage",
144 append([]metric.Float64HistogramOption{
145 metric.WithDescription("Distribution of CPU usage per invocation"),
146 metric.WithUnit("s"),
147 }, opt...)...,
148 )
149 if err != nil {
150 return CPUUsage{noop.Float64Histogram{}}, err
151 }
152 return CPUUsage{i}, nil
153 }
154
155 // Inst returns the underlying metric instrument.
156 func (m CPUUsage) Inst() metric.Float64Histogram {
157 return m.Float64Histogram
158 }
159
160 // Name returns the semantic convention name of the instrument.
161 func (CPUUsage) Name() string {
162 return "faas.cpu_usage"
163 }
164
165 // Unit returns the semantic convention unit of the instrument
166 func (CPUUsage) Unit() string {
167 return "s"
168 }
169
170 // Description returns the semantic convention description of the instrument
171 func (CPUUsage) Description() string {
172 return "Distribution of CPU usage per invocation"
173 }
174
175 // Record records val to the current distribution.
176 //
177 // All additional attrs passed are included in the recorded value.
178 func (m CPUUsage) Record(
179 ctx context.Context,
180 val float64,
181 attrs ...attribute.KeyValue,
182 ) {
183 o := recOptPool.Get().(*[]metric.RecordOption)
184 defer func() {
185 *o = (*o)[:0]
186 recOptPool.Put(o)
187 }()
188
189 *o = append(
190 *o,
191 metric.WithAttributes(
192 attrs...,
193 ),
194 )
195
196 m.Float64Histogram.Record(ctx, val, *o...)
197 }
198
199 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
200 // convention. It represents the type of the trigger which caused this function
201 // invocation.
202 func (CPUUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue {
203 return attribute.String("faas.trigger", string(val))
204 }
205
206 // Errors is an instrument used to record metric values conforming to the
207 // "faas.errors" semantic conventions. It represents the number of invocation
208 // errors.
209 type Errors struct {
210 metric.Int64Counter
211 }
212
213 // NewErrors returns a new Errors instrument.
214 func NewErrors(
215 m metric.Meter,
216 opt ...metric.Int64CounterOption,
217 ) (Errors, error) {
218 // Check if the meter is nil.
219 if m == nil {
220 return Errors{noop.Int64Counter{}}, nil
221 }
222
223 i, err := m.Int64Counter(
224 "faas.errors",
225 append([]metric.Int64CounterOption{
226 metric.WithDescription("Number of invocation errors"),
227 metric.WithUnit("{error}"),
228 }, opt...)...,
229 )
230 if err != nil {
231 return Errors{noop.Int64Counter{}}, err
232 }
233 return Errors{i}, nil
234 }
235
236 // Inst returns the underlying metric instrument.
237 func (m Errors) Inst() metric.Int64Counter {
238 return m.Int64Counter
239 }
240
241 // Name returns the semantic convention name of the instrument.
242 func (Errors) Name() string {
243 return "faas.errors"
244 }
245
246 // Unit returns the semantic convention unit of the instrument
247 func (Errors) Unit() string {
248 return "{error}"
249 }
250
251 // Description returns the semantic convention description of the instrument
252 func (Errors) Description() string {
253 return "Number of invocation errors"
254 }
255
256 // Add adds incr to the existing count.
257 //
258 // All additional attrs passed are included in the recorded value.
259 func (m Errors) Add(
260 ctx context.Context,
261 incr int64,
262 attrs ...attribute.KeyValue,
263 ) {
264 o := addOptPool.Get().(*[]metric.AddOption)
265 defer func() {
266 *o = (*o)[:0]
267 addOptPool.Put(o)
268 }()
269
270 *o = append(
271 *o,
272 metric.WithAttributes(
273 attrs...,
274 ),
275 )
276
277 m.Int64Counter.Add(ctx, incr, *o...)
278 }
279
280 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
281 // convention. It represents the type of the trigger which caused this function
282 // invocation.
283 func (Errors) AttrTrigger(val TriggerAttr) attribute.KeyValue {
284 return attribute.String("faas.trigger", string(val))
285 }
286
287 // InitDuration is an instrument used to record metric values conforming to the
288 // "faas.init_duration" semantic conventions. It represents the measures the
289 // duration of the function's initialization, such as a cold start.
290 type InitDuration struct {
291 metric.Float64Histogram
292 }
293
294 // NewInitDuration returns a new InitDuration instrument.
295 func NewInitDuration(
296 m metric.Meter,
297 opt ...metric.Float64HistogramOption,
298 ) (InitDuration, error) {
299 // Check if the meter is nil.
300 if m == nil {
301 return InitDuration{noop.Float64Histogram{}}, nil
302 }
303
304 i, err := m.Float64Histogram(
305 "faas.init_duration",
306 append([]metric.Float64HistogramOption{
307 metric.WithDescription("Measures the duration of the function's initialization, such as a cold start"),
308 metric.WithUnit("s"),
309 }, opt...)...,
310 )
311 if err != nil {
312 return InitDuration{noop.Float64Histogram{}}, err
313 }
314 return InitDuration{i}, nil
315 }
316
317 // Inst returns the underlying metric instrument.
318 func (m InitDuration) Inst() metric.Float64Histogram {
319 return m.Float64Histogram
320 }
321
322 // Name returns the semantic convention name of the instrument.
323 func (InitDuration) Name() string {
324 return "faas.init_duration"
325 }
326
327 // Unit returns the semantic convention unit of the instrument
328 func (InitDuration) Unit() string {
329 return "s"
330 }
331
332 // Description returns the semantic convention description of the instrument
333 func (InitDuration) Description() string {
334 return "Measures the duration of the function's initialization, such as a cold start"
335 }
336
337 // Record records val to the current distribution.
338 //
339 // All additional attrs passed are included in the recorded value.
340 func (m InitDuration) Record(
341 ctx context.Context,
342 val float64,
343 attrs ...attribute.KeyValue,
344 ) {
345 o := recOptPool.Get().(*[]metric.RecordOption)
346 defer func() {
347 *o = (*o)[:0]
348 recOptPool.Put(o)
349 }()
350
351 *o = append(
352 *o,
353 metric.WithAttributes(
354 attrs...,
355 ),
356 )
357
358 m.Float64Histogram.Record(ctx, val, *o...)
359 }
360
361 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
362 // convention. It represents the type of the trigger which caused this function
363 // invocation.
364 func (InitDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue {
365 return attribute.String("faas.trigger", string(val))
366 }
367
368 // Invocations is an instrument used to record metric values conforming to the
369 // "faas.invocations" semantic conventions. It represents the number of
370 // successful invocations.
371 type Invocations struct {
372 metric.Int64Counter
373 }
374
375 // NewInvocations returns a new Invocations instrument.
376 func NewInvocations(
377 m metric.Meter,
378 opt ...metric.Int64CounterOption,
379 ) (Invocations, error) {
380 // Check if the meter is nil.
381 if m == nil {
382 return Invocations{noop.Int64Counter{}}, nil
383 }
384
385 i, err := m.Int64Counter(
386 "faas.invocations",
387 append([]metric.Int64CounterOption{
388 metric.WithDescription("Number of successful invocations"),
389 metric.WithUnit("{invocation}"),
390 }, opt...)...,
391 )
392 if err != nil {
393 return Invocations{noop.Int64Counter{}}, err
394 }
395 return Invocations{i}, nil
396 }
397
398 // Inst returns the underlying metric instrument.
399 func (m Invocations) Inst() metric.Int64Counter {
400 return m.Int64Counter
401 }
402
403 // Name returns the semantic convention name of the instrument.
404 func (Invocations) Name() string {
405 return "faas.invocations"
406 }
407
408 // Unit returns the semantic convention unit of the instrument
409 func (Invocations) Unit() string {
410 return "{invocation}"
411 }
412
413 // Description returns the semantic convention description of the instrument
414 func (Invocations) Description() string {
415 return "Number of successful invocations"
416 }
417
418 // Add adds incr to the existing count.
419 //
420 // All additional attrs passed are included in the recorded value.
421 func (m Invocations) Add(
422 ctx context.Context,
423 incr int64,
424 attrs ...attribute.KeyValue,
425 ) {
426 o := addOptPool.Get().(*[]metric.AddOption)
427 defer func() {
428 *o = (*o)[:0]
429 addOptPool.Put(o)
430 }()
431
432 *o = append(
433 *o,
434 metric.WithAttributes(
435 attrs...,
436 ),
437 )
438
439 m.Int64Counter.Add(ctx, incr, *o...)
440 }
441
442 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
443 // convention. It represents the type of the trigger which caused this function
444 // invocation.
445 func (Invocations) AttrTrigger(val TriggerAttr) attribute.KeyValue {
446 return attribute.String("faas.trigger", string(val))
447 }
448
449 // InvokeDuration is an instrument used to record metric values conforming to the
450 // "faas.invoke_duration" semantic conventions. It represents the measures the
451 // duration of the function's logic execution.
452 type InvokeDuration struct {
453 metric.Float64Histogram
454 }
455
456 // NewInvokeDuration returns a new InvokeDuration instrument.
457 func NewInvokeDuration(
458 m metric.Meter,
459 opt ...metric.Float64HistogramOption,
460 ) (InvokeDuration, error) {
461 // Check if the meter is nil.
462 if m == nil {
463 return InvokeDuration{noop.Float64Histogram{}}, nil
464 }
465
466 i, err := m.Float64Histogram(
467 "faas.invoke_duration",
468 append([]metric.Float64HistogramOption{
469 metric.WithDescription("Measures the duration of the function's logic execution"),
470 metric.WithUnit("s"),
471 }, opt...)...,
472 )
473 if err != nil {
474 return InvokeDuration{noop.Float64Histogram{}}, err
475 }
476 return InvokeDuration{i}, nil
477 }
478
479 // Inst returns the underlying metric instrument.
480 func (m InvokeDuration) Inst() metric.Float64Histogram {
481 return m.Float64Histogram
482 }
483
484 // Name returns the semantic convention name of the instrument.
485 func (InvokeDuration) Name() string {
486 return "faas.invoke_duration"
487 }
488
489 // Unit returns the semantic convention unit of the instrument
490 func (InvokeDuration) Unit() string {
491 return "s"
492 }
493
494 // Description returns the semantic convention description of the instrument
495 func (InvokeDuration) Description() string {
496 return "Measures the duration of the function's logic execution"
497 }
498
499 // Record records val to the current distribution.
500 //
501 // All additional attrs passed are included in the recorded value.
502 func (m InvokeDuration) Record(
503 ctx context.Context,
504 val float64,
505 attrs ...attribute.KeyValue,
506 ) {
507 o := recOptPool.Get().(*[]metric.RecordOption)
508 defer func() {
509 *o = (*o)[:0]
510 recOptPool.Put(o)
511 }()
512
513 *o = append(
514 *o,
515 metric.WithAttributes(
516 attrs...,
517 ),
518 )
519
520 m.Float64Histogram.Record(ctx, val, *o...)
521 }
522
523 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
524 // convention. It represents the type of the trigger which caused this function
525 // invocation.
526 func (InvokeDuration) AttrTrigger(val TriggerAttr) attribute.KeyValue {
527 return attribute.String("faas.trigger", string(val))
528 }
529
530 // MemUsage is an instrument used to record metric values conforming to the
531 // "faas.mem_usage" semantic conventions. It represents the distribution of max
532 // memory usage per invocation.
533 type MemUsage struct {
534 metric.Int64Histogram
535 }
536
537 // NewMemUsage returns a new MemUsage instrument.
538 func NewMemUsage(
539 m metric.Meter,
540 opt ...metric.Int64HistogramOption,
541 ) (MemUsage, error) {
542 // Check if the meter is nil.
543 if m == nil {
544 return MemUsage{noop.Int64Histogram{}}, nil
545 }
546
547 i, err := m.Int64Histogram(
548 "faas.mem_usage",
549 append([]metric.Int64HistogramOption{
550 metric.WithDescription("Distribution of max memory usage per invocation"),
551 metric.WithUnit("By"),
552 }, opt...)...,
553 )
554 if err != nil {
555 return MemUsage{noop.Int64Histogram{}}, err
556 }
557 return MemUsage{i}, nil
558 }
559
560 // Inst returns the underlying metric instrument.
561 func (m MemUsage) Inst() metric.Int64Histogram {
562 return m.Int64Histogram
563 }
564
565 // Name returns the semantic convention name of the instrument.
566 func (MemUsage) Name() string {
567 return "faas.mem_usage"
568 }
569
570 // Unit returns the semantic convention unit of the instrument
571 func (MemUsage) Unit() string {
572 return "By"
573 }
574
575 // Description returns the semantic convention description of the instrument
576 func (MemUsage) Description() string {
577 return "Distribution of max memory usage per invocation"
578 }
579
580 // Record records val to the current distribution.
581 //
582 // All additional attrs passed are included in the recorded value.
583 func (m MemUsage) Record(
584 ctx context.Context,
585 val int64,
586 attrs ...attribute.KeyValue,
587 ) {
588 o := recOptPool.Get().(*[]metric.RecordOption)
589 defer func() {
590 *o = (*o)[:0]
591 recOptPool.Put(o)
592 }()
593
594 *o = append(
595 *o,
596 metric.WithAttributes(
597 attrs...,
598 ),
599 )
600
601 m.Int64Histogram.Record(ctx, val, *o...)
602 }
603
604 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
605 // convention. It represents the type of the trigger which caused this function
606 // invocation.
607 func (MemUsage) AttrTrigger(val TriggerAttr) attribute.KeyValue {
608 return attribute.String("faas.trigger", string(val))
609 }
610
611 // NetIO is an instrument used to record metric values conforming to the
612 // "faas.net_io" semantic conventions. It represents the distribution of net I/O
613 // usage per invocation.
614 type NetIO struct {
615 metric.Int64Histogram
616 }
617
618 // NewNetIO returns a new NetIO instrument.
619 func NewNetIO(
620 m metric.Meter,
621 opt ...metric.Int64HistogramOption,
622 ) (NetIO, error) {
623 // Check if the meter is nil.
624 if m == nil {
625 return NetIO{noop.Int64Histogram{}}, nil
626 }
627
628 i, err := m.Int64Histogram(
629 "faas.net_io",
630 append([]metric.Int64HistogramOption{
631 metric.WithDescription("Distribution of net I/O usage per invocation"),
632 metric.WithUnit("By"),
633 }, opt...)...,
634 )
635 if err != nil {
636 return NetIO{noop.Int64Histogram{}}, err
637 }
638 return NetIO{i}, nil
639 }
640
641 // Inst returns the underlying metric instrument.
642 func (m NetIO) Inst() metric.Int64Histogram {
643 return m.Int64Histogram
644 }
645
646 // Name returns the semantic convention name of the instrument.
647 func (NetIO) Name() string {
648 return "faas.net_io"
649 }
650
651 // Unit returns the semantic convention unit of the instrument
652 func (NetIO) Unit() string {
653 return "By"
654 }
655
656 // Description returns the semantic convention description of the instrument
657 func (NetIO) Description() string {
658 return "Distribution of net I/O usage per invocation"
659 }
660
661 // Record records val to the current distribution.
662 //
663 // All additional attrs passed are included in the recorded value.
664 func (m NetIO) Record(
665 ctx context.Context,
666 val int64,
667 attrs ...attribute.KeyValue,
668 ) {
669 o := recOptPool.Get().(*[]metric.RecordOption)
670 defer func() {
671 *o = (*o)[:0]
672 recOptPool.Put(o)
673 }()
674
675 *o = append(
676 *o,
677 metric.WithAttributes(
678 attrs...,
679 ),
680 )
681
682 m.Int64Histogram.Record(ctx, val, *o...)
683 }
684
685 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
686 // convention. It represents the type of the trigger which caused this function
687 // invocation.
688 func (NetIO) AttrTrigger(val TriggerAttr) attribute.KeyValue {
689 return attribute.String("faas.trigger", string(val))
690 }
691
692 // Timeouts is an instrument used to record metric values conforming to the
693 // "faas.timeouts" semantic conventions. It represents the number of invocation
694 // timeouts.
695 type Timeouts struct {
696 metric.Int64Counter
697 }
698
699 // NewTimeouts returns a new Timeouts instrument.
700 func NewTimeouts(
701 m metric.Meter,
702 opt ...metric.Int64CounterOption,
703 ) (Timeouts, error) {
704 // Check if the meter is nil.
705 if m == nil {
706 return Timeouts{noop.Int64Counter{}}, nil
707 }
708
709 i, err := m.Int64Counter(
710 "faas.timeouts",
711 append([]metric.Int64CounterOption{
712 metric.WithDescription("Number of invocation timeouts"),
713 metric.WithUnit("{timeout}"),
714 }, opt...)...,
715 )
716 if err != nil {
717 return Timeouts{noop.Int64Counter{}}, err
718 }
719 return Timeouts{i}, nil
720 }
721
722 // Inst returns the underlying metric instrument.
723 func (m Timeouts) Inst() metric.Int64Counter {
724 return m.Int64Counter
725 }
726
727 // Name returns the semantic convention name of the instrument.
728 func (Timeouts) Name() string {
729 return "faas.timeouts"
730 }
731
732 // Unit returns the semantic convention unit of the instrument
733 func (Timeouts) Unit() string {
734 return "{timeout}"
735 }
736
737 // Description returns the semantic convention description of the instrument
738 func (Timeouts) Description() string {
739 return "Number of invocation timeouts"
740 }
741
742 // Add adds incr to the existing count.
743 //
744 // All additional attrs passed are included in the recorded value.
745 func (m Timeouts) Add(
746 ctx context.Context,
747 incr int64,
748 attrs ...attribute.KeyValue,
749 ) {
750 o := addOptPool.Get().(*[]metric.AddOption)
751 defer func() {
752 *o = (*o)[:0]
753 addOptPool.Put(o)
754 }()
755
756 *o = append(
757 *o,
758 metric.WithAttributes(
759 attrs...,
760 ),
761 )
762
763 m.Int64Counter.Add(ctx, incr, *o...)
764 }
765
766 // AttrTrigger returns an optional attribute for the "faas.trigger" semantic
767 // convention. It represents the type of the trigger which caused this function
768 // invocation.
769 func (Timeouts) AttrTrigger(val TriggerAttr) attribute.KeyValue {
770 return attribute.String("faas.trigger", string(val))
771 }