Debian Codegraph @

semconv/v1.37.0/httpconv/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 httpconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "http" namespace.
8 package httpconv
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 // ConnectionStateAttr is an attribute conforming to the http.connection.state
36 // semantic conventions. It represents the state of the HTTP connection in the
37 // HTTP connection pool.
38 type ConnectionStateAttr string
39
40 var (
41 // ConnectionStateActive is the active state.
42 ConnectionStateActive ConnectionStateAttr = "active"
43 // ConnectionStateIdle is the idle state.
44 ConnectionStateIdle ConnectionStateAttr = "idle"
45 )
46
47 // RequestMethodAttr is an attribute conforming to the http.request.method
48 // semantic conventions. It represents the HTTP request method.
49 type RequestMethodAttr string
50
51 var (
52 // RequestMethodConnect is the CONNECT method.
53 RequestMethodConnect RequestMethodAttr = "CONNECT"
54 // RequestMethodDelete is the DELETE method.
55 RequestMethodDelete RequestMethodAttr = "DELETE"
56 // RequestMethodGet is the GET method.
57 RequestMethodGet RequestMethodAttr = "GET"
58 // RequestMethodHead is the HEAD method.
59 RequestMethodHead RequestMethodAttr = "HEAD"
60 // RequestMethodOptions is the OPTIONS method.
61 RequestMethodOptions RequestMethodAttr = "OPTIONS"
62 // RequestMethodPatch is the PATCH method.
63 RequestMethodPatch RequestMethodAttr = "PATCH"
64 // RequestMethodPost is the POST method.
65 RequestMethodPost RequestMethodAttr = "POST"
66 // RequestMethodPut is the PUT method.
67 RequestMethodPut RequestMethodAttr = "PUT"
68 // RequestMethodTrace is the TRACE method.
69 RequestMethodTrace RequestMethodAttr = "TRACE"
70 // RequestMethodOther is the any HTTP method that the instrumentation has no
71 // prior knowledge of.
72 RequestMethodOther RequestMethodAttr = "_OTHER"
73 )
74
75 // UserAgentSyntheticTypeAttr is an attribute conforming to the
76 // user_agent.synthetic.type semantic conventions. It represents the specifies
77 // the category of synthetic traffic, such as tests or bots.
78 type UserAgentSyntheticTypeAttr string
79
80 var (
81 // UserAgentSyntheticTypeBot is the bot source.
82 UserAgentSyntheticTypeBot UserAgentSyntheticTypeAttr = "bot"
83 // UserAgentSyntheticTypeTest is the synthetic test source.
84 UserAgentSyntheticTypeTest UserAgentSyntheticTypeAttr = "test"
85 )
86
87 // ClientActiveRequests is an instrument used to record metric values conforming
88 // to the "http.client.active_requests" semantic conventions. It represents the
89 // number of active HTTP requests.
90 type ClientActiveRequests struct {
91 metric.Int64UpDownCounter
92 }
93
94 var newClientActiveRequestsOpts = []metric.Int64UpDownCounterOption{
95 metric.WithDescription("Number of active HTTP requests."),
96 metric.WithUnit("{request}"),
97 }
98
99 // NewClientActiveRequests returns a new ClientActiveRequests instrument.
100 func NewClientActiveRequests(
101 m metric.Meter,
102 opt ...metric.Int64UpDownCounterOption,
103 ) (ClientActiveRequests, error) {
104 // Check if the meter is nil.
105 if m == nil {
106 return ClientActiveRequests{noop.Int64UpDownCounter{}}, nil
107 }
108
109 if len(opt) == 0 {
110 opt = newClientActiveRequestsOpts
111 } else {
112 opt = append(opt, newClientActiveRequestsOpts...)
113 }
114
115 i, err := m.Int64UpDownCounter(
116 "http.client.active_requests",
117 opt...,
118 )
119 if err != nil {
120 return ClientActiveRequests{noop.Int64UpDownCounter{}}, err
121 }
122 return ClientActiveRequests{i}, nil
123 }
124
125 // Inst returns the underlying metric instrument.
126 func (m ClientActiveRequests) Inst() metric.Int64UpDownCounter {
127 return m.Int64UpDownCounter
128 }
129
130 // Name returns the semantic convention name of the instrument.
131 func (ClientActiveRequests) Name() string {
132 return "http.client.active_requests"
133 }
134
135 // Unit returns the semantic convention unit of the instrument
136 func (ClientActiveRequests) Unit() string {
137 return "{request}"
138 }
139
140 // Description returns the semantic convention description of the instrument
141 func (ClientActiveRequests) Description() string {
142 return "Number of active HTTP requests."
143 }
144
145 // Add adds incr to the existing count for attrs.
146 //
147 // The serverAddress is the server domain name if available without reverse DNS
148 // lookup; otherwise, IP address or Unix domain socket name.
149 //
150 // The serverPort is the server port number.
151 //
152 // All additional attrs passed are included in the recorded value.
153 func (m ClientActiveRequests) Add(
154 ctx context.Context,
155 incr int64,
156 serverAddress string,
157 serverPort int,
158 attrs ...attribute.KeyValue,
159 ) {
160 if len(attrs) == 0 {
161 m.Int64UpDownCounter.Add(ctx, incr)
162 return
163 }
164
165 o := addOptPool.Get().(*[]metric.AddOption)
166 defer func() {
167 *o = (*o)[:0]
168 addOptPool.Put(o)
169 }()
170
171 *o = append(
172 *o,
173 metric.WithAttributes(
174 append(
175 attrs,
176 attribute.String("server.address", serverAddress),
177 attribute.Int("server.port", serverPort),
178 )...,
179 ),
180 )
181
182 m.Int64UpDownCounter.Add(ctx, incr, *o...)
183 }
184
185 // AddSet adds incr to the existing count for set.
186 func (m ClientActiveRequests) AddSet(ctx context.Context, incr int64, set attribute.Set) {
187 if set.Len() == 0 {
188 m.Int64UpDownCounter.Add(ctx, incr)
189 return
190 }
191
192 o := addOptPool.Get().(*[]metric.AddOption)
193 defer func() {
194 *o = (*o)[:0]
195 addOptPool.Put(o)
196 }()
197
198 *o = append(*o, metric.WithAttributeSet(set))
199 m.Int64UpDownCounter.Add(ctx, incr, *o...)
200 }
201
202 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
203 // convention. It represents the low-cardinality template of an
204 // [absolute path reference].
205 //
206 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
207 func (ClientActiveRequests) AttrURLTemplate(val string) attribute.KeyValue {
208 return attribute.String("url.template", val)
209 }
210
211 // AttrRequestMethod returns an optional attribute for the "http.request.method"
212 // semantic convention. It represents the HTTP request method.
213 func (ClientActiveRequests) AttrRequestMethod(val RequestMethodAttr) attribute.KeyValue {
214 return attribute.String("http.request.method", string(val))
215 }
216
217 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
218 // convention. It represents the [URI scheme] component identifying the used
219 // protocol.
220 //
221 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
222 func (ClientActiveRequests) AttrURLScheme(val string) attribute.KeyValue {
223 return attribute.String("url.scheme", val)
224 }
225
226 // ClientConnectionDuration is an instrument used to record metric values
227 // conforming to the "http.client.connection.duration" semantic conventions. It
228 // represents the duration of the successfully established outbound HTTP
229 // connections.
230 type ClientConnectionDuration struct {
231 metric.Float64Histogram
232 }
233
234 var newClientConnectionDurationOpts = []metric.Float64HistogramOption{
235 metric.WithDescription("The duration of the successfully established outbound HTTP connections."),
236 metric.WithUnit("s"),
237 }
238
239 // NewClientConnectionDuration returns a new ClientConnectionDuration instrument.
240 func NewClientConnectionDuration(
241 m metric.Meter,
242 opt ...metric.Float64HistogramOption,
243 ) (ClientConnectionDuration, error) {
244 // Check if the meter is nil.
245 if m == nil {
246 return ClientConnectionDuration{noop.Float64Histogram{}}, nil
247 }
248
249 if len(opt) == 0 {
250 opt = newClientConnectionDurationOpts
251 } else {
252 opt = append(opt, newClientConnectionDurationOpts...)
253 }
254
255 i, err := m.Float64Histogram(
256 "http.client.connection.duration",
257 opt...,
258 )
259 if err != nil {
260 return ClientConnectionDuration{noop.Float64Histogram{}}, err
261 }
262 return ClientConnectionDuration{i}, nil
263 }
264
265 // Inst returns the underlying metric instrument.
266 func (m ClientConnectionDuration) Inst() metric.Float64Histogram {
267 return m.Float64Histogram
268 }
269
270 // Name returns the semantic convention name of the instrument.
271 func (ClientConnectionDuration) Name() string {
272 return "http.client.connection.duration"
273 }
274
275 // Unit returns the semantic convention unit of the instrument
276 func (ClientConnectionDuration) Unit() string {
277 return "s"
278 }
279
280 // Description returns the semantic convention description of the instrument
281 func (ClientConnectionDuration) Description() string {
282 return "The duration of the successfully established outbound HTTP connections."
283 }
284
285 // Record records val to the current distribution for attrs.
286 //
287 // The serverAddress is the server domain name if available without reverse DNS
288 // lookup; otherwise, IP address or Unix domain socket name.
289 //
290 // The serverPort is the server port number.
291 //
292 // All additional attrs passed are included in the recorded value.
293 func (m ClientConnectionDuration) Record(
294 ctx context.Context,
295 val float64,
296 serverAddress string,
297 serverPort int,
298 attrs ...attribute.KeyValue,
299 ) {
300 if len(attrs) == 0 {
301 m.Float64Histogram.Record(ctx, val)
302 return
303 }
304
305 o := recOptPool.Get().(*[]metric.RecordOption)
306 defer func() {
307 *o = (*o)[:0]
308 recOptPool.Put(o)
309 }()
310
311 *o = append(
312 *o,
313 metric.WithAttributes(
314 append(
315 attrs,
316 attribute.String("server.address", serverAddress),
317 attribute.Int("server.port", serverPort),
318 )...,
319 ),
320 )
321
322 m.Float64Histogram.Record(ctx, val, *o...)
323 }
324
325 // RecordSet records val to the current distribution for set.
326 func (m ClientConnectionDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
327 if set.Len() == 0 {
328 m.Float64Histogram.Record(ctx, val)
329 return
330 }
331
332 o := recOptPool.Get().(*[]metric.RecordOption)
333 defer func() {
334 *o = (*o)[:0]
335 recOptPool.Put(o)
336 }()
337
338 *o = append(*o, metric.WithAttributeSet(set))
339 m.Float64Histogram.Record(ctx, val, *o...)
340 }
341
342 // AttrNetworkPeerAddress returns an optional attribute for the
343 // "network.peer.address" semantic convention. It represents the peer address of
344 // the network connection - IP address or Unix domain socket name.
345 func (ClientConnectionDuration) AttrNetworkPeerAddress(val string) attribute.KeyValue {
346 return attribute.String("network.peer.address", val)
347 }
348
349 // AttrNetworkProtocolVersion returns an optional attribute for the
350 // "network.protocol.version" semantic convention. It represents the actual
351 // version of the protocol used for network communication.
352 func (ClientConnectionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
353 return attribute.String("network.protocol.version", val)
354 }
355
356 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
357 // convention. It represents the [URI scheme] component identifying the used
358 // protocol.
359 //
360 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
361 func (ClientConnectionDuration) AttrURLScheme(val string) attribute.KeyValue {
362 return attribute.String("url.scheme", val)
363 }
364
365 // ClientOpenConnections is an instrument used to record metric values conforming
366 // to the "http.client.open_connections" semantic conventions. It represents the
367 // number of outbound HTTP connections that are currently active or idle on the
368 // client.
369 type ClientOpenConnections struct {
370 metric.Int64UpDownCounter
371 }
372
373 var newClientOpenConnectionsOpts = []metric.Int64UpDownCounterOption{
374 metric.WithDescription("Number of outbound HTTP connections that are currently active or idle on the client."),
375 metric.WithUnit("{connection}"),
376 }
377
378 // NewClientOpenConnections returns a new ClientOpenConnections instrument.
379 func NewClientOpenConnections(
380 m metric.Meter,
381 opt ...metric.Int64UpDownCounterOption,
382 ) (ClientOpenConnections, error) {
383 // Check if the meter is nil.
384 if m == nil {
385 return ClientOpenConnections{noop.Int64UpDownCounter{}}, nil
386 }
387
388 if len(opt) == 0 {
389 opt = newClientOpenConnectionsOpts
390 } else {
391 opt = append(opt, newClientOpenConnectionsOpts...)
392 }
393
394 i, err := m.Int64UpDownCounter(
395 "http.client.open_connections",
396 opt...,
397 )
398 if err != nil {
399 return ClientOpenConnections{noop.Int64UpDownCounter{}}, err
400 }
401 return ClientOpenConnections{i}, nil
402 }
403
404 // Inst returns the underlying metric instrument.
405 func (m ClientOpenConnections) Inst() metric.Int64UpDownCounter {
406 return m.Int64UpDownCounter
407 }
408
409 // Name returns the semantic convention name of the instrument.
410 func (ClientOpenConnections) Name() string {
411 return "http.client.open_connections"
412 }
413
414 // Unit returns the semantic convention unit of the instrument
415 func (ClientOpenConnections) Unit() string {
416 return "{connection}"
417 }
418
419 // Description returns the semantic convention description of the instrument
420 func (ClientOpenConnections) Description() string {
421 return "Number of outbound HTTP connections that are currently active or idle on the client."
422 }
423
424 // Add adds incr to the existing count for attrs.
425 //
426 // The connectionState is the state of the HTTP connection in the HTTP connection
427 // pool.
428 //
429 // The serverAddress is the server domain name if available without reverse DNS
430 // lookup; otherwise, IP address or Unix domain socket name.
431 //
432 // The serverPort is the server port number.
433 //
434 // All additional attrs passed are included in the recorded value.
435 func (m ClientOpenConnections) Add(
436 ctx context.Context,
437 incr int64,
438 connectionState ConnectionStateAttr,
439 serverAddress string,
440 serverPort int,
441 attrs ...attribute.KeyValue,
442 ) {
443 if len(attrs) == 0 {
444 m.Int64UpDownCounter.Add(ctx, incr)
445 return
446 }
447
448 o := addOptPool.Get().(*[]metric.AddOption)
449 defer func() {
450 *o = (*o)[:0]
451 addOptPool.Put(o)
452 }()
453
454 *o = append(
455 *o,
456 metric.WithAttributes(
457 append(
458 attrs,
459 attribute.String("http.connection.state", string(connectionState)),
460 attribute.String("server.address", serverAddress),
461 attribute.Int("server.port", serverPort),
462 )...,
463 ),
464 )
465
466 m.Int64UpDownCounter.Add(ctx, incr, *o...)
467 }
468
469 // AddSet adds incr to the existing count for set.
470 func (m ClientOpenConnections) AddSet(ctx context.Context, incr int64, set attribute.Set) {
471 if set.Len() == 0 {
472 m.Int64UpDownCounter.Add(ctx, incr)
473 return
474 }
475
476 o := addOptPool.Get().(*[]metric.AddOption)
477 defer func() {
478 *o = (*o)[:0]
479 addOptPool.Put(o)
480 }()
481
482 *o = append(*o, metric.WithAttributeSet(set))
483 m.Int64UpDownCounter.Add(ctx, incr, *o...)
484 }
485
486 // AttrNetworkPeerAddress returns an optional attribute for the
487 // "network.peer.address" semantic convention. It represents the peer address of
488 // the network connection - IP address or Unix domain socket name.
489 func (ClientOpenConnections) AttrNetworkPeerAddress(val string) attribute.KeyValue {
490 return attribute.String("network.peer.address", val)
491 }
492
493 // AttrNetworkProtocolVersion returns an optional attribute for the
494 // "network.protocol.version" semantic convention. It represents the actual
495 // version of the protocol used for network communication.
496 func (ClientOpenConnections) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
497 return attribute.String("network.protocol.version", val)
498 }
499
500 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
501 // convention. It represents the [URI scheme] component identifying the used
502 // protocol.
503 //
504 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
505 func (ClientOpenConnections) AttrURLScheme(val string) attribute.KeyValue {
506 return attribute.String("url.scheme", val)
507 }
508
509 // ClientRequestBodySize is an instrument used to record metric values conforming
510 // to the "http.client.request.body.size" semantic conventions. It represents the
511 // size of HTTP client request bodies.
512 type ClientRequestBodySize struct {
513 metric.Int64Histogram
514 }
515
516 var newClientRequestBodySizeOpts = []metric.Int64HistogramOption{
517 metric.WithDescription("Size of HTTP client request bodies."),
518 metric.WithUnit("By"),
519 }
520
521 // NewClientRequestBodySize returns a new ClientRequestBodySize instrument.
522 func NewClientRequestBodySize(
523 m metric.Meter,
524 opt ...metric.Int64HistogramOption,
525 ) (ClientRequestBodySize, error) {
526 // Check if the meter is nil.
527 if m == nil {
528 return ClientRequestBodySize{noop.Int64Histogram{}}, nil
529 }
530
531 if len(opt) == 0 {
532 opt = newClientRequestBodySizeOpts
533 } else {
534 opt = append(opt, newClientRequestBodySizeOpts...)
535 }
536
537 i, err := m.Int64Histogram(
538 "http.client.request.body.size",
539 opt...,
540 )
541 if err != nil {
542 return ClientRequestBodySize{noop.Int64Histogram{}}, err
543 }
544 return ClientRequestBodySize{i}, nil
545 }
546
547 // Inst returns the underlying metric instrument.
548 func (m ClientRequestBodySize) Inst() metric.Int64Histogram {
549 return m.Int64Histogram
550 }
551
552 // Name returns the semantic convention name of the instrument.
553 func (ClientRequestBodySize) Name() string {
554 return "http.client.request.body.size"
555 }
556
557 // Unit returns the semantic convention unit of the instrument
558 func (ClientRequestBodySize) Unit() string {
559 return "By"
560 }
561
562 // Description returns the semantic convention description of the instrument
563 func (ClientRequestBodySize) Description() string {
564 return "Size of HTTP client request bodies."
565 }
566
567 // Record records val to the current distribution for attrs.
568 //
569 // The requestMethod is the HTTP request method.
570 //
571 // The serverAddress is the server domain name if available without reverse DNS
572 // lookup; otherwise, IP address or Unix domain socket name.
573 //
574 // The serverPort is the server port number.
575 //
576 // All additional attrs passed are included in the recorded value.
577 //
578 // The size of the request payload body in bytes. This is the number of bytes
579 // transferred excluding headers and is often, but not always, present as the
580 // [Content-Length] header. For requests using transport encoding, this should be
581 // the compressed size.
582 //
583 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
584 func (m ClientRequestBodySize) Record(
585 ctx context.Context,
586 val int64,
587 requestMethod RequestMethodAttr,
588 serverAddress string,
589 serverPort int,
590 attrs ...attribute.KeyValue,
591 ) {
592 if len(attrs) == 0 {
593 m.Int64Histogram.Record(ctx, val)
594 return
595 }
596
597 o := recOptPool.Get().(*[]metric.RecordOption)
598 defer func() {
599 *o = (*o)[:0]
600 recOptPool.Put(o)
601 }()
602
603 *o = append(
604 *o,
605 metric.WithAttributes(
606 append(
607 attrs,
608 attribute.String("http.request.method", string(requestMethod)),
609 attribute.String("server.address", serverAddress),
610 attribute.Int("server.port", serverPort),
611 )...,
612 ),
613 )
614
615 m.Int64Histogram.Record(ctx, val, *o...)
616 }
617
618 // RecordSet records val to the current distribution for set.
619 //
620 // The size of the request payload body in bytes. This is the number of bytes
621 // transferred excluding headers and is often, but not always, present as the
622 // [Content-Length] header. For requests using transport encoding, this should be
623 // the compressed size.
624 //
625 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
626 func (m ClientRequestBodySize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
627 if set.Len() == 0 {
628 m.Int64Histogram.Record(ctx, val)
629 return
630 }
631
632 o := recOptPool.Get().(*[]metric.RecordOption)
633 defer func() {
634 *o = (*o)[:0]
635 recOptPool.Put(o)
636 }()
637
638 *o = append(*o, metric.WithAttributeSet(set))
639 m.Int64Histogram.Record(ctx, val, *o...)
640 }
641
642 // AttrErrorType returns an optional attribute for the "error.type" semantic
643 // convention. It represents the describes a class of error the operation ended
644 // with.
645 func (ClientRequestBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
646 return attribute.String("error.type", string(val))
647 }
648
649 // AttrResponseStatusCode returns an optional attribute for the
650 // "http.response.status_code" semantic convention. It represents the
651 // [HTTP response status code].
652 //
653 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
654 func (ClientRequestBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
655 return attribute.Int("http.response.status_code", val)
656 }
657
658 // AttrNetworkProtocolName returns an optional attribute for the
659 // "network.protocol.name" semantic convention. It represents the
660 // [OSI application layer] or non-OSI equivalent.
661 //
662 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
663 func (ClientRequestBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
664 return attribute.String("network.protocol.name", val)
665 }
666
667 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
668 // convention. It represents the low-cardinality template of an
669 // [absolute path reference].
670 //
671 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
672 func (ClientRequestBodySize) AttrURLTemplate(val string) attribute.KeyValue {
673 return attribute.String("url.template", val)
674 }
675
676 // AttrNetworkProtocolVersion returns an optional attribute for the
677 // "network.protocol.version" semantic convention. It represents the actual
678 // version of the protocol used for network communication.
679 func (ClientRequestBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
680 return attribute.String("network.protocol.version", val)
681 }
682
683 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
684 // convention. It represents the [URI scheme] component identifying the used
685 // protocol.
686 //
687 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
688 func (ClientRequestBodySize) AttrURLScheme(val string) attribute.KeyValue {
689 return attribute.String("url.scheme", val)
690 }
691
692 // ClientRequestDuration is an instrument used to record metric values conforming
693 // to the "http.client.request.duration" semantic conventions. It represents the
694 // duration of HTTP client requests.
695 type ClientRequestDuration struct {
696 metric.Float64Histogram
697 }
698
699 var newClientRequestDurationOpts = []metric.Float64HistogramOption{
700 metric.WithDescription("Duration of HTTP client requests."),
701 metric.WithUnit("s"),
702 }
703
704 // NewClientRequestDuration returns a new ClientRequestDuration instrument.
705 func NewClientRequestDuration(
706 m metric.Meter,
707 opt ...metric.Float64HistogramOption,
708 ) (ClientRequestDuration, error) {
709 // Check if the meter is nil.
710 if m == nil {
711 return ClientRequestDuration{noop.Float64Histogram{}}, nil
712 }
713
714 if len(opt) == 0 {
715 opt = newClientRequestDurationOpts
716 } else {
717 opt = append(opt, newClientRequestDurationOpts...)
718 }
719
720 i, err := m.Float64Histogram(
721 "http.client.request.duration",
722 opt...,
723 )
724 if err != nil {
725 return ClientRequestDuration{noop.Float64Histogram{}}, err
726 }
727 return ClientRequestDuration{i}, nil
728 }
729
730 // Inst returns the underlying metric instrument.
731 func (m ClientRequestDuration) Inst() metric.Float64Histogram {
732 return m.Float64Histogram
733 }
734
735 // Name returns the semantic convention name of the instrument.
736 func (ClientRequestDuration) Name() string {
737 return "http.client.request.duration"
738 }
739
740 // Unit returns the semantic convention unit of the instrument
741 func (ClientRequestDuration) Unit() string {
742 return "s"
743 }
744
745 // Description returns the semantic convention description of the instrument
746 func (ClientRequestDuration) Description() string {
747 return "Duration of HTTP client requests."
748 }
749
750 // Record records val to the current distribution for attrs.
751 //
752 // The requestMethod is the HTTP request method.
753 //
754 // The serverAddress is the server domain name if available without reverse DNS
755 // lookup; otherwise, IP address or Unix domain socket name.
756 //
757 // The serverPort is the server port number.
758 //
759 // All additional attrs passed are included in the recorded value.
760 func (m ClientRequestDuration) Record(
761 ctx context.Context,
762 val float64,
763 requestMethod RequestMethodAttr,
764 serverAddress string,
765 serverPort int,
766 attrs ...attribute.KeyValue,
767 ) {
768 if len(attrs) == 0 {
769 m.Float64Histogram.Record(ctx, val)
770 return
771 }
772
773 o := recOptPool.Get().(*[]metric.RecordOption)
774 defer func() {
775 *o = (*o)[:0]
776 recOptPool.Put(o)
777 }()
778
779 *o = append(
780 *o,
781 metric.WithAttributes(
782 append(
783 attrs,
784 attribute.String("http.request.method", string(requestMethod)),
785 attribute.String("server.address", serverAddress),
786 attribute.Int("server.port", serverPort),
787 )...,
788 ),
789 )
790
791 m.Float64Histogram.Record(ctx, val, *o...)
792 }
793
794 // RecordSet records val to the current distribution for set.
795 func (m ClientRequestDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
796 if set.Len() == 0 {
797 m.Float64Histogram.Record(ctx, val)
798 return
799 }
800
801 o := recOptPool.Get().(*[]metric.RecordOption)
802 defer func() {
803 *o = (*o)[:0]
804 recOptPool.Put(o)
805 }()
806
807 *o = append(*o, metric.WithAttributeSet(set))
808 m.Float64Histogram.Record(ctx, val, *o...)
809 }
810
811 // AttrErrorType returns an optional attribute for the "error.type" semantic
812 // convention. It represents the describes a class of error the operation ended
813 // with.
814 func (ClientRequestDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
815 return attribute.String("error.type", string(val))
816 }
817
818 // AttrResponseStatusCode returns an optional attribute for the
819 // "http.response.status_code" semantic convention. It represents the
820 // [HTTP response status code].
821 //
822 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
823 func (ClientRequestDuration) AttrResponseStatusCode(val int) attribute.KeyValue {
824 return attribute.Int("http.response.status_code", val)
825 }
826
827 // AttrNetworkProtocolName returns an optional attribute for the
828 // "network.protocol.name" semantic convention. It represents the
829 // [OSI application layer] or non-OSI equivalent.
830 //
831 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
832 func (ClientRequestDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
833 return attribute.String("network.protocol.name", val)
834 }
835
836 // AttrNetworkProtocolVersion returns an optional attribute for the
837 // "network.protocol.version" semantic convention. It represents the actual
838 // version of the protocol used for network communication.
839 func (ClientRequestDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
840 return attribute.String("network.protocol.version", val)
841 }
842
843 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
844 // convention. It represents the [URI scheme] component identifying the used
845 // protocol.
846 //
847 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
848 func (ClientRequestDuration) AttrURLScheme(val string) attribute.KeyValue {
849 return attribute.String("url.scheme", val)
850 }
851
852 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
853 // convention. It represents the low-cardinality template of an
854 // [absolute path reference].
855 //
856 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
857 func (ClientRequestDuration) AttrURLTemplate(val string) attribute.KeyValue {
858 return attribute.String("url.template", val)
859 }
860
861 // ClientResponseBodySize is an instrument used to record metric values
862 // conforming to the "http.client.response.body.size" semantic conventions. It
863 // represents the size of HTTP client response bodies.
864 type ClientResponseBodySize struct {
865 metric.Int64Histogram
866 }
867
868 var newClientResponseBodySizeOpts = []metric.Int64HistogramOption{
869 metric.WithDescription("Size of HTTP client response bodies."),
870 metric.WithUnit("By"),
871 }
872
873 // NewClientResponseBodySize returns a new ClientResponseBodySize instrument.
874 func NewClientResponseBodySize(
875 m metric.Meter,
876 opt ...metric.Int64HistogramOption,
877 ) (ClientResponseBodySize, error) {
878 // Check if the meter is nil.
879 if m == nil {
880 return ClientResponseBodySize{noop.Int64Histogram{}}, nil
881 }
882
883 if len(opt) == 0 {
884 opt = newClientResponseBodySizeOpts
885 } else {
886 opt = append(opt, newClientResponseBodySizeOpts...)
887 }
888
889 i, err := m.Int64Histogram(
890 "http.client.response.body.size",
891 opt...,
892 )
893 if err != nil {
894 return ClientResponseBodySize{noop.Int64Histogram{}}, err
895 }
896 return ClientResponseBodySize{i}, nil
897 }
898
899 // Inst returns the underlying metric instrument.
900 func (m ClientResponseBodySize) Inst() metric.Int64Histogram {
901 return m.Int64Histogram
902 }
903
904 // Name returns the semantic convention name of the instrument.
905 func (ClientResponseBodySize) Name() string {
906 return "http.client.response.body.size"
907 }
908
909 // Unit returns the semantic convention unit of the instrument
910 func (ClientResponseBodySize) Unit() string {
911 return "By"
912 }
913
914 // Description returns the semantic convention description of the instrument
915 func (ClientResponseBodySize) Description() string {
916 return "Size of HTTP client response bodies."
917 }
918
919 // Record records val to the current distribution for attrs.
920 //
921 // The requestMethod is the HTTP request method.
922 //
923 // The serverAddress is the server domain name if available without reverse DNS
924 // lookup; otherwise, IP address or Unix domain socket name.
925 //
926 // The serverPort is the server port number.
927 //
928 // All additional attrs passed are included in the recorded value.
929 //
930 // The size of the response payload body in bytes. This is the number of bytes
931 // transferred excluding headers and is often, but not always, present as the
932 // [Content-Length] header. For requests using transport encoding, this should be
933 // the compressed size.
934 //
935 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
936 func (m ClientResponseBodySize) Record(
937 ctx context.Context,
938 val int64,
939 requestMethod RequestMethodAttr,
940 serverAddress string,
941 serverPort int,
942 attrs ...attribute.KeyValue,
943 ) {
944 if len(attrs) == 0 {
945 m.Int64Histogram.Record(ctx, val)
946 return
947 }
948
949 o := recOptPool.Get().(*[]metric.RecordOption)
950 defer func() {
951 *o = (*o)[:0]
952 recOptPool.Put(o)
953 }()
954
955 *o = append(
956 *o,
957 metric.WithAttributes(
958 append(
959 attrs,
960 attribute.String("http.request.method", string(requestMethod)),
961 attribute.String("server.address", serverAddress),
962 attribute.Int("server.port", serverPort),
963 )...,
964 ),
965 )
966
967 m.Int64Histogram.Record(ctx, val, *o...)
968 }
969
970 // RecordSet records val to the current distribution for set.
971 //
972 // The size of the response payload body in bytes. This is the number of bytes
973 // transferred excluding headers and is often, but not always, present as the
974 // [Content-Length] header. For requests using transport encoding, this should be
975 // the compressed size.
976 //
977 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
978 func (m ClientResponseBodySize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
979 if set.Len() == 0 {
980 m.Int64Histogram.Record(ctx, val)
981 return
982 }
983
984 o := recOptPool.Get().(*[]metric.RecordOption)
985 defer func() {
986 *o = (*o)[:0]
987 recOptPool.Put(o)
988 }()
989
990 *o = append(*o, metric.WithAttributeSet(set))
991 m.Int64Histogram.Record(ctx, val, *o...)
992 }
993
994 // AttrErrorType returns an optional attribute for the "error.type" semantic
995 // convention. It represents the describes a class of error the operation ended
996 // with.
997 func (ClientResponseBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
998 return attribute.String("error.type", string(val))
999 }
1000
1001 // AttrResponseStatusCode returns an optional attribute for the
1002 // "http.response.status_code" semantic convention. It represents the
1003 // [HTTP response status code].
1004 //
1005 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1006 func (ClientResponseBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
1007 return attribute.Int("http.response.status_code", val)
1008 }
1009
1010 // AttrNetworkProtocolName returns an optional attribute for the
1011 // "network.protocol.name" semantic convention. It represents the
1012 // [OSI application layer] or non-OSI equivalent.
1013 //
1014 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1015 func (ClientResponseBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1016 return attribute.String("network.protocol.name", val)
1017 }
1018
1019 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
1020 // convention. It represents the low-cardinality template of an
1021 // [absolute path reference].
1022 //
1023 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
1024 func (ClientResponseBodySize) AttrURLTemplate(val string) attribute.KeyValue {
1025 return attribute.String("url.template", val)
1026 }
1027
1028 // AttrNetworkProtocolVersion returns an optional attribute for the
1029 // "network.protocol.version" semantic convention. It represents the actual
1030 // version of the protocol used for network communication.
1031 func (ClientResponseBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1032 return attribute.String("network.protocol.version", val)
1033 }
1034
1035 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
1036 // convention. It represents the [URI scheme] component identifying the used
1037 // protocol.
1038 //
1039 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1040 func (ClientResponseBodySize) AttrURLScheme(val string) attribute.KeyValue {
1041 return attribute.String("url.scheme", val)
1042 }
1043
1044 // ServerActiveRequests is an instrument used to record metric values conforming
1045 // to the "http.server.active_requests" semantic conventions. It represents the
1046 // number of active HTTP server requests.
1047 type ServerActiveRequests struct {
1048 metric.Int64UpDownCounter
1049 }
1050
1051 var newServerActiveRequestsOpts = []metric.Int64UpDownCounterOption{
1052 metric.WithDescription("Number of active HTTP server requests."),
1053 metric.WithUnit("{request}"),
1054 }
1055
1056 // NewServerActiveRequests returns a new ServerActiveRequests instrument.
1057 func NewServerActiveRequests(
1058 m metric.Meter,
1059 opt ...metric.Int64UpDownCounterOption,
1060 ) (ServerActiveRequests, error) {
1061 // Check if the meter is nil.
1062 if m == nil {
1063 return ServerActiveRequests{noop.Int64UpDownCounter{}}, nil
1064 }
1065
1066 if len(opt) == 0 {
1067 opt = newServerActiveRequestsOpts
1068 } else {
1069 opt = append(opt, newServerActiveRequestsOpts...)
1070 }
1071
1072 i, err := m.Int64UpDownCounter(
1073 "http.server.active_requests",
1074 opt...,
1075 )
1076 if err != nil {
1077 return ServerActiveRequests{noop.Int64UpDownCounter{}}, err
1078 }
1079 return ServerActiveRequests{i}, nil
1080 }
1081
1082 // Inst returns the underlying metric instrument.
1083 func (m ServerActiveRequests) Inst() metric.Int64UpDownCounter {
1084 return m.Int64UpDownCounter
1085 }
1086
1087 // Name returns the semantic convention name of the instrument.
1088 func (ServerActiveRequests) Name() string {
1089 return "http.server.active_requests"
1090 }
1091
1092 // Unit returns the semantic convention unit of the instrument
1093 func (ServerActiveRequests) Unit() string {
1094 return "{request}"
1095 }
1096
1097 // Description returns the semantic convention description of the instrument
1098 func (ServerActiveRequests) Description() string {
1099 return "Number of active HTTP server requests."
1100 }
1101
1102 // Add adds incr to the existing count for attrs.
1103 //
1104 // The requestMethod is the HTTP request method.
1105 //
1106 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1107 //
1108 // All additional attrs passed are included in the recorded value.
1109 //
1110 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1111 func (m ServerActiveRequests) Add(
1112 ctx context.Context,
1113 incr int64,
1114 requestMethod RequestMethodAttr,
1115 urlScheme string,
1116 attrs ...attribute.KeyValue,
1117 ) {
1118 if len(attrs) == 0 {
1119 m.Int64UpDownCounter.Add(ctx, incr)
1120 return
1121 }
1122
1123 o := addOptPool.Get().(*[]metric.AddOption)
1124 defer func() {
1125 *o = (*o)[:0]
1126 addOptPool.Put(o)
1127 }()
1128
1129 *o = append(
1130 *o,
1131 metric.WithAttributes(
1132 append(
1133 attrs,
1134 attribute.String("http.request.method", string(requestMethod)),
1135 attribute.String("url.scheme", urlScheme),
1136 )...,
1137 ),
1138 )
1139
1140 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1141 }
1142
1143 // AddSet adds incr to the existing count for set.
1144 func (m ServerActiveRequests) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1145 if set.Len() == 0 {
1146 m.Int64UpDownCounter.Add(ctx, incr)
1147 return
1148 }
1149
1150 o := addOptPool.Get().(*[]metric.AddOption)
1151 defer func() {
1152 *o = (*o)[:0]
1153 addOptPool.Put(o)
1154 }()
1155
1156 *o = append(*o, metric.WithAttributeSet(set))
1157 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1158 }
1159
1160 // AttrServerAddress returns an optional attribute for the "server.address"
1161 // semantic convention. It represents the name of the local HTTP server that
1162 // received the request.
1163 func (ServerActiveRequests) AttrServerAddress(val string) attribute.KeyValue {
1164 return attribute.String("server.address", val)
1165 }
1166
1167 // AttrServerPort returns an optional attribute for the "server.port" semantic
1168 // convention. It represents the port of the local HTTP server that received the
1169 // request.
1170 func (ServerActiveRequests) AttrServerPort(val int) attribute.KeyValue {
1171 return attribute.Int("server.port", val)
1172 }
1173
1174 // ServerRequestBodySize is an instrument used to record metric values conforming
1175 // to the "http.server.request.body.size" semantic conventions. It represents the
1176 // size of HTTP server request bodies.
1177 type ServerRequestBodySize struct {
1178 metric.Int64Histogram
1179 }
1180
1181 var newServerRequestBodySizeOpts = []metric.Int64HistogramOption{
1182 metric.WithDescription("Size of HTTP server request bodies."),
1183 metric.WithUnit("By"),
1184 }
1185
1186 // NewServerRequestBodySize returns a new ServerRequestBodySize instrument.
1187 func NewServerRequestBodySize(
1188 m metric.Meter,
1189 opt ...metric.Int64HistogramOption,
1190 ) (ServerRequestBodySize, error) {
1191 // Check if the meter is nil.
1192 if m == nil {
1193 return ServerRequestBodySize{noop.Int64Histogram{}}, nil
1194 }
1195
1196 if len(opt) == 0 {
1197 opt = newServerRequestBodySizeOpts
1198 } else {
1199 opt = append(opt, newServerRequestBodySizeOpts...)
1200 }
1201
1202 i, err := m.Int64Histogram(
1203 "http.server.request.body.size",
1204 opt...,
1205 )
1206 if err != nil {
1207 return ServerRequestBodySize{noop.Int64Histogram{}}, err
1208 }
1209 return ServerRequestBodySize{i}, nil
1210 }
1211
1212 // Inst returns the underlying metric instrument.
1213 func (m ServerRequestBodySize) Inst() metric.Int64Histogram {
1214 return m.Int64Histogram
1215 }
1216
1217 // Name returns the semantic convention name of the instrument.
1218 func (ServerRequestBodySize) Name() string {
1219 return "http.server.request.body.size"
1220 }
1221
1222 // Unit returns the semantic convention unit of the instrument
1223 func (ServerRequestBodySize) Unit() string {
1224 return "By"
1225 }
1226
1227 // Description returns the semantic convention description of the instrument
1228 func (ServerRequestBodySize) Description() string {
1229 return "Size of HTTP server request bodies."
1230 }
1231
1232 // Record records val to the current distribution for attrs.
1233 //
1234 // The requestMethod is the HTTP request method.
1235 //
1236 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1237 //
1238 // All additional attrs passed are included in the recorded value.
1239 //
1240 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1241 //
1242 // The size of the request payload body in bytes. This is the number of bytes
1243 // transferred excluding headers and is often, but not always, present as the
1244 // [Content-Length] header. For requests using transport encoding, this should be
1245 // the compressed size.
1246 //
1247 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1248 func (m ServerRequestBodySize) Record(
1249 ctx context.Context,
1250 val int64,
1251 requestMethod RequestMethodAttr,
1252 urlScheme string,
1253 attrs ...attribute.KeyValue,
1254 ) {
1255 if len(attrs) == 0 {
1256 m.Int64Histogram.Record(ctx, val)
1257 return
1258 }
1259
1260 o := recOptPool.Get().(*[]metric.RecordOption)
1261 defer func() {
1262 *o = (*o)[:0]
1263 recOptPool.Put(o)
1264 }()
1265
1266 *o = append(
1267 *o,
1268 metric.WithAttributes(
1269 append(
1270 attrs,
1271 attribute.String("http.request.method", string(requestMethod)),
1272 attribute.String("url.scheme", urlScheme),
1273 )...,
1274 ),
1275 )
1276
1277 m.Int64Histogram.Record(ctx, val, *o...)
1278 }
1279
1280 // RecordSet records val to the current distribution for set.
1281 //
1282 // The size of the request payload body in bytes. This is the number of bytes
1283 // transferred excluding headers and is often, but not always, present as the
1284 // [Content-Length] header. For requests using transport encoding, this should be
1285 // the compressed size.
1286 //
1287 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1288 func (m ServerRequestBodySize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1289 if set.Len() == 0 {
1290 m.Int64Histogram.Record(ctx, val)
1291 return
1292 }
1293
1294 o := recOptPool.Get().(*[]metric.RecordOption)
1295 defer func() {
1296 *o = (*o)[:0]
1297 recOptPool.Put(o)
1298 }()
1299
1300 *o = append(*o, metric.WithAttributeSet(set))
1301 m.Int64Histogram.Record(ctx, val, *o...)
1302 }
1303
1304 // AttrErrorType returns an optional attribute for the "error.type" semantic
1305 // convention. It represents the describes a class of error the operation ended
1306 // with.
1307 func (ServerRequestBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1308 return attribute.String("error.type", string(val))
1309 }
1310
1311 // AttrResponseStatusCode returns an optional attribute for the
1312 // "http.response.status_code" semantic convention. It represents the
1313 // [HTTP response status code].
1314 //
1315 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1316 func (ServerRequestBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
1317 return attribute.Int("http.response.status_code", val)
1318 }
1319
1320 // AttrRoute returns an optional attribute for the "http.route" semantic
1321 // convention. It represents the matched route, that is, the path template in the
1322 // format used by the respective server framework.
1323 func (ServerRequestBodySize) AttrRoute(val string) attribute.KeyValue {
1324 return attribute.String("http.route", val)
1325 }
1326
1327 // AttrNetworkProtocolName returns an optional attribute for the
1328 // "network.protocol.name" semantic convention. It represents the
1329 // [OSI application layer] or non-OSI equivalent.
1330 //
1331 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1332 func (ServerRequestBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1333 return attribute.String("network.protocol.name", val)
1334 }
1335
1336 // AttrNetworkProtocolVersion returns an optional attribute for the
1337 // "network.protocol.version" semantic convention. It represents the actual
1338 // version of the protocol used for network communication.
1339 func (ServerRequestBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1340 return attribute.String("network.protocol.version", val)
1341 }
1342
1343 // AttrServerAddress returns an optional attribute for the "server.address"
1344 // semantic convention. It represents the name of the local HTTP server that
1345 // received the request.
1346 func (ServerRequestBodySize) AttrServerAddress(val string) attribute.KeyValue {
1347 return attribute.String("server.address", val)
1348 }
1349
1350 // AttrServerPort returns an optional attribute for the "server.port" semantic
1351 // convention. It represents the port of the local HTTP server that received the
1352 // request.
1353 func (ServerRequestBodySize) AttrServerPort(val int) attribute.KeyValue {
1354 return attribute.Int("server.port", val)
1355 }
1356
1357 // AttrUserAgentSyntheticType returns an optional attribute for the
1358 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1359 // the category of synthetic traffic, such as tests or bots.
1360 func (ServerRequestBodySize) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1361 return attribute.String("user_agent.synthetic.type", string(val))
1362 }
1363
1364 // ServerRequestDuration is an instrument used to record metric values conforming
1365 // to the "http.server.request.duration" semantic conventions. It represents the
1366 // duration of HTTP server requests.
1367 type ServerRequestDuration struct {
1368 metric.Float64Histogram
1369 }
1370
1371 var newServerRequestDurationOpts = []metric.Float64HistogramOption{
1372 metric.WithDescription("Duration of HTTP server requests."),
1373 metric.WithUnit("s"),
1374 }
1375
1376 // NewServerRequestDuration returns a new ServerRequestDuration instrument.
1377 func NewServerRequestDuration(
1378 m metric.Meter,
1379 opt ...metric.Float64HistogramOption,
1380 ) (ServerRequestDuration, error) {
1381 // Check if the meter is nil.
1382 if m == nil {
1383 return ServerRequestDuration{noop.Float64Histogram{}}, nil
1384 }
1385
1386 if len(opt) == 0 {
1387 opt = newServerRequestDurationOpts
1388 } else {
1389 opt = append(opt, newServerRequestDurationOpts...)
1390 }
1391
1392 i, err := m.Float64Histogram(
1393 "http.server.request.duration",
1394 opt...,
1395 )
1396 if err != nil {
1397 return ServerRequestDuration{noop.Float64Histogram{}}, err
1398 }
1399 return ServerRequestDuration{i}, nil
1400 }
1401
1402 // Inst returns the underlying metric instrument.
1403 func (m ServerRequestDuration) Inst() metric.Float64Histogram {
1404 return m.Float64Histogram
1405 }
1406
1407 // Name returns the semantic convention name of the instrument.
1408 func (ServerRequestDuration) Name() string {
1409 return "http.server.request.duration"
1410 }
1411
1412 // Unit returns the semantic convention unit of the instrument
1413 func (ServerRequestDuration) Unit() string {
1414 return "s"
1415 }
1416
1417 // Description returns the semantic convention description of the instrument
1418 func (ServerRequestDuration) Description() string {
1419 return "Duration of HTTP server requests."
1420 }
1421
1422 // Record records val to the current distribution for attrs.
1423 //
1424 // The requestMethod is the HTTP request method.
1425 //
1426 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1427 //
1428 // All additional attrs passed are included in the recorded value.
1429 //
1430 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1431 func (m ServerRequestDuration) Record(
1432 ctx context.Context,
1433 val float64,
1434 requestMethod RequestMethodAttr,
1435 urlScheme string,
1436 attrs ...attribute.KeyValue,
1437 ) {
1438 if len(attrs) == 0 {
1439 m.Float64Histogram.Record(ctx, val)
1440 return
1441 }
1442
1443 o := recOptPool.Get().(*[]metric.RecordOption)
1444 defer func() {
1445 *o = (*o)[:0]
1446 recOptPool.Put(o)
1447 }()
1448
1449 *o = append(
1450 *o,
1451 metric.WithAttributes(
1452 append(
1453 attrs,
1454 attribute.String("http.request.method", string(requestMethod)),
1455 attribute.String("url.scheme", urlScheme),
1456 )...,
1457 ),
1458 )
1459
1460 m.Float64Histogram.Record(ctx, val, *o...)
1461 }
1462
1463 // RecordSet records val to the current distribution for set.
1464 func (m ServerRequestDuration) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1465 if set.Len() == 0 {
1466 m.Float64Histogram.Record(ctx, val)
1467 return
1468 }
1469
1470 o := recOptPool.Get().(*[]metric.RecordOption)
1471 defer func() {
1472 *o = (*o)[:0]
1473 recOptPool.Put(o)
1474 }()
1475
1476 *o = append(*o, metric.WithAttributeSet(set))
1477 m.Float64Histogram.Record(ctx, val, *o...)
1478 }
1479
1480 // AttrErrorType returns an optional attribute for the "error.type" semantic
1481 // convention. It represents the describes a class of error the operation ended
1482 // with.
1483 func (ServerRequestDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1484 return attribute.String("error.type", string(val))
1485 }
1486
1487 // AttrResponseStatusCode returns an optional attribute for the
1488 // "http.response.status_code" semantic convention. It represents the
1489 // [HTTP response status code].
1490 //
1491 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1492 func (ServerRequestDuration) AttrResponseStatusCode(val int) attribute.KeyValue {
1493 return attribute.Int("http.response.status_code", val)
1494 }
1495
1496 // AttrRoute returns an optional attribute for the "http.route" semantic
1497 // convention. It represents the matched route, that is, the path template in the
1498 // format used by the respective server framework.
1499 func (ServerRequestDuration) AttrRoute(val string) attribute.KeyValue {
1500 return attribute.String("http.route", val)
1501 }
1502
1503 // AttrNetworkProtocolName returns an optional attribute for the
1504 // "network.protocol.name" semantic convention. It represents the
1505 // [OSI application layer] or non-OSI equivalent.
1506 //
1507 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1508 func (ServerRequestDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
1509 return attribute.String("network.protocol.name", val)
1510 }
1511
1512 // AttrNetworkProtocolVersion returns an optional attribute for the
1513 // "network.protocol.version" semantic convention. It represents the actual
1514 // version of the protocol used for network communication.
1515 func (ServerRequestDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1516 return attribute.String("network.protocol.version", val)
1517 }
1518
1519 // AttrServerAddress returns an optional attribute for the "server.address"
1520 // semantic convention. It represents the name of the local HTTP server that
1521 // received the request.
1522 func (ServerRequestDuration) AttrServerAddress(val string) attribute.KeyValue {
1523 return attribute.String("server.address", val)
1524 }
1525
1526 // AttrServerPort returns an optional attribute for the "server.port" semantic
1527 // convention. It represents the port of the local HTTP server that received the
1528 // request.
1529 func (ServerRequestDuration) AttrServerPort(val int) attribute.KeyValue {
1530 return attribute.Int("server.port", val)
1531 }
1532
1533 // AttrUserAgentSyntheticType returns an optional attribute for the
1534 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1535 // the category of synthetic traffic, such as tests or bots.
1536 func (ServerRequestDuration) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1537 return attribute.String("user_agent.synthetic.type", string(val))
1538 }
1539
1540 // ServerResponseBodySize is an instrument used to record metric values
1541 // conforming to the "http.server.response.body.size" semantic conventions. It
1542 // represents the size of HTTP server response bodies.
1543 type ServerResponseBodySize struct {
1544 metric.Int64Histogram
1545 }
1546
1547 var newServerResponseBodySizeOpts = []metric.Int64HistogramOption{
1548 metric.WithDescription("Size of HTTP server response bodies."),
1549 metric.WithUnit("By"),
1550 }
1551
1552 // NewServerResponseBodySize returns a new ServerResponseBodySize instrument.
1553 func NewServerResponseBodySize(
1554 m metric.Meter,
1555 opt ...metric.Int64HistogramOption,
1556 ) (ServerResponseBodySize, error) {
1557 // Check if the meter is nil.
1558 if m == nil {
1559 return ServerResponseBodySize{noop.Int64Histogram{}}, nil
1560 }
1561
1562 if len(opt) == 0 {
1563 opt = newServerResponseBodySizeOpts
1564 } else {
1565 opt = append(opt, newServerResponseBodySizeOpts...)
1566 }
1567
1568 i, err := m.Int64Histogram(
1569 "http.server.response.body.size",
1570 opt...,
1571 )
1572 if err != nil {
1573 return ServerResponseBodySize{noop.Int64Histogram{}}, err
1574 }
1575 return ServerResponseBodySize{i}, nil
1576 }
1577
1578 // Inst returns the underlying metric instrument.
1579 func (m ServerResponseBodySize) Inst() metric.Int64Histogram {
1580 return m.Int64Histogram
1581 }
1582
1583 // Name returns the semantic convention name of the instrument.
1584 func (ServerResponseBodySize) Name() string {
1585 return "http.server.response.body.size"
1586 }
1587
1588 // Unit returns the semantic convention unit of the instrument
1589 func (ServerResponseBodySize) Unit() string {
1590 return "By"
1591 }
1592
1593 // Description returns the semantic convention description of the instrument
1594 func (ServerResponseBodySize) Description() string {
1595 return "Size of HTTP server response bodies."
1596 }
1597
1598 // Record records val to the current distribution for attrs.
1599 //
1600 // The requestMethod is the HTTP request method.
1601 //
1602 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1603 //
1604 // All additional attrs passed are included in the recorded value.
1605 //
1606 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1607 //
1608 // The size of the response payload body in bytes. This is the number of bytes
1609 // transferred excluding headers and is often, but not always, present as the
1610 // [Content-Length] header. For requests using transport encoding, this should be
1611 // the compressed size.
1612 //
1613 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1614 func (m ServerResponseBodySize) Record(
1615 ctx context.Context,
1616 val int64,
1617 requestMethod RequestMethodAttr,
1618 urlScheme string,
1619 attrs ...attribute.KeyValue,
1620 ) {
1621 if len(attrs) == 0 {
1622 m.Int64Histogram.Record(ctx, val)
1623 return
1624 }
1625
1626 o := recOptPool.Get().(*[]metric.RecordOption)
1627 defer func() {
1628 *o = (*o)[:0]
1629 recOptPool.Put(o)
1630 }()
1631
1632 *o = append(
1633 *o,
1634 metric.WithAttributes(
1635 append(
1636 attrs,
1637 attribute.String("http.request.method", string(requestMethod)),
1638 attribute.String("url.scheme", urlScheme),
1639 )...,
1640 ),
1641 )
1642
1643 m.Int64Histogram.Record(ctx, val, *o...)
1644 }
1645
1646 // RecordSet records val to the current distribution for set.
1647 //
1648 // The size of the response payload body in bytes. This is the number of bytes
1649 // transferred excluding headers and is often, but not always, present as the
1650 // [Content-Length] header. For requests using transport encoding, this should be
1651 // the compressed size.
1652 //
1653 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1654 func (m ServerResponseBodySize) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1655 if set.Len() == 0 {
1656 m.Int64Histogram.Record(ctx, val)
1657 return
1658 }
1659
1660 o := recOptPool.Get().(*[]metric.RecordOption)
1661 defer func() {
1662 *o = (*o)[:0]
1663 recOptPool.Put(o)
1664 }()
1665
1666 *o = append(*o, metric.WithAttributeSet(set))
1667 m.Int64Histogram.Record(ctx, val, *o...)
1668 }
1669
1670 // AttrErrorType returns an optional attribute for the "error.type" semantic
1671 // convention. It represents the describes a class of error the operation ended
1672 // with.
1673 func (ServerResponseBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1674 return attribute.String("error.type", string(val))
1675 }
1676
1677 // AttrResponseStatusCode returns an optional attribute for the
1678 // "http.response.status_code" semantic convention. It represents the
1679 // [HTTP response status code].
1680 //
1681 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1682 func (ServerResponseBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
1683 return attribute.Int("http.response.status_code", val)
1684 }
1685
1686 // AttrRoute returns an optional attribute for the "http.route" semantic
1687 // convention. It represents the matched route, that is, the path template in the
1688 // format used by the respective server framework.
1689 func (ServerResponseBodySize) AttrRoute(val string) attribute.KeyValue {
1690 return attribute.String("http.route", val)
1691 }
1692
1693 // AttrNetworkProtocolName returns an optional attribute for the
1694 // "network.protocol.name" semantic convention. It represents the
1695 // [OSI application layer] or non-OSI equivalent.
1696 //
1697 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1698 func (ServerResponseBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1699 return attribute.String("network.protocol.name", val)
1700 }
1701
1702 // AttrNetworkProtocolVersion returns an optional attribute for the
1703 // "network.protocol.version" semantic convention. It represents the actual
1704 // version of the protocol used for network communication.
1705 func (ServerResponseBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1706 return attribute.String("network.protocol.version", val)
1707 }
1708
1709 // AttrServerAddress returns an optional attribute for the "server.address"
1710 // semantic convention. It represents the name of the local HTTP server that
1711 // received the request.
1712 func (ServerResponseBodySize) AttrServerAddress(val string) attribute.KeyValue {
1713 return attribute.String("server.address", val)
1714 }
1715
1716 // AttrServerPort returns an optional attribute for the "server.port" semantic
1717 // convention. It represents the port of the local HTTP server that received the
1718 // request.
1719 func (ServerResponseBodySize) AttrServerPort(val int) attribute.KeyValue {
1720 return attribute.Int("server.port", val)
1721 }
1722
1723 // AttrUserAgentSyntheticType returns an optional attribute for the
1724 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1725 // the category of synthetic traffic, such as tests or bots.
1726 func (ServerResponseBodySize) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1727 return attribute.String("user_agent.synthetic.type", string(val))
1728 }