Debian Codegraph @

semconv/v1.36.0/httpconv/metric.go

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