Debian Codegraph @

semconv/v1.38.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 // ErrorTypeAttr is an attribute conforming to the error.type semantic
25 // conventions. It represents the describes a class of error the operation ended
26 // with.
27 type ErrorTypeAttr string
28
29 var (
30 // ErrorTypeOther is a fallback error value to be used when the instrumentation
31 // doesn't define a custom value.
32 ErrorTypeOther ErrorTypeAttr = "_OTHER"
33 )
34
35 // NetworkTransportAttr is an attribute conforming to the network.transport
36 // semantic conventions. It represents the [OSI transport layer] or
37 // [inter-process communication method].
38 //
39 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
40 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
41 type NetworkTransportAttr string
42
43 var (
44 // NetworkTransportTCP is the TCP.
45 NetworkTransportTCP NetworkTransportAttr = "tcp"
46 // NetworkTransportUDP is the UDP.
47 NetworkTransportUDP NetworkTransportAttr = "udp"
48 // NetworkTransportPipe is the named or anonymous pipe.
49 NetworkTransportPipe NetworkTransportAttr = "pipe"
50 // NetworkTransportUnix is the unix domain socket.
51 NetworkTransportUnix NetworkTransportAttr = "unix"
52 // NetworkTransportQUIC is the QUIC.
53 NetworkTransportQUIC NetworkTransportAttr = "quic"
54 )
55
56 // SystemAttr is an attribute conforming to the rpc.system semantic conventions.
57 // It represents a string identifying the remoting system. See below for a list
58 // of well-known identifiers.
59 type SystemAttr string
60
61 var (
62 // SystemGRPC is the gRPC.
63 SystemGRPC SystemAttr = "grpc"
64 // SystemJavaRmi is the java RMI.
65 SystemJavaRmi SystemAttr = "java_rmi"
66 // SystemDotnetWcf is the NET WCF.
67 SystemDotnetWcf SystemAttr = "dotnet_wcf"
68 // SystemApacheDubbo is the apache Dubbo.
69 SystemApacheDubbo SystemAttr = "apache_dubbo"
70 // SystemConnectRPC is the connect RPC.
71 SystemConnectRPC SystemAttr = "connect_rpc"
72 // SystemOncRPC is the [ONC RPC (Sun RPC)].
73 //
74 // [ONC RPC (Sun RPC)]: https://datatracker.ietf.org/doc/html/rfc5531
75 SystemOncRPC SystemAttr = "onc_rpc"
76 // SystemJSONRPC is the JSON-RPC.
77 SystemJSONRPC SystemAttr = "jsonrpc"
78 )
79
80 // ClientDuration is an instrument used to record metric values conforming to the
81 // "rpc.client.duration" semantic conventions. It represents the measures the
82 // duration of outbound RPC.
83 type ClientDuration struct {
84 metric.Float64Histogram
85 }
86
87 var newClientDurationOpts = []metric.Float64HistogramOption{
88 metric.WithDescription("Measures the duration of outbound RPC."),
89 metric.WithUnit("ms"),
90 }
91
92 // NewClientDuration returns a new ClientDuration instrument.
93 func NewClientDuration(
94 m metric.Meter,
95 opt ...metric.Float64HistogramOption,
96 ) (ClientDuration, error) {
97 // Check if the meter is nil.
98 if m == nil {
99 return ClientDuration{noop.Float64Histogram{}}, nil
100 }
101
102 if len(opt) == 0 {
103 opt = newClientDurationOpts
104 } else {
105 opt = append(opt, newClientDurationOpts...)
106 }
107
108 i, err := m.Float64Histogram(
109 "rpc.client.duration",
110 opt...,
111 )
112 if err != nil {
113 return ClientDuration{noop.Float64Histogram{}}, err
114 }
115 return ClientDuration{i}, nil
116 }
117
118 // Inst returns the underlying metric instrument.
119 func (m ClientDuration) Inst() metric.Float64Histogram {
120 return m.Float64Histogram
121 }
122
123 // Name returns the semantic convention name of the instrument.
124 func (ClientDuration) Name() string {
125 return "rpc.client.duration"
126 }
127
128 // Unit returns the semantic convention unit of the instrument
129 func (ClientDuration) Unit() string {
130 return "ms"
131 }
132
133 // Description returns the semantic convention description of the instrument
134 func (ClientDuration) Description() string {
135 return "Measures the duration of outbound RPC."
136 }
137
138 // Record records val to the current distribution for attrs.
139 //
140 // The system is the a string identifying the remoting system. See below for a
141 // list of well-known identifiers.
142 //
143 // The serverAddress is the server domain name if available without reverse DNS
144 // lookup; otherwise, IP address or Unix domain socket name.
145 //
146 // All additional attrs passed are included in the recorded value.
147 //
148 // While streaming RPCs may record this metric as start-of-batch
149 // to end-of-batch, it's hard to interpret in practice.
150 //
151 // **Streaming**: N/A.
152 func (m ClientDuration) Record(
153 ctx context.Context,
154 val float64,
155 system SystemAttr,
156 serverAddress string,
157 attrs ...attribute.KeyValue,
158 ) {
159 if len(attrs) == 0 {
160 m.Float64Histogram.Record(ctx, val)
161 return
162 }
163
164 o := recOptPool.Get().(*[]metric.RecordOption)
165 defer func() {
166 *o = (*o)[:0]
167 recOptPool.Put(o)
168 }()
169
170 *o = append(
171 *o,
172 metric.WithAttributes(
173 append(
174 attrs,
175 attribute.String("rpc.system", string(system)),
176 attribute.String("server.address", serverAddress),
177 )...,
178 ),
179 )
180
181 m.Float64Histogram.Record(ctx, val, *o...)
182 }
183
184 // RecordSet records val to the current distribution for set.
185 //
186 // While streaming RPCs may record this metric as start-of-batch
187 // to end-of-batch, it's hard to interpret in practice.
188 //
189 // **Streaming**: N/A.
190 func (m ClientDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
191 if set.Len() == 0 {
192 m.Float64Histogram.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.Float64Histogram.Record(ctx, val, *o...)
204 }
205
206 // AttrErrorType returns an optional attribute for the "error.type" semantic
207 // convention. It represents the describes a class of error the operation ended
208 // with.
209 func (ClientDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
210 return attribute.String("error.type", string(val))
211 }
212
213 // AttrServerPort returns an optional attribute for the "server.port" semantic
214 // convention. It represents the server port number.
215 func (ClientDuration) AttrServerPort(val int) attribute.KeyValue {
216 return attribute.Int("server.port", val)
217 }
218
219 // AttrNetworkProtocolName returns an optional attribute for the
220 // "network.protocol.name" semantic convention. It represents the
221 // [OSI application layer] or non-OSI equivalent.
222 //
223 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
224 func (ClientDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
225 return attribute.String("network.protocol.name", val)
226 }
227
228 // AttrNetworkProtocolVersion returns an optional attribute for the
229 // "network.protocol.version" semantic convention. It represents the actual
230 // version of the protocol used for network communication.
231 func (ClientDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
232 return attribute.String("network.protocol.version", val)
233 }
234
235 // AttrNetworkTransport returns an optional attribute for the "network.transport"
236 // semantic convention. It represents the [OSI transport layer] or
237 // [inter-process communication method].
238 //
239 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
240 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
241 func (ClientDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
242 return attribute.String("network.transport", string(val))
243 }
244
245 // AttrMethod returns an optional attribute for the "rpc.method" semantic
246 // convention. It represents the this is the logical name of the method from the
247 // RPC interface perspective.
248 func (ClientDuration) AttrMethod(val string) attribute.KeyValue {
249 return attribute.String("rpc.method", val)
250 }
251
252 // AttrService returns an optional attribute for the "rpc.service" semantic
253 // convention. It represents the full (logical) name of the service being called,
254 // including its package name, if applicable.
255 func (ClientDuration) AttrService(val string) attribute.KeyValue {
256 return attribute.String("rpc.service", val)
257 }
258
259 // ClientRequestSize is an instrument used to record metric values conforming to
260 // the "rpc.client.request.size" semantic conventions. It represents the measures
261 // the size of RPC request messages (uncompressed).
262 type ClientRequestSize struct {
263 metric.Int64Histogram
264 }
265
266 var newClientRequestSizeOpts = []metric.Int64HistogramOption{
267 metric.WithDescription("Measures the size of RPC request messages (uncompressed)."),
268 metric.WithUnit("By"),
269 }
270
271 // NewClientRequestSize returns a new ClientRequestSize instrument.
272 func NewClientRequestSize(
273 m metric.Meter,
274 opt ...metric.Int64HistogramOption,
275 ) (ClientRequestSize, error) {
276 // Check if the meter is nil.
277 if m == nil {
278 return ClientRequestSize{noop.Int64Histogram{}}, nil
279 }
280
281 if len(opt) == 0 {
282 opt = newClientRequestSizeOpts
283 } else {
284 opt = append(opt, newClientRequestSizeOpts...)
285 }
286
287 i, err := m.Int64Histogram(
288 "rpc.client.request.size",
289 opt...,
290 )
291 if err != nil {
292 return ClientRequestSize{noop.Int64Histogram{}}, err
293 }
294 return ClientRequestSize{i}, nil
295 }
296
297 // Inst returns the underlying metric instrument.
298 func (m ClientRequestSize) Inst() metric.Int64Histogram {
299 return m.Int64Histogram
300 }
301
302 // Name returns the semantic convention name of the instrument.
303 func (ClientRequestSize) Name() string {
304 return "rpc.client.request.size"
305 }
306
307 // Unit returns the semantic convention unit of the instrument
308 func (ClientRequestSize) Unit() string {
309 return "By"
310 }
311
312 // Description returns the semantic convention description of the instrument
313 func (ClientRequestSize) Description() string {
314 return "Measures the size of RPC request messages (uncompressed)."
315 }
316
317 // Record records val to the current distribution for attrs.
318 //
319 // The system is the a string identifying the remoting system. See below for a
320 // list of well-known identifiers.
321 //
322 // The serverAddress is the server domain name if available without reverse DNS
323 // lookup; otherwise, IP address or Unix domain socket name.
324 //
325 // All additional attrs passed are included in the recorded value.
326 //
327 // **Streaming**: Recorded per message in a streaming batch
328 func (m ClientRequestSize) Record(
329 ctx context.Context,
330 val int64,
331 system SystemAttr,
332 serverAddress string,
333 attrs ...attribute.KeyValue,
334 ) {
335 if len(attrs) == 0 {
336 m.Int64Histogram.Record(ctx, val)
337 return
338 }
339
340 o := recOptPool.Get().(*[]metric.RecordOption)
341 defer func() {
342 *o = (*o)[:0]
343 recOptPool.Put(o)
344 }()
345
346 *o = append(
347 *o,
348 metric.WithAttributes(
349 append(
350 attrs,
351 attribute.String("rpc.system", string(system)),
352 attribute.String("server.address", serverAddress),
353 )...,
354 ),
355 )
356
357 m.Int64Histogram.Record(ctx, val, *o...)
358 }
359
360 // RecordSet records val to the current distribution for set.
361 //
362 // **Streaming**: Recorded per message in a streaming batch
363 func (m ClientRequestSize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
364 if set.Len() == 0 {
365 m.Int64Histogram.Record(ctx, val)
366 return
367 }
368
369 o := recOptPool.Get().(*[]metric.RecordOption)
370 defer func() {
371 *o = (*o)[:0]
372 recOptPool.Put(o)
373 }()
374
375 *o = append(*o, metric.WithAttributeSet(set))
376 m.Int64Histogram.Record(ctx, val, *o...)
377 }
378
379 // AttrErrorType returns an optional attribute for the "error.type" semantic
380 // convention. It represents the describes a class of error the operation ended
381 // with.
382 func (ClientRequestSize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
383 return attribute.String("error.type", string(val))
384 }
385
386 // AttrServerPort returns an optional attribute for the "server.port" semantic
387 // convention. It represents the server port number.
388 func (ClientRequestSize) AttrServerPort(val int) attribute.KeyValue {
389 return attribute.Int("server.port", val)
390 }
391
392 // AttrNetworkProtocolName returns an optional attribute for the
393 // "network.protocol.name" semantic convention. It represents the
394 // [OSI application layer] or non-OSI equivalent.
395 //
396 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
397 func (ClientRequestSize) AttrNetworkProtocolName(val string) attribute.KeyValue {
398 return attribute.String("network.protocol.name", val)
399 }
400
401 // AttrNetworkProtocolVersion returns an optional attribute for the
402 // "network.protocol.version" semantic convention. It represents the actual
403 // version of the protocol used for network communication.
404 func (ClientRequestSize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
405 return attribute.String("network.protocol.version", val)
406 }
407
408 // AttrNetworkTransport returns an optional attribute for the "network.transport"
409 // semantic convention. It represents the [OSI transport layer] or
410 // [inter-process communication method].
411 //
412 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
413 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
414 func (ClientRequestSize) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
415 return attribute.String("network.transport", string(val))
416 }
417
418 // AttrMethod returns an optional attribute for the "rpc.method" semantic
419 // convention. It represents the this is the logical name of the method from the
420 // RPC interface perspective.
421 func (ClientRequestSize) AttrMethod(val string) attribute.KeyValue {
422 return attribute.String("rpc.method", val)
423 }
424
425 // AttrService returns an optional attribute for the "rpc.service" semantic
426 // convention. It represents the full (logical) name of the service being called,
427 // including its package name, if applicable.
428 func (ClientRequestSize) AttrService(val string) attribute.KeyValue {
429 return attribute.String("rpc.service", val)
430 }
431
432 // ClientResponseSize is an instrument used to record metric values conforming to
433 // the "rpc.client.response.size" semantic conventions. It represents the
434 // measures the size of RPC response messages (uncompressed).
435 type ClientResponseSize struct {
436 metric.Int64Histogram
437 }
438
439 var newClientResponseSizeOpts = []metric.Int64HistogramOption{
440 metric.WithDescription("Measures the size of RPC response messages (uncompressed)."),
441 metric.WithUnit("By"),
442 }
443
444 // NewClientResponseSize returns a new ClientResponseSize instrument.
445 func NewClientResponseSize(
446 m metric.Meter,
447 opt ...metric.Int64HistogramOption,
448 ) (ClientResponseSize, error) {
449 // Check if the meter is nil.
450 if m == nil {
451 return ClientResponseSize{noop.Int64Histogram{}}, nil
452 }
453
454 if len(opt) == 0 {
455 opt = newClientResponseSizeOpts
456 } else {
457 opt = append(opt, newClientResponseSizeOpts...)
458 }
459
460 i, err := m.Int64Histogram(
461 "rpc.client.response.size",
462 opt...,
463 )
464 if err != nil {
465 return ClientResponseSize{noop.Int64Histogram{}}, err
466 }
467 return ClientResponseSize{i}, nil
468 }
469
470 // Inst returns the underlying metric instrument.
471 func (m ClientResponseSize) Inst() metric.Int64Histogram {
472 return m.Int64Histogram
473 }
474
475 // Name returns the semantic convention name of the instrument.
476 func (ClientResponseSize) Name() string {
477 return "rpc.client.response.size"
478 }
479
480 // Unit returns the semantic convention unit of the instrument
481 func (ClientResponseSize) Unit() string {
482 return "By"
483 }
484
485 // Description returns the semantic convention description of the instrument
486 func (ClientResponseSize) Description() string {
487 return "Measures the size of RPC response messages (uncompressed)."
488 }
489
490 // Record records val to the current distribution for attrs.
491 //
492 // The system is the a string identifying the remoting system. See below for a
493 // list of well-known identifiers.
494 //
495 // The serverAddress is the server domain name if available without reverse DNS
496 // lookup; otherwise, IP address or Unix domain socket name.
497 //
498 // All additional attrs passed are included in the recorded value.
499 //
500 // **Streaming**: Recorded per response in a streaming batch
501 func (m ClientResponseSize) Record(
502 ctx context.Context,
503 val int64,
504 system SystemAttr,
505 serverAddress string,
506 attrs ...attribute.KeyValue,
507 ) {
508 if len(attrs) == 0 {
509 m.Int64Histogram.Record(ctx, val)
510 return
511 }
512
513 o := recOptPool.Get().(*[]metric.RecordOption)
514 defer func() {
515 *o = (*o)[:0]
516 recOptPool.Put(o)
517 }()
518
519 *o = append(
520 *o,
521 metric.WithAttributes(
522 append(
523 attrs,
524 attribute.String("rpc.system", string(system)),
525 attribute.String("server.address", serverAddress),
526 )...,
527 ),
528 )
529
530 m.Int64Histogram.Record(ctx, val, *o...)
531 }
532
533 // RecordSet records val to the current distribution for set.
534 //
535 // **Streaming**: Recorded per response in a streaming batch
536 func (m ClientResponseSize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
537 if set.Len() == 0 {
538 m.Int64Histogram.Record(ctx, val)
539 return
540 }
541
542 o := recOptPool.Get().(*[]metric.RecordOption)
543 defer func() {
544 *o = (*o)[:0]
545 recOptPool.Put(o)
546 }()
547
548 *o = append(*o, metric.WithAttributeSet(set))
549 m.Int64Histogram.Record(ctx, val, *o...)
550 }
551
552 // AttrErrorType returns an optional attribute for the "error.type" semantic
553 // convention. It represents the describes a class of error the operation ended
554 // with.
555 func (ClientResponseSize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
556 return attribute.String("error.type", string(val))
557 }
558
559 // AttrServerPort returns an optional attribute for the "server.port" semantic
560 // convention. It represents the server port number.
561 func (ClientResponseSize) AttrServerPort(val int) attribute.KeyValue {
562 return attribute.Int("server.port", val)
563 }
564
565 // AttrNetworkProtocolName returns an optional attribute for the
566 // "network.protocol.name" semantic convention. It represents the
567 // [OSI application layer] or non-OSI equivalent.
568 //
569 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
570 func (ClientResponseSize) AttrNetworkProtocolName(val string) attribute.KeyValue {
571 return attribute.String("network.protocol.name", val)
572 }
573
574 // AttrNetworkProtocolVersion returns an optional attribute for the
575 // "network.protocol.version" semantic convention. It represents the actual
576 // version of the protocol used for network communication.
577 func (ClientResponseSize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
578 return attribute.String("network.protocol.version", val)
579 }
580
581 // AttrNetworkTransport returns an optional attribute for the "network.transport"
582 // semantic convention. It represents the [OSI transport layer] or
583 // [inter-process communication method].
584 //
585 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
586 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
587 func (ClientResponseSize) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
588 return attribute.String("network.transport", string(val))
589 }
590
591 // AttrMethod returns an optional attribute for the "rpc.method" semantic
592 // convention. It represents the this is the logical name of the method from the
593 // RPC interface perspective.
594 func (ClientResponseSize) AttrMethod(val string) attribute.KeyValue {
595 return attribute.String("rpc.method", val)
596 }
597
598 // AttrService returns an optional attribute for the "rpc.service" semantic
599 // convention. It represents the full (logical) name of the service being called,
600 // including its package name, if applicable.
601 func (ClientResponseSize) AttrService(val string) attribute.KeyValue {
602 return attribute.String("rpc.service", val)
603 }
604
605 // ServerDuration is an instrument used to record metric values conforming to the
606 // "rpc.server.duration" semantic conventions. It represents the measures the
607 // duration of inbound RPC.
608 type ServerDuration struct {
609 metric.Float64Histogram
610 }
611
612 var newServerDurationOpts = []metric.Float64HistogramOption{
613 metric.WithDescription("Measures the duration of inbound RPC."),
614 metric.WithUnit("ms"),
615 }
616
617 // NewServerDuration returns a new ServerDuration instrument.
618 func NewServerDuration(
619 m metric.Meter,
620 opt ...metric.Float64HistogramOption,
621 ) (ServerDuration, error) {
622 // Check if the meter is nil.
623 if m == nil {
624 return ServerDuration{noop.Float64Histogram{}}, nil
625 }
626
627 if len(opt) == 0 {
628 opt = newServerDurationOpts
629 } else {
630 opt = append(opt, newServerDurationOpts...)
631 }
632
633 i, err := m.Float64Histogram(
634 "rpc.server.duration",
635 opt...,
636 )
637 if err != nil {
638 return ServerDuration{noop.Float64Histogram{}}, err
639 }
640 return ServerDuration{i}, nil
641 }
642
643 // Inst returns the underlying metric instrument.
644 func (m ServerDuration) Inst() metric.Float64Histogram {
645 return m.Float64Histogram
646 }
647
648 // Name returns the semantic convention name of the instrument.
649 func (ServerDuration) Name() string {
650 return "rpc.server.duration"
651 }
652
653 // Unit returns the semantic convention unit of the instrument
654 func (ServerDuration) Unit() string {
655 return "ms"
656 }
657
658 // Description returns the semantic convention description of the instrument
659 func (ServerDuration) Description() string {
660 return "Measures the duration of inbound RPC."
661 }
662
663 // Record records val to the current distribution for attrs.
664 //
665 // The system is the a string identifying the remoting system. See below for a
666 // list of well-known identifiers.
667 //
668 // All additional attrs passed are included in the recorded value.
669 //
670 // While streaming RPCs may record this metric as start-of-batch
671 // to end-of-batch, it's hard to interpret in practice.
672 //
673 // **Streaming**: N/A.
674 func (m ServerDuration) Record(
675 ctx context.Context,
676 val float64,
677 system SystemAttr,
678 attrs ...attribute.KeyValue,
679 ) {
680 if len(attrs) == 0 {
681 m.Float64Histogram.Record(ctx, val)
682 return
683 }
684
685 o := recOptPool.Get().(*[]metric.RecordOption)
686 defer func() {
687 *o = (*o)[:0]
688 recOptPool.Put(o)
689 }()
690
691 *o = append(
692 *o,
693 metric.WithAttributes(
694 append(
695 attrs,
696 attribute.String("rpc.system", string(system)),
697 )...,
698 ),
699 )
700
701 m.Float64Histogram.Record(ctx, val, *o...)
702 }
703
704 // RecordSet records val to the current distribution for set.
705 //
706 // While streaming RPCs may record this metric as start-of-batch
707 // to end-of-batch, it's hard to interpret in practice.
708 //
709 // **Streaming**: N/A.
710 func (m ServerDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
711 if set.Len() == 0 {
712 m.Float64Histogram.Record(ctx, val)
713 return
714 }
715
716 o := recOptPool.Get().(*[]metric.RecordOption)
717 defer func() {
718 *o = (*o)[:0]
719 recOptPool.Put(o)
720 }()
721
722 *o = append(*o, metric.WithAttributeSet(set))
723 m.Float64Histogram.Record(ctx, val, *o...)
724 }
725
726 // AttrErrorType returns an optional attribute for the "error.type" semantic
727 // convention. It represents the describes a class of error the operation ended
728 // with.
729 func (ServerDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
730 return attribute.String("error.type", string(val))
731 }
732
733 // AttrNetworkProtocolName returns an optional attribute for the
734 // "network.protocol.name" semantic convention. It represents the
735 // [OSI application layer] or non-OSI equivalent.
736 //
737 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
738 func (ServerDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
739 return attribute.String("network.protocol.name", val)
740 }
741
742 // AttrNetworkProtocolVersion returns an optional attribute for the
743 // "network.protocol.version" semantic convention. It represents the actual
744 // version of the protocol used for network communication.
745 func (ServerDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
746 return attribute.String("network.protocol.version", val)
747 }
748
749 // AttrNetworkTransport returns an optional attribute for the "network.transport"
750 // semantic convention. It represents the [OSI transport layer] or
751 // [inter-process communication method].
752 //
753 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
754 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
755 func (ServerDuration) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
756 return attribute.String("network.transport", string(val))
757 }
758
759 // AttrMethod returns an optional attribute for the "rpc.method" semantic
760 // convention. It represents the this is the logical name of the method from the
761 // RPC interface perspective.
762 func (ServerDuration) AttrMethod(val string) attribute.KeyValue {
763 return attribute.String("rpc.method", val)
764 }
765
766 // AttrService returns an optional attribute for the "rpc.service" semantic
767 // convention. It represents the full (logical) name of the service being called,
768 // including its package name, if applicable.
769 func (ServerDuration) AttrService(val string) attribute.KeyValue {
770 return attribute.String("rpc.service", val)
771 }
772
773 // AttrServerAddress returns an optional attribute for the "server.address"
774 // semantic convention. It represents the server domain name if available without
775 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
776 func (ServerDuration) AttrServerAddress(val string) attribute.KeyValue {
777 return attribute.String("server.address", val)
778 }
779
780 // AttrServerPort returns an optional attribute for the "server.port" semantic
781 // convention. It represents the server port number.
782 func (ServerDuration) AttrServerPort(val int) attribute.KeyValue {
783 return attribute.Int("server.port", val)
784 }
785
786 // ServerRequestSize is an instrument used to record metric values conforming to
787 // the "rpc.server.request.size" semantic conventions. It represents the measures
788 // the size of RPC request messages (uncompressed).
789 type ServerRequestSize struct {
790 metric.Int64Histogram
791 }
792
793 var newServerRequestSizeOpts = []metric.Int64HistogramOption{
794 metric.WithDescription("Measures the size of RPC request messages (uncompressed)."),
795 metric.WithUnit("By"),
796 }
797
798 // NewServerRequestSize returns a new ServerRequestSize instrument.
799 func NewServerRequestSize(
800 m metric.Meter,
801 opt ...metric.Int64HistogramOption,
802 ) (ServerRequestSize, error) {
803 // Check if the meter is nil.
804 if m == nil {
805 return ServerRequestSize{noop.Int64Histogram{}}, nil
806 }
807
808 if len(opt) == 0 {
809 opt = newServerRequestSizeOpts
810 } else {
811 opt = append(opt, newServerRequestSizeOpts...)
812 }
813
814 i, err := m.Int64Histogram(
815 "rpc.server.request.size",
816 opt...,
817 )
818 if err != nil {
819 return ServerRequestSize{noop.Int64Histogram{}}, err
820 }
821 return ServerRequestSize{i}, nil
822 }
823
824 // Inst returns the underlying metric instrument.
825 func (m ServerRequestSize) Inst() metric.Int64Histogram {
826 return m.Int64Histogram
827 }
828
829 // Name returns the semantic convention name of the instrument.
830 func (ServerRequestSize) Name() string {
831 return "rpc.server.request.size"
832 }
833
834 // Unit returns the semantic convention unit of the instrument
835 func (ServerRequestSize) Unit() string {
836 return "By"
837 }
838
839 // Description returns the semantic convention description of the instrument
840 func (ServerRequestSize) Description() string {
841 return "Measures the size of RPC request messages (uncompressed)."
842 }
843
844 // Record records val to the current distribution for attrs.
845 //
846 // The system is the a string identifying the remoting system. See below for a
847 // list of well-known identifiers.
848 //
849 // All additional attrs passed are included in the recorded value.
850 //
851 // **Streaming**: Recorded per message in a streaming batch
852 func (m ServerRequestSize) Record(
853 ctx context.Context,
854 val int64,
855 system SystemAttr,
856 attrs ...attribute.KeyValue,
857 ) {
858 if len(attrs) == 0 {
859 m.Int64Histogram.Record(ctx, val)
860 return
861 }
862
863 o := recOptPool.Get().(*[]metric.RecordOption)
864 defer func() {
865 *o = (*o)[:0]
866 recOptPool.Put(o)
867 }()
868
869 *o = append(
870 *o,
871 metric.WithAttributes(
872 append(
873 attrs,
874 attribute.String("rpc.system", string(system)),
875 )...,
876 ),
877 )
878
879 m.Int64Histogram.Record(ctx, val, *o...)
880 }
881
882 // RecordSet records val to the current distribution for set.
883 //
884 // **Streaming**: Recorded per message in a streaming batch
885 func (m ServerRequestSize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
886 if set.Len() == 0 {
887 m.Int64Histogram.Record(ctx, val)
888 return
889 }
890
891 o := recOptPool.Get().(*[]metric.RecordOption)
892 defer func() {
893 *o = (*o)[:0]
894 recOptPool.Put(o)
895 }()
896
897 *o = append(*o, metric.WithAttributeSet(set))
898 m.Int64Histogram.Record(ctx, val, *o...)
899 }
900
901 // AttrErrorType returns an optional attribute for the "error.type" semantic
902 // convention. It represents the describes a class of error the operation ended
903 // with.
904 func (ServerRequestSize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
905 return attribute.String("error.type", string(val))
906 }
907
908 // AttrNetworkProtocolName returns an optional attribute for the
909 // "network.protocol.name" semantic convention. It represents the
910 // [OSI application layer] or non-OSI equivalent.
911 //
912 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
913 func (ServerRequestSize) AttrNetworkProtocolName(val string) attribute.KeyValue {
914 return attribute.String("network.protocol.name", val)
915 }
916
917 // AttrNetworkProtocolVersion returns an optional attribute for the
918 // "network.protocol.version" semantic convention. It represents the actual
919 // version of the protocol used for network communication.
920 func (ServerRequestSize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
921 return attribute.String("network.protocol.version", val)
922 }
923
924 // AttrNetworkTransport returns an optional attribute for the "network.transport"
925 // semantic convention. It represents the [OSI transport layer] or
926 // [inter-process communication method].
927 //
928 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
929 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
930 func (ServerRequestSize) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
931 return attribute.String("network.transport", string(val))
932 }
933
934 // AttrMethod returns an optional attribute for the "rpc.method" semantic
935 // convention. It represents the this is the logical name of the method from the
936 // RPC interface perspective.
937 func (ServerRequestSize) AttrMethod(val string) attribute.KeyValue {
938 return attribute.String("rpc.method", val)
939 }
940
941 // AttrService returns an optional attribute for the "rpc.service" semantic
942 // convention. It represents the full (logical) name of the service being called,
943 // including its package name, if applicable.
944 func (ServerRequestSize) AttrService(val string) attribute.KeyValue {
945 return attribute.String("rpc.service", val)
946 }
947
948 // AttrServerAddress returns an optional attribute for the "server.address"
949 // semantic convention. It represents the server domain name if available without
950 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
951 func (ServerRequestSize) AttrServerAddress(val string) attribute.KeyValue {
952 return attribute.String("server.address", val)
953 }
954
955 // AttrServerPort returns an optional attribute for the "server.port" semantic
956 // convention. It represents the server port number.
957 func (ServerRequestSize) AttrServerPort(val int) attribute.KeyValue {
958 return attribute.Int("server.port", val)
959 }
960
961 // ServerResponseSize is an instrument used to record metric values conforming to
962 // the "rpc.server.response.size" semantic conventions. It represents the
963 // measures the size of RPC response messages (uncompressed).
964 type ServerResponseSize struct {
965 metric.Int64Histogram
966 }
967
968 var newServerResponseSizeOpts = []metric.Int64HistogramOption{
969 metric.WithDescription("Measures the size of RPC response messages (uncompressed)."),
970 metric.WithUnit("By"),
971 }
972
973 // NewServerResponseSize returns a new ServerResponseSize instrument.
974 func NewServerResponseSize(
975 m metric.Meter,
976 opt ...metric.Int64HistogramOption,
977 ) (ServerResponseSize, error) {
978 // Check if the meter is nil.
979 if m == nil {
980 return ServerResponseSize{noop.Int64Histogram{}}, nil
981 }
982
983 if len(opt) == 0 {
984 opt = newServerResponseSizeOpts
985 } else {
986 opt = append(opt, newServerResponseSizeOpts...)
987 }
988
989 i, err := m.Int64Histogram(
990 "rpc.server.response.size",
991 opt...,
992 )
993 if err != nil {
994 return ServerResponseSize{noop.Int64Histogram{}}, err
995 }
996 return ServerResponseSize{i}, nil
997 }
998
999 // Inst returns the underlying metric instrument.
1000 func (m ServerResponseSize) Inst() metric.Int64Histogram {
1001 return m.Int64Histogram
1002 }
1003
1004 // Name returns the semantic convention name of the instrument.
1005 func (ServerResponseSize) Name() string {
1006 return "rpc.server.response.size"
1007 }
1008
1009 // Unit returns the semantic convention unit of the instrument
1010 func (ServerResponseSize) Unit() string {
1011 return "By"
1012 }
1013
1014 // Description returns the semantic convention description of the instrument
1015 func (ServerResponseSize) Description() string {
1016 return "Measures the size of RPC response messages (uncompressed)."
1017 }
1018
1019 // Record records val to the current distribution for attrs.
1020 //
1021 // The system is the a string identifying the remoting system. See below for a
1022 // list of well-known identifiers.
1023 //
1024 // All additional attrs passed are included in the recorded value.
1025 //
1026 // **Streaming**: Recorded per response in a streaming batch
1027 func (m ServerResponseSize) Record(
1028 ctx context.Context,
1029 val int64,
1030 system SystemAttr,
1031 attrs ...attribute.KeyValue,
1032 ) {
1033 if len(attrs) == 0 {
1034 m.Int64Histogram.Record(ctx, val)
1035 return
1036 }
1037
1038 o := recOptPool.Get().(*[]metric.RecordOption)
1039 defer func() {
1040 *o = (*o)[:0]
1041 recOptPool.Put(o)
1042 }()
1043
1044 *o = append(
1045 *o,
1046 metric.WithAttributes(
1047 append(
1048 attrs,
1049 attribute.String("rpc.system", string(system)),
1050 )...,
1051 ),
1052 )
1053
1054 m.Int64Histogram.Record(ctx, val, *o...)
1055 }
1056
1057 // RecordSet records val to the current distribution for set.
1058 //
1059 // **Streaming**: Recorded per response in a streaming batch
1060 func (m ServerResponseSize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1061 if set.Len() == 0 {
1062 m.Int64Histogram.Record(ctx, val)
1063 return
1064 }
1065
1066 o := recOptPool.Get().(*[]metric.RecordOption)
1067 defer func() {
1068 *o = (*o)[:0]
1069 recOptPool.Put(o)
1070 }()
1071
1072 *o = append(*o, metric.WithAttributeSet(set))
1073 m.Int64Histogram.Record(ctx, val, *o...)
1074 }
1075
1076 // AttrErrorType returns an optional attribute for the "error.type" semantic
1077 // convention. It represents the describes a class of error the operation ended
1078 // with.
1079 func (ServerResponseSize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1080 return attribute.String("error.type", string(val))
1081 }
1082
1083 // AttrNetworkProtocolName returns an optional attribute for the
1084 // "network.protocol.name" semantic convention. It represents the
1085 // [OSI application layer] or non-OSI equivalent.
1086 //
1087 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1088 func (ServerResponseSize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1089 return attribute.String("network.protocol.name", val)
1090 }
1091
1092 // AttrNetworkProtocolVersion returns an optional attribute for the
1093 // "network.protocol.version" semantic convention. It represents the actual
1094 // version of the protocol used for network communication.
1095 func (ServerResponseSize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1096 return attribute.String("network.protocol.version", val)
1097 }
1098
1099 // AttrNetworkTransport returns an optional attribute for the "network.transport"
1100 // semantic convention. It represents the [OSI transport layer] or
1101 // [inter-process communication method].
1102 //
1103 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
1104 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
1105 func (ServerResponseSize) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
1106 return attribute.String("network.transport", string(val))
1107 }
1108
1109 // AttrMethod returns an optional attribute for the "rpc.method" semantic
1110 // convention. It represents the this is the logical name of the method from the
1111 // RPC interface perspective.
1112 func (ServerResponseSize) AttrMethod(val string) attribute.KeyValue {
1113 return attribute.String("rpc.method", val)
1114 }
1115
1116 // AttrService returns an optional attribute for the "rpc.service" semantic
1117 // convention. It represents the full (logical) name of the service being called,
1118 // including its package name, if applicable.
1119 func (ServerResponseSize) AttrService(val string) attribute.KeyValue {
1120 return attribute.String("rpc.service", val)
1121 }
1122
1123 // AttrServerAddress returns an optional attribute for the "server.address"
1124 // semantic convention. It represents the server domain name if available without
1125 // reverse DNS lookup; otherwise, IP address or Unix domain socket name.
1126 func (ServerResponseSize) AttrServerAddress(val string) attribute.KeyValue {
1127 return attribute.String("server.address", val)
1128 }
1129
1130 // AttrServerPort returns an optional attribute for the "server.port" semantic
1131 // convention. It represents the server port number.
1132 func (ServerResponseSize) AttrServerPort(val int) attribute.KeyValue {
1133 return attribute.Int("server.port", val)
1134 }