Debian Codegraph @

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