Debian Codegraph @

semconv/v1.32.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.
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 }
84
85 o := recOptPool.Get().(*[]metric.RecordOption)
86 defer func() {
87 *o = (*o)[:0]
88 recOptPool.Put(o)
89 }()
90
91 *o = append(*o, metric.WithAttributes(attrs...))
92 m.Float64Histogram.Record(ctx, val, *o...)
93 }
94
95 // ClientRequestSize is an instrument used to record metric values conforming to
96 // the "rpc.client.request.size" semantic conventions. It represents the measures
97 // the size of RPC request messages (uncompressed).
98 type ClientRequestSize struct {
99 metric.Int64Histogram
100 }
101
102 // NewClientRequestSize returns a new ClientRequestSize instrument.
103 func NewClientRequestSize(
104 m metric.Meter,
105 opt ...metric.Int64HistogramOption,
106 ) (ClientRequestSize, error) {
107 // Check if the meter is nil.
108 if m == nil {
109 return ClientRequestSize{noop.Int64Histogram{}}, nil
110 }
111
112 i, err := m.Int64Histogram(
113 "rpc.client.request.size",
114 append([]metric.Int64HistogramOption{
115 metric.WithDescription("Measures the size of RPC request messages (uncompressed)."),
116 metric.WithUnit("By"),
117 }, opt...)...,
118 )
119 if err != nil {
120 return ClientRequestSize{noop.Int64Histogram{}}, err
121 }
122 return ClientRequestSize{i}, nil
123 }
124
125 // Inst returns the underlying metric instrument.
126 func (m ClientRequestSize) Inst() metric.Int64Histogram {
127 return m.Int64Histogram
128 }
129
130 // Name returns the semantic convention name of the instrument.
131 func (ClientRequestSize) Name() string {
132 return "rpc.client.request.size"
133 }
134
135 // Unit returns the semantic convention unit of the instrument
136 func (ClientRequestSize) Unit() string {
137 return "By"
138 }
139
140 // Description returns the semantic convention description of the instrument
141 func (ClientRequestSize) Description() string {
142 return "Measures the size of RPC request messages (uncompressed)."
143 }
144
145 // Record records val to the current distribution.
146 //
147 // **Streaming**: Recorded per message in a streaming batch
148 func (m ClientRequestSize) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
149 if len(attrs) == 0 {
150 m.Int64Histogram.Record(ctx, val)
151 }
152
153 o := recOptPool.Get().(*[]metric.RecordOption)
154 defer func() {
155 *o = (*o)[:0]
156 recOptPool.Put(o)
157 }()
158
159 *o = append(*o, metric.WithAttributes(attrs...))
160 m.Int64Histogram.Record(ctx, val, *o...)
161 }
162
163 // ClientRequestsPerRPC is an instrument used to record metric values conforming
164 // to the "rpc.client.requests_per_rpc" semantic conventions. It represents the
165 // measures the number of messages received per RPC.
166 type ClientRequestsPerRPC struct {
167 metric.Int64Histogram
168 }
169
170 // NewClientRequestsPerRPC returns a new ClientRequestsPerRPC instrument.
171 func NewClientRequestsPerRPC(
172 m metric.Meter,
173 opt ...metric.Int64HistogramOption,
174 ) (ClientRequestsPerRPC, error) {
175 // Check if the meter is nil.
176 if m == nil {
177 return ClientRequestsPerRPC{noop.Int64Histogram{}}, nil
178 }
179
180 i, err := m.Int64Histogram(
181 "rpc.client.requests_per_rpc",
182 append([]metric.Int64HistogramOption{
183 metric.WithDescription("Measures the number of messages received per RPC."),
184 metric.WithUnit("{count}"),
185 }, opt...)...,
186 )
187 if err != nil {
188 return ClientRequestsPerRPC{noop.Int64Histogram{}}, err
189 }
190 return ClientRequestsPerRPC{i}, nil
191 }
192
193 // Inst returns the underlying metric instrument.
194 func (m ClientRequestsPerRPC) Inst() metric.Int64Histogram {
195 return m.Int64Histogram
196 }
197
198 // Name returns the semantic convention name of the instrument.
199 func (ClientRequestsPerRPC) Name() string {
200 return "rpc.client.requests_per_rpc"
201 }
202
203 // Unit returns the semantic convention unit of the instrument
204 func (ClientRequestsPerRPC) Unit() string {
205 return "{count}"
206 }
207
208 // Description returns the semantic convention description of the instrument
209 func (ClientRequestsPerRPC) Description() string {
210 return "Measures the number of messages received per RPC."
211 }
212
213 // Record records val to the current distribution.
214 //
215 // Should be 1 for all non-streaming RPCs.
216 //
217 // **Streaming**: This metric is required for server and client streaming RPCs
218 func (m ClientRequestsPerRPC) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
219 if len(attrs) == 0 {
220 m.Int64Histogram.Record(ctx, val)
221 }
222
223 o := recOptPool.Get().(*[]metric.RecordOption)
224 defer func() {
225 *o = (*o)[:0]
226 recOptPool.Put(o)
227 }()
228
229 *o = append(*o, metric.WithAttributes(attrs...))
230 m.Int64Histogram.Record(ctx, val, *o...)
231 }
232
233 // ClientResponseSize is an instrument used to record metric values conforming to
234 // the "rpc.client.response.size" semantic conventions. It represents the
235 // measures the size of RPC response messages (uncompressed).
236 type ClientResponseSize struct {
237 metric.Int64Histogram
238 }
239
240 // NewClientResponseSize returns a new ClientResponseSize instrument.
241 func NewClientResponseSize(
242 m metric.Meter,
243 opt ...metric.Int64HistogramOption,
244 ) (ClientResponseSize, error) {
245 // Check if the meter is nil.
246 if m == nil {
247 return ClientResponseSize{noop.Int64Histogram{}}, nil
248 }
249
250 i, err := m.Int64Histogram(
251 "rpc.client.response.size",
252 append([]metric.Int64HistogramOption{
253 metric.WithDescription("Measures the size of RPC response messages (uncompressed)."),
254 metric.WithUnit("By"),
255 }, opt...)...,
256 )
257 if err != nil {
258 return ClientResponseSize{noop.Int64Histogram{}}, err
259 }
260 return ClientResponseSize{i}, nil
261 }
262
263 // Inst returns the underlying metric instrument.
264 func (m ClientResponseSize) Inst() metric.Int64Histogram {
265 return m.Int64Histogram
266 }
267
268 // Name returns the semantic convention name of the instrument.
269 func (ClientResponseSize) Name() string {
270 return "rpc.client.response.size"
271 }
272
273 // Unit returns the semantic convention unit of the instrument
274 func (ClientResponseSize) Unit() string {
275 return "By"
276 }
277
278 // Description returns the semantic convention description of the instrument
279 func (ClientResponseSize) Description() string {
280 return "Measures the size of RPC response messages (uncompressed)."
281 }
282
283 // Record records val to the current distribution.
284 //
285 // **Streaming**: Recorded per response in a streaming batch
286 func (m ClientResponseSize) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
287 if len(attrs) == 0 {
288 m.Int64Histogram.Record(ctx, val)
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 // ClientResponsesPerRPC is an instrument used to record metric values conforming
302 // to the "rpc.client.responses_per_rpc" semantic conventions. It represents the
303 // measures the number of messages sent per RPC.
304 type ClientResponsesPerRPC struct {
305 metric.Int64Histogram
306 }
307
308 // NewClientResponsesPerRPC returns a new ClientResponsesPerRPC instrument.
309 func NewClientResponsesPerRPC(
310 m metric.Meter,
311 opt ...metric.Int64HistogramOption,
312 ) (ClientResponsesPerRPC, error) {
313 // Check if the meter is nil.
314 if m == nil {
315 return ClientResponsesPerRPC{noop.Int64Histogram{}}, nil
316 }
317
318 i, err := m.Int64Histogram(
319 "rpc.client.responses_per_rpc",
320 append([]metric.Int64HistogramOption{
321 metric.WithDescription("Measures the number of messages sent per RPC."),
322 metric.WithUnit("{count}"),
323 }, opt...)...,
324 )
325 if err != nil {
326 return ClientResponsesPerRPC{noop.Int64Histogram{}}, err
327 }
328 return ClientResponsesPerRPC{i}, nil
329 }
330
331 // Inst returns the underlying metric instrument.
332 func (m ClientResponsesPerRPC) Inst() metric.Int64Histogram {
333 return m.Int64Histogram
334 }
335
336 // Name returns the semantic convention name of the instrument.
337 func (ClientResponsesPerRPC) Name() string {
338 return "rpc.client.responses_per_rpc"
339 }
340
341 // Unit returns the semantic convention unit of the instrument
342 func (ClientResponsesPerRPC) Unit() string {
343 return "{count}"
344 }
345
346 // Description returns the semantic convention description of the instrument
347 func (ClientResponsesPerRPC) Description() string {
348 return "Measures the number of messages sent per RPC."
349 }
350
351 // Record records val to the current distribution.
352 //
353 // Should be 1 for all non-streaming RPCs.
354 //
355 // **Streaming**: This metric is required for server and client streaming RPCs
356 func (m ClientResponsesPerRPC) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
357 if len(attrs) == 0 {
358 m.Int64Histogram.Record(ctx, val)
359 }
360
361 o := recOptPool.Get().(*[]metric.RecordOption)
362 defer func() {
363 *o = (*o)[:0]
364 recOptPool.Put(o)
365 }()
366
367 *o = append(*o, metric.WithAttributes(attrs...))
368 m.Int64Histogram.Record(ctx, val, *o...)
369 }
370
371 // ServerDuration is an instrument used to record metric values conforming to the
372 // "rpc.server.duration" semantic conventions. It represents the measures the
373 // duration of inbound RPC.
374 type ServerDuration struct {
375 metric.Float64Histogram
376 }
377
378 // NewServerDuration returns a new ServerDuration instrument.
379 func NewServerDuration(
380 m metric.Meter,
381 opt ...metric.Float64HistogramOption,
382 ) (ServerDuration, error) {
383 // Check if the meter is nil.
384 if m == nil {
385 return ServerDuration{noop.Float64Histogram{}}, nil
386 }
387
388 i, err := m.Float64Histogram(
389 "rpc.server.duration",
390 append([]metric.Float64HistogramOption{
391 metric.WithDescription("Measures the duration of inbound RPC."),
392 metric.WithUnit("ms"),
393 }, opt...)...,
394 )
395 if err != nil {
396 return ServerDuration{noop.Float64Histogram{}}, err
397 }
398 return ServerDuration{i}, nil
399 }
400
401 // Inst returns the underlying metric instrument.
402 func (m ServerDuration) Inst() metric.Float64Histogram {
403 return m.Float64Histogram
404 }
405
406 // Name returns the semantic convention name of the instrument.
407 func (ServerDuration) Name() string {
408 return "rpc.server.duration"
409 }
410
411 // Unit returns the semantic convention unit of the instrument
412 func (ServerDuration) Unit() string {
413 return "ms"
414 }
415
416 // Description returns the semantic convention description of the instrument
417 func (ServerDuration) Description() string {
418 return "Measures the duration of inbound RPC."
419 }
420
421 // Record records val to the current distribution.
422 //
423 // While streaming RPCs may record this metric as start-of-batch
424 // to end-of-batch, it's hard to interpret in practice.
425 //
426 // **Streaming**: N/A.
427 func (m ServerDuration) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
428 if len(attrs) == 0 {
429 m.Float64Histogram.Record(ctx, val)
430 }
431
432 o := recOptPool.Get().(*[]metric.RecordOption)
433 defer func() {
434 *o = (*o)[:0]
435 recOptPool.Put(o)
436 }()
437
438 *o = append(*o, metric.WithAttributes(attrs...))
439 m.Float64Histogram.Record(ctx, val, *o...)
440 }
441
442 // ServerRequestSize is an instrument used to record metric values conforming to
443 // the "rpc.server.request.size" semantic conventions. It represents the measures
444 // the size of RPC request messages (uncompressed).
445 type ServerRequestSize struct {
446 metric.Int64Histogram
447 }
448
449 // NewServerRequestSize returns a new ServerRequestSize instrument.
450 func NewServerRequestSize(
451 m metric.Meter,
452 opt ...metric.Int64HistogramOption,
453 ) (ServerRequestSize, error) {
454 // Check if the meter is nil.
455 if m == nil {
456 return ServerRequestSize{noop.Int64Histogram{}}, nil
457 }
458
459 i, err := m.Int64Histogram(
460 "rpc.server.request.size",
461 append([]metric.Int64HistogramOption{
462 metric.WithDescription("Measures the size of RPC request messages (uncompressed)."),
463 metric.WithUnit("By"),
464 }, opt...)...,
465 )
466 if err != nil {
467 return ServerRequestSize{noop.Int64Histogram{}}, err
468 }
469 return ServerRequestSize{i}, nil
470 }
471
472 // Inst returns the underlying metric instrument.
473 func (m ServerRequestSize) Inst() metric.Int64Histogram {
474 return m.Int64Histogram
475 }
476
477 // Name returns the semantic convention name of the instrument.
478 func (ServerRequestSize) Name() string {
479 return "rpc.server.request.size"
480 }
481
482 // Unit returns the semantic convention unit of the instrument
483 func (ServerRequestSize) Unit() string {
484 return "By"
485 }
486
487 // Description returns the semantic convention description of the instrument
488 func (ServerRequestSize) Description() string {
489 return "Measures the size of RPC request messages (uncompressed)."
490 }
491
492 // Record records val to the current distribution.
493 //
494 // **Streaming**: Recorded per message in a streaming batch
495 func (m ServerRequestSize) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
496 if len(attrs) == 0 {
497 m.Int64Histogram.Record(ctx, val)
498 }
499
500 o := recOptPool.Get().(*[]metric.RecordOption)
501 defer func() {
502 *o = (*o)[:0]
503 recOptPool.Put(o)
504 }()
505
506 *o = append(*o, metric.WithAttributes(attrs...))
507 m.Int64Histogram.Record(ctx, val, *o...)
508 }
509
510 // ServerRequestsPerRPC is an instrument used to record metric values conforming
511 // to the "rpc.server.requests_per_rpc" semantic conventions. It represents the
512 // measures the number of messages received per RPC.
513 type ServerRequestsPerRPC struct {
514 metric.Int64Histogram
515 }
516
517 // NewServerRequestsPerRPC returns a new ServerRequestsPerRPC instrument.
518 func NewServerRequestsPerRPC(
519 m metric.Meter,
520 opt ...metric.Int64HistogramOption,
521 ) (ServerRequestsPerRPC, error) {
522 // Check if the meter is nil.
523 if m == nil {
524 return ServerRequestsPerRPC{noop.Int64Histogram{}}, nil
525 }
526
527 i, err := m.Int64Histogram(
528 "rpc.server.requests_per_rpc",
529 append([]metric.Int64HistogramOption{
530 metric.WithDescription("Measures the number of messages received per RPC."),
531 metric.WithUnit("{count}"),
532 }, opt...)...,
533 )
534 if err != nil {
535 return ServerRequestsPerRPC{noop.Int64Histogram{}}, err
536 }
537 return ServerRequestsPerRPC{i}, nil
538 }
539
540 // Inst returns the underlying metric instrument.
541 func (m ServerRequestsPerRPC) Inst() metric.Int64Histogram {
542 return m.Int64Histogram
543 }
544
545 // Name returns the semantic convention name of the instrument.
546 func (ServerRequestsPerRPC) Name() string {
547 return "rpc.server.requests_per_rpc"
548 }
549
550 // Unit returns the semantic convention unit of the instrument
551 func (ServerRequestsPerRPC) Unit() string {
552 return "{count}"
553 }
554
555 // Description returns the semantic convention description of the instrument
556 func (ServerRequestsPerRPC) Description() string {
557 return "Measures the number of messages received per RPC."
558 }
559
560 // Record records val to the current distribution.
561 //
562 // Should be 1 for all non-streaming RPCs.
563 //
564 // **Streaming** : This metric is required for server and client streaming RPCs
565 func (m ServerRequestsPerRPC) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
566 if len(attrs) == 0 {
567 m.Int64Histogram.Record(ctx, val)
568 }
569
570 o := recOptPool.Get().(*[]metric.RecordOption)
571 defer func() {
572 *o = (*o)[:0]
573 recOptPool.Put(o)
574 }()
575
576 *o = append(*o, metric.WithAttributes(attrs...))
577 m.Int64Histogram.Record(ctx, val, *o...)
578 }
579
580 // ServerResponseSize is an instrument used to record metric values conforming to
581 // the "rpc.server.response.size" semantic conventions. It represents the
582 // measures the size of RPC response messages (uncompressed).
583 type ServerResponseSize struct {
584 metric.Int64Histogram
585 }
586
587 // NewServerResponseSize returns a new ServerResponseSize instrument.
588 func NewServerResponseSize(
589 m metric.Meter,
590 opt ...metric.Int64HistogramOption,
591 ) (ServerResponseSize, error) {
592 // Check if the meter is nil.
593 if m == nil {
594 return ServerResponseSize{noop.Int64Histogram{}}, nil
595 }
596
597 i, err := m.Int64Histogram(
598 "rpc.server.response.size",
599 append([]metric.Int64HistogramOption{
600 metric.WithDescription("Measures the size of RPC response messages (uncompressed)."),
601 metric.WithUnit("By"),
602 }, opt...)...,
603 )
604 if err != nil {
605 return ServerResponseSize{noop.Int64Histogram{}}, err
606 }
607 return ServerResponseSize{i}, nil
608 }
609
610 // Inst returns the underlying metric instrument.
611 func (m ServerResponseSize) Inst() metric.Int64Histogram {
612 return m.Int64Histogram
613 }
614
615 // Name returns the semantic convention name of the instrument.
616 func (ServerResponseSize) Name() string {
617 return "rpc.server.response.size"
618 }
619
620 // Unit returns the semantic convention unit of the instrument
621 func (ServerResponseSize) Unit() string {
622 return "By"
623 }
624
625 // Description returns the semantic convention description of the instrument
626 func (ServerResponseSize) Description() string {
627 return "Measures the size of RPC response messages (uncompressed)."
628 }
629
630 // Record records val to the current distribution.
631 //
632 // **Streaming**: Recorded per response in a streaming batch
633 func (m ServerResponseSize) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
634 if len(attrs) == 0 {
635 m.Int64Histogram.Record(ctx, val)
636 }
637
638 o := recOptPool.Get().(*[]metric.RecordOption)
639 defer func() {
640 *o = (*o)[:0]
641 recOptPool.Put(o)
642 }()
643
644 *o = append(*o, metric.WithAttributes(attrs...))
645 m.Int64Histogram.Record(ctx, val, *o...)
646 }
647
648 // ServerResponsesPerRPC is an instrument used to record metric values conforming
649 // to the "rpc.server.responses_per_rpc" semantic conventions. It represents the
650 // measures the number of messages sent per RPC.
651 type ServerResponsesPerRPC struct {
652 metric.Int64Histogram
653 }
654
655 // NewServerResponsesPerRPC returns a new ServerResponsesPerRPC instrument.
656 func NewServerResponsesPerRPC(
657 m metric.Meter,
658 opt ...metric.Int64HistogramOption,
659 ) (ServerResponsesPerRPC, error) {
660 // Check if the meter is nil.
661 if m == nil {
662 return ServerResponsesPerRPC{noop.Int64Histogram{}}, nil
663 }
664
665 i, err := m.Int64Histogram(
666 "rpc.server.responses_per_rpc",
667 append([]metric.Int64HistogramOption{
668 metric.WithDescription("Measures the number of messages sent per RPC."),
669 metric.WithUnit("{count}"),
670 }, opt...)...,
671 )
672 if err != nil {
673 return ServerResponsesPerRPC{noop.Int64Histogram{}}, err
674 }
675 return ServerResponsesPerRPC{i}, nil
676 }
677
678 // Inst returns the underlying metric instrument.
679 func (m ServerResponsesPerRPC) Inst() metric.Int64Histogram {
680 return m.Int64Histogram
681 }
682
683 // Name returns the semantic convention name of the instrument.
684 func (ServerResponsesPerRPC) Name() string {
685 return "rpc.server.responses_per_rpc"
686 }
687
688 // Unit returns the semantic convention unit of the instrument
689 func (ServerResponsesPerRPC) Unit() string {
690 return "{count}"
691 }
692
693 // Description returns the semantic convention description of the instrument
694 func (ServerResponsesPerRPC) Description() string {
695 return "Measures the number of messages sent per RPC."
696 }
697
698 // Record records val to the current distribution.
699 //
700 // Should be 1 for all non-streaming RPCs.
701 //
702 // **Streaming**: This metric is required for server and client streaming RPCs
703 func (m ServerResponsesPerRPC) Record(ctx context.Context, val int64, attrs ...attribute.KeyValue) {
704 if len(attrs) == 0 {
705 m.Int64Histogram.Record(ctx, val)
706 }
707
708 o := recOptPool.Get().(*[]metric.RecordOption)
709 defer func() {
710 *o = (*o)[:0]
711 recOptPool.Put(o)
712 }()
713
714 *o = append(*o, metric.WithAttributes(attrs...))
715 m.Int64Histogram.Record(ctx, val, *o...)
716 }