Debian Codegraph @

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