Debian Codegraph @

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