Debian Codegraph @

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