Debian Codegraph @

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