Debian Codegraph @

semconv/v1.34.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.
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 o := addOptPool.Get().(*[]metric.AddOption)
156 defer func() {
157 *o = (*o)[:0]
158 addOptPool.Put(o)
159 }()
160
161 *o = append(
162 *o,
163 metric.WithAttributes(
164 append(
165 attrs,
166 attribute.String("server.address", serverAddress),
167 attribute.Int("server.port", serverPort),
168 )...,
169 ),
170 )
171
172 m.Int64UpDownCounter.Add(ctx, incr, *o...)
173 }
174
175 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
176 // convention. It represents the low-cardinality template of an
177 // [absolute path reference].
178 //
179 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
180 func (ClientActiveRequests) AttrURLTemplate(val string) attribute.KeyValue {
181 return attribute.String("url.template", val)
182 }
183
184 // AttrRequestMethod returns an optional attribute for the "http.request.method"
185 // semantic convention. It represents the HTTP request method.
186 func (ClientActiveRequests) AttrRequestMethod(val RequestMethodAttr) attribute.KeyValue {
187 return attribute.String("http.request.method", string(val))
188 }
189
190 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
191 // convention. It represents the [URI scheme] component identifying the used
192 // protocol.
193 //
194 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
195 func (ClientActiveRequests) AttrURLScheme(val string) attribute.KeyValue {
196 return attribute.String("url.scheme", val)
197 }
198
199 // ClientConnectionDuration is an instrument used to record metric values
200 // conforming to the "http.client.connection.duration" semantic conventions. It
201 // represents the duration of the successfully established outbound HTTP
202 // connections.
203 type ClientConnectionDuration struct {
204 metric.Float64Histogram
205 }
206
207 // NewClientConnectionDuration returns a new ClientConnectionDuration instrument.
208 func NewClientConnectionDuration(
209 m metric.Meter,
210 opt ...metric.Float64HistogramOption,
211 ) (ClientConnectionDuration, error) {
212 // Check if the meter is nil.
213 if m == nil {
214 return ClientConnectionDuration{noop.Float64Histogram{}}, nil
215 }
216
217 i, err := m.Float64Histogram(
218 "http.client.connection.duration",
219 append([]metric.Float64HistogramOption{
220 metric.WithDescription("The duration of the successfully established outbound HTTP connections."),
221 metric.WithUnit("s"),
222 }, opt...)...,
223 )
224 if err != nil {
225 return ClientConnectionDuration{noop.Float64Histogram{}}, err
226 }
227 return ClientConnectionDuration{i}, nil
228 }
229
230 // Inst returns the underlying metric instrument.
231 func (m ClientConnectionDuration) Inst() metric.Float64Histogram {
232 return m.Float64Histogram
233 }
234
235 // Name returns the semantic convention name of the instrument.
236 func (ClientConnectionDuration) Name() string {
237 return "http.client.connection.duration"
238 }
239
240 // Unit returns the semantic convention unit of the instrument
241 func (ClientConnectionDuration) Unit() string {
242 return "s"
243 }
244
245 // Description returns the semantic convention description of the instrument
246 func (ClientConnectionDuration) Description() string {
247 return "The duration of the successfully established outbound HTTP connections."
248 }
249
250 // Record records val to the current distribution.
251 //
252 // The serverAddress is the server domain name if available without reverse DNS
253 // lookup; otherwise, IP address or Unix domain socket name.
254 //
255 // The serverPort is the port identifier of the ["URI origin"] HTTP request is
256 // sent to.
257 //
258 // All additional attrs passed are included in the recorded value.
259 //
260 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
261 func (m ClientConnectionDuration) Record(
262 ctx context.Context,
263 val float64,
264 serverAddress string,
265 serverPort int,
266 attrs ...attribute.KeyValue,
267 ) {
268 o := recOptPool.Get().(*[]metric.RecordOption)
269 defer func() {
270 *o = (*o)[:0]
271 recOptPool.Put(o)
272 }()
273
274 *o = append(
275 *o,
276 metric.WithAttributes(
277 append(
278 attrs,
279 attribute.String("server.address", serverAddress),
280 attribute.Int("server.port", serverPort),
281 )...,
282 ),
283 )
284
285 m.Float64Histogram.Record(ctx, val, *o...)
286 }
287
288 // AttrNetworkPeerAddress returns an optional attribute for the
289 // "network.peer.address" semantic convention. It represents the peer address of
290 // the network connection - IP address or Unix domain socket name.
291 func (ClientConnectionDuration) AttrNetworkPeerAddress(val string) attribute.KeyValue {
292 return attribute.String("network.peer.address", val)
293 }
294
295 // AttrNetworkProtocolVersion returns an optional attribute for the
296 // "network.protocol.version" semantic convention. It represents the actual
297 // version of the protocol used for network communication.
298 func (ClientConnectionDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
299 return attribute.String("network.protocol.version", val)
300 }
301
302 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
303 // convention. It represents the [URI scheme] component identifying the used
304 // protocol.
305 //
306 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
307 func (ClientConnectionDuration) AttrURLScheme(val string) attribute.KeyValue {
308 return attribute.String("url.scheme", val)
309 }
310
311 // ClientOpenConnections is an instrument used to record metric values conforming
312 // to the "http.client.open_connections" semantic conventions. It represents the
313 // number of outbound HTTP connections that are currently active or idle on the
314 // client.
315 type ClientOpenConnections struct {
316 metric.Int64UpDownCounter
317 }
318
319 // NewClientOpenConnections returns a new ClientOpenConnections instrument.
320 func NewClientOpenConnections(
321 m metric.Meter,
322 opt ...metric.Int64UpDownCounterOption,
323 ) (ClientOpenConnections, error) {
324 // Check if the meter is nil.
325 if m == nil {
326 return ClientOpenConnections{noop.Int64UpDownCounter{}}, nil
327 }
328
329 i, err := m.Int64UpDownCounter(
330 "http.client.open_connections",
331 append([]metric.Int64UpDownCounterOption{
332 metric.WithDescription("Number of outbound HTTP connections that are currently active or idle on the client."),
333 metric.WithUnit("{connection}"),
334 }, opt...)...,
335 )
336 if err != nil {
337 return ClientOpenConnections{noop.Int64UpDownCounter{}}, err
338 }
339 return ClientOpenConnections{i}, nil
340 }
341
342 // Inst returns the underlying metric instrument.
343 func (m ClientOpenConnections) Inst() metric.Int64UpDownCounter {
344 return m.Int64UpDownCounter
345 }
346
347 // Name returns the semantic convention name of the instrument.
348 func (ClientOpenConnections) Name() string {
349 return "http.client.open_connections"
350 }
351
352 // Unit returns the semantic convention unit of the instrument
353 func (ClientOpenConnections) Unit() string {
354 return "{connection}"
355 }
356
357 // Description returns the semantic convention description of the instrument
358 func (ClientOpenConnections) Description() string {
359 return "Number of outbound HTTP connections that are currently active or idle on the client."
360 }
361
362 // Add adds incr to the existing count.
363 //
364 // The connectionState is the state of the HTTP connection in the HTTP connection
365 // pool.
366 //
367 // The serverAddress is the server domain name if available without reverse DNS
368 // lookup; otherwise, IP address or Unix domain socket name.
369 //
370 // The serverPort is the port identifier of the ["URI origin"] HTTP request is
371 // sent to.
372 //
373 // All additional attrs passed are included in the recorded value.
374 //
375 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
376 func (m ClientOpenConnections) Add(
377 ctx context.Context,
378 incr int64,
379 connectionState ConnectionStateAttr,
380 serverAddress string,
381 serverPort int,
382 attrs ...attribute.KeyValue,
383 ) {
384 o := addOptPool.Get().(*[]metric.AddOption)
385 defer func() {
386 *o = (*o)[:0]
387 addOptPool.Put(o)
388 }()
389
390 *o = append(
391 *o,
392 metric.WithAttributes(
393 append(
394 attrs,
395 attribute.String("http.connection.state", string(connectionState)),
396 attribute.String("server.address", serverAddress),
397 attribute.Int("server.port", serverPort),
398 )...,
399 ),
400 )
401
402 m.Int64UpDownCounter.Add(ctx, incr, *o...)
403 }
404
405 // AttrNetworkPeerAddress returns an optional attribute for the
406 // "network.peer.address" semantic convention. It represents the peer address of
407 // the network connection - IP address or Unix domain socket name.
408 func (ClientOpenConnections) AttrNetworkPeerAddress(val string) attribute.KeyValue {
409 return attribute.String("network.peer.address", val)
410 }
411
412 // AttrNetworkProtocolVersion returns an optional attribute for the
413 // "network.protocol.version" semantic convention. It represents the actual
414 // version of the protocol used for network communication.
415 func (ClientOpenConnections) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
416 return attribute.String("network.protocol.version", val)
417 }
418
419 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
420 // convention. It represents the [URI scheme] component identifying the used
421 // protocol.
422 //
423 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
424 func (ClientOpenConnections) AttrURLScheme(val string) attribute.KeyValue {
425 return attribute.String("url.scheme", val)
426 }
427
428 // ClientRequestBodySize is an instrument used to record metric values conforming
429 // to the "http.client.request.body.size" semantic conventions. It represents the
430 // size of HTTP client request bodies.
431 type ClientRequestBodySize struct {
432 metric.Int64Histogram
433 }
434
435 // NewClientRequestBodySize returns a new ClientRequestBodySize instrument.
436 func NewClientRequestBodySize(
437 m metric.Meter,
438 opt ...metric.Int64HistogramOption,
439 ) (ClientRequestBodySize, error) {
440 // Check if the meter is nil.
441 if m == nil {
442 return ClientRequestBodySize{noop.Int64Histogram{}}, nil
443 }
444
445 i, err := m.Int64Histogram(
446 "http.client.request.body.size",
447 append([]metric.Int64HistogramOption{
448 metric.WithDescription("Size of HTTP client request bodies."),
449 metric.WithUnit("By"),
450 }, opt...)...,
451 )
452 if err != nil {
453 return ClientRequestBodySize{noop.Int64Histogram{}}, err
454 }
455 return ClientRequestBodySize{i}, nil
456 }
457
458 // Inst returns the underlying metric instrument.
459 func (m ClientRequestBodySize) Inst() metric.Int64Histogram {
460 return m.Int64Histogram
461 }
462
463 // Name returns the semantic convention name of the instrument.
464 func (ClientRequestBodySize) Name() string {
465 return "http.client.request.body.size"
466 }
467
468 // Unit returns the semantic convention unit of the instrument
469 func (ClientRequestBodySize) Unit() string {
470 return "By"
471 }
472
473 // Description returns the semantic convention description of the instrument
474 func (ClientRequestBodySize) Description() string {
475 return "Size of HTTP client request bodies."
476 }
477
478 // Record records val to the current distribution.
479 //
480 // The requestMethod is the HTTP request method.
481 //
482 // The serverAddress is the host identifier of the ["URI origin"] HTTP request is
483 // sent to.
484 //
485 // The serverPort is the port identifier of the ["URI origin"] HTTP request is
486 // sent to.
487 //
488 // All additional attrs passed are included in the recorded value.
489 //
490 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
491 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
492 //
493 // The size of the request payload body in bytes. This is the number of bytes
494 // transferred excluding headers and is often, but not always, present as the
495 // [Content-Length] header. For requests using transport encoding, this should be
496 // the compressed size.
497 //
498 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
499 func (m ClientRequestBodySize) Record(
500 ctx context.Context,
501 val int64,
502 requestMethod RequestMethodAttr,
503 serverAddress string,
504 serverPort int,
505 attrs ...attribute.KeyValue,
506 ) {
507 o := recOptPool.Get().(*[]metric.RecordOption)
508 defer func() {
509 *o = (*o)[:0]
510 recOptPool.Put(o)
511 }()
512
513 *o = append(
514 *o,
515 metric.WithAttributes(
516 append(
517 attrs,
518 attribute.String("http.request.method", string(requestMethod)),
519 attribute.String("server.address", serverAddress),
520 attribute.Int("server.port", serverPort),
521 )...,
522 ),
523 )
524
525 m.Int64Histogram.Record(ctx, val, *o...)
526 }
527
528 // AttrErrorType returns an optional attribute for the "error.type" semantic
529 // convention. It represents the describes a class of error the operation ended
530 // with.
531 func (ClientRequestBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
532 return attribute.String("error.type", string(val))
533 }
534
535 // AttrResponseStatusCode returns an optional attribute for the
536 // "http.response.status_code" semantic convention. It represents the
537 // [HTTP response status code].
538 //
539 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
540 func (ClientRequestBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
541 return attribute.Int("http.response.status_code", val)
542 }
543
544 // AttrNetworkProtocolName returns an optional attribute for the
545 // "network.protocol.name" semantic convention. It represents the
546 // [OSI application layer] or non-OSI equivalent.
547 //
548 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
549 func (ClientRequestBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
550 return attribute.String("network.protocol.name", val)
551 }
552
553 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
554 // convention. It represents the low-cardinality template of an
555 // [absolute path reference].
556 //
557 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
558 func (ClientRequestBodySize) AttrURLTemplate(val string) attribute.KeyValue {
559 return attribute.String("url.template", val)
560 }
561
562 // AttrNetworkProtocolVersion returns an optional attribute for the
563 // "network.protocol.version" semantic convention. It represents the actual
564 // version of the protocol used for network communication.
565 func (ClientRequestBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
566 return attribute.String("network.protocol.version", val)
567 }
568
569 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
570 // convention. It represents the [URI scheme] component identifying the used
571 // protocol.
572 //
573 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
574 func (ClientRequestBodySize) AttrURLScheme(val string) attribute.KeyValue {
575 return attribute.String("url.scheme", val)
576 }
577
578 // ClientRequestDuration is an instrument used to record metric values conforming
579 // to the "http.client.request.duration" semantic conventions. It represents the
580 // duration of HTTP client requests.
581 type ClientRequestDuration struct {
582 metric.Float64Histogram
583 }
584
585 // NewClientRequestDuration returns a new ClientRequestDuration instrument.
586 func NewClientRequestDuration(
587 m metric.Meter,
588 opt ...metric.Float64HistogramOption,
589 ) (ClientRequestDuration, error) {
590 // Check if the meter is nil.
591 if m == nil {
592 return ClientRequestDuration{noop.Float64Histogram{}}, nil
593 }
594
595 i, err := m.Float64Histogram(
596 "http.client.request.duration",
597 append([]metric.Float64HistogramOption{
598 metric.WithDescription("Duration of HTTP client requests."),
599 metric.WithUnit("s"),
600 }, opt...)...,
601 )
602 if err != nil {
603 return ClientRequestDuration{noop.Float64Histogram{}}, err
604 }
605 return ClientRequestDuration{i}, nil
606 }
607
608 // Inst returns the underlying metric instrument.
609 func (m ClientRequestDuration) Inst() metric.Float64Histogram {
610 return m.Float64Histogram
611 }
612
613 // Name returns the semantic convention name of the instrument.
614 func (ClientRequestDuration) Name() string {
615 return "http.client.request.duration"
616 }
617
618 // Unit returns the semantic convention unit of the instrument
619 func (ClientRequestDuration) Unit() string {
620 return "s"
621 }
622
623 // Description returns the semantic convention description of the instrument
624 func (ClientRequestDuration) Description() string {
625 return "Duration of HTTP client requests."
626 }
627
628 // Record records val to the current distribution.
629 //
630 // The requestMethod is the HTTP request method.
631 //
632 // The serverAddress is the host identifier of the ["URI origin"] HTTP request is
633 // sent to.
634 //
635 // The serverPort is the port identifier of the ["URI origin"] HTTP request is
636 // sent to.
637 //
638 // All additional attrs passed are included in the recorded value.
639 //
640 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
641 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
642 func (m ClientRequestDuration) Record(
643 ctx context.Context,
644 val float64,
645 requestMethod RequestMethodAttr,
646 serverAddress string,
647 serverPort int,
648 attrs ...attribute.KeyValue,
649 ) {
650 o := recOptPool.Get().(*[]metric.RecordOption)
651 defer func() {
652 *o = (*o)[:0]
653 recOptPool.Put(o)
654 }()
655
656 *o = append(
657 *o,
658 metric.WithAttributes(
659 append(
660 attrs,
661 attribute.String("http.request.method", string(requestMethod)),
662 attribute.String("server.address", serverAddress),
663 attribute.Int("server.port", serverPort),
664 )...,
665 ),
666 )
667
668 m.Float64Histogram.Record(ctx, val, *o...)
669 }
670
671 // AttrErrorType returns an optional attribute for the "error.type" semantic
672 // convention. It represents the describes a class of error the operation ended
673 // with.
674 func (ClientRequestDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
675 return attribute.String("error.type", string(val))
676 }
677
678 // AttrResponseStatusCode returns an optional attribute for the
679 // "http.response.status_code" semantic convention. It represents the
680 // [HTTP response status code].
681 //
682 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
683 func (ClientRequestDuration) AttrResponseStatusCode(val int) attribute.KeyValue {
684 return attribute.Int("http.response.status_code", val)
685 }
686
687 // AttrNetworkProtocolName returns an optional attribute for the
688 // "network.protocol.name" semantic convention. It represents the
689 // [OSI application layer] or non-OSI equivalent.
690 //
691 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
692 func (ClientRequestDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
693 return attribute.String("network.protocol.name", val)
694 }
695
696 // AttrNetworkProtocolVersion returns an optional attribute for the
697 // "network.protocol.version" semantic convention. It represents the actual
698 // version of the protocol used for network communication.
699 func (ClientRequestDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
700 return attribute.String("network.protocol.version", val)
701 }
702
703 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
704 // convention. It represents the [URI scheme] component identifying the used
705 // protocol.
706 //
707 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
708 func (ClientRequestDuration) AttrURLScheme(val string) attribute.KeyValue {
709 return attribute.String("url.scheme", val)
710 }
711
712 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
713 // convention. It represents the low-cardinality template of an
714 // [absolute path reference].
715 //
716 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
717 func (ClientRequestDuration) AttrURLTemplate(val string) attribute.KeyValue {
718 return attribute.String("url.template", val)
719 }
720
721 // ClientResponseBodySize is an instrument used to record metric values
722 // conforming to the "http.client.response.body.size" semantic conventions. It
723 // represents the size of HTTP client response bodies.
724 type ClientResponseBodySize struct {
725 metric.Int64Histogram
726 }
727
728 // NewClientResponseBodySize returns a new ClientResponseBodySize instrument.
729 func NewClientResponseBodySize(
730 m metric.Meter,
731 opt ...metric.Int64HistogramOption,
732 ) (ClientResponseBodySize, error) {
733 // Check if the meter is nil.
734 if m == nil {
735 return ClientResponseBodySize{noop.Int64Histogram{}}, nil
736 }
737
738 i, err := m.Int64Histogram(
739 "http.client.response.body.size",
740 append([]metric.Int64HistogramOption{
741 metric.WithDescription("Size of HTTP client response bodies."),
742 metric.WithUnit("By"),
743 }, opt...)...,
744 )
745 if err != nil {
746 return ClientResponseBodySize{noop.Int64Histogram{}}, err
747 }
748 return ClientResponseBodySize{i}, nil
749 }
750
751 // Inst returns the underlying metric instrument.
752 func (m ClientResponseBodySize) Inst() metric.Int64Histogram {
753 return m.Int64Histogram
754 }
755
756 // Name returns the semantic convention name of the instrument.
757 func (ClientResponseBodySize) Name() string {
758 return "http.client.response.body.size"
759 }
760
761 // Unit returns the semantic convention unit of the instrument
762 func (ClientResponseBodySize) Unit() string {
763 return "By"
764 }
765
766 // Description returns the semantic convention description of the instrument
767 func (ClientResponseBodySize) Description() string {
768 return "Size of HTTP client response bodies."
769 }
770
771 // Record records val to the current distribution.
772 //
773 // The requestMethod is the HTTP request method.
774 //
775 // The serverAddress is the host identifier of the ["URI origin"] HTTP request is
776 // sent to.
777 //
778 // The serverPort is the port identifier of the ["URI origin"] HTTP request is
779 // sent to.
780 //
781 // All additional attrs passed are included in the recorded value.
782 //
783 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
784 // ["URI origin"]: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
785 //
786 // The size of the response payload body in bytes. This is the number of bytes
787 // transferred excluding headers and is often, but not always, present as the
788 // [Content-Length] header. For requests using transport encoding, this should be
789 // the compressed size.
790 //
791 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
792 func (m ClientResponseBodySize) Record(
793 ctx context.Context,
794 val int64,
795 requestMethod RequestMethodAttr,
796 serverAddress string,
797 serverPort int,
798 attrs ...attribute.KeyValue,
799 ) {
800 o := recOptPool.Get().(*[]metric.RecordOption)
801 defer func() {
802 *o = (*o)[:0]
803 recOptPool.Put(o)
804 }()
805
806 *o = append(
807 *o,
808 metric.WithAttributes(
809 append(
810 attrs,
811 attribute.String("http.request.method", string(requestMethod)),
812 attribute.String("server.address", serverAddress),
813 attribute.Int("server.port", serverPort),
814 )...,
815 ),
816 )
817
818 m.Int64Histogram.Record(ctx, val, *o...)
819 }
820
821 // AttrErrorType returns an optional attribute for the "error.type" semantic
822 // convention. It represents the describes a class of error the operation ended
823 // with.
824 func (ClientResponseBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
825 return attribute.String("error.type", string(val))
826 }
827
828 // AttrResponseStatusCode returns an optional attribute for the
829 // "http.response.status_code" semantic convention. It represents the
830 // [HTTP response status code].
831 //
832 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
833 func (ClientResponseBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
834 return attribute.Int("http.response.status_code", val)
835 }
836
837 // AttrNetworkProtocolName returns an optional attribute for the
838 // "network.protocol.name" semantic convention. It represents the
839 // [OSI application layer] or non-OSI equivalent.
840 //
841 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
842 func (ClientResponseBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
843 return attribute.String("network.protocol.name", val)
844 }
845
846 // AttrURLTemplate returns an optional attribute for the "url.template" semantic
847 // convention. It represents the low-cardinality template of an
848 // [absolute path reference].
849 //
850 // [absolute path reference]: https://www.rfc-editor.org/rfc/rfc3986#section-4.2
851 func (ClientResponseBodySize) AttrURLTemplate(val string) attribute.KeyValue {
852 return attribute.String("url.template", val)
853 }
854
855 // AttrNetworkProtocolVersion returns an optional attribute for the
856 // "network.protocol.version" semantic convention. It represents the actual
857 // version of the protocol used for network communication.
858 func (ClientResponseBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
859 return attribute.String("network.protocol.version", val)
860 }
861
862 // AttrURLScheme returns an optional attribute for the "url.scheme" semantic
863 // convention. It represents the [URI scheme] component identifying the used
864 // protocol.
865 //
866 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
867 func (ClientResponseBodySize) AttrURLScheme(val string) attribute.KeyValue {
868 return attribute.String("url.scheme", val)
869 }
870
871 // ServerActiveRequests is an instrument used to record metric values conforming
872 // to the "http.server.active_requests" semantic conventions. It represents the
873 // number of active HTTP server requests.
874 type ServerActiveRequests struct {
875 metric.Int64UpDownCounter
876 }
877
878 // NewServerActiveRequests returns a new ServerActiveRequests instrument.
879 func NewServerActiveRequests(
880 m metric.Meter,
881 opt ...metric.Int64UpDownCounterOption,
882 ) (ServerActiveRequests, error) {
883 // Check if the meter is nil.
884 if m == nil {
885 return ServerActiveRequests{noop.Int64UpDownCounter{}}, nil
886 }
887
888 i, err := m.Int64UpDownCounter(
889 "http.server.active_requests",
890 append([]metric.Int64UpDownCounterOption{
891 metric.WithDescription("Number of active HTTP server requests."),
892 metric.WithUnit("{request}"),
893 }, opt...)...,
894 )
895 if err != nil {
896 return ServerActiveRequests{noop.Int64UpDownCounter{}}, err
897 }
898 return ServerActiveRequests{i}, nil
899 }
900
901 // Inst returns the underlying metric instrument.
902 func (m ServerActiveRequests) Inst() metric.Int64UpDownCounter {
903 return m.Int64UpDownCounter
904 }
905
906 // Name returns the semantic convention name of the instrument.
907 func (ServerActiveRequests) Name() string {
908 return "http.server.active_requests"
909 }
910
911 // Unit returns the semantic convention unit of the instrument
912 func (ServerActiveRequests) Unit() string {
913 return "{request}"
914 }
915
916 // Description returns the semantic convention description of the instrument
917 func (ServerActiveRequests) Description() string {
918 return "Number of active HTTP server requests."
919 }
920
921 // Add adds incr to the existing count.
922 //
923 // The requestMethod is the HTTP request method.
924 //
925 // The urlScheme is the the [URI scheme] component identifying the used protocol.
926 //
927 // All additional attrs passed are included in the recorded value.
928 //
929 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
930 func (m ServerActiveRequests) Add(
931 ctx context.Context,
932 incr int64,
933 requestMethod RequestMethodAttr,
934 urlScheme string,
935 attrs ...attribute.KeyValue,
936 ) {
937 o := addOptPool.Get().(*[]metric.AddOption)
938 defer func() {
939 *o = (*o)[:0]
940 addOptPool.Put(o)
941 }()
942
943 *o = append(
944 *o,
945 metric.WithAttributes(
946 append(
947 attrs,
948 attribute.String("http.request.method", string(requestMethod)),
949 attribute.String("url.scheme", urlScheme),
950 )...,
951 ),
952 )
953
954 m.Int64UpDownCounter.Add(ctx, incr, *o...)
955 }
956
957 // AttrServerAddress returns an optional attribute for the "server.address"
958 // semantic convention. It represents the name of the local HTTP server that
959 // received the request.
960 func (ServerActiveRequests) AttrServerAddress(val string) attribute.KeyValue {
961 return attribute.String("server.address", val)
962 }
963
964 // AttrServerPort returns an optional attribute for the "server.port" semantic
965 // convention. It represents the port of the local HTTP server that received the
966 // request.
967 func (ServerActiveRequests) AttrServerPort(val int) attribute.KeyValue {
968 return attribute.Int("server.port", val)
969 }
970
971 // ServerRequestBodySize is an instrument used to record metric values conforming
972 // to the "http.server.request.body.size" semantic conventions. It represents the
973 // size of HTTP server request bodies.
974 type ServerRequestBodySize struct {
975 metric.Int64Histogram
976 }
977
978 // NewServerRequestBodySize returns a new ServerRequestBodySize instrument.
979 func NewServerRequestBodySize(
980 m metric.Meter,
981 opt ...metric.Int64HistogramOption,
982 ) (ServerRequestBodySize, error) {
983 // Check if the meter is nil.
984 if m == nil {
985 return ServerRequestBodySize{noop.Int64Histogram{}}, nil
986 }
987
988 i, err := m.Int64Histogram(
989 "http.server.request.body.size",
990 append([]metric.Int64HistogramOption{
991 metric.WithDescription("Size of HTTP server request bodies."),
992 metric.WithUnit("By"),
993 }, opt...)...,
994 )
995 if err != nil {
996 return ServerRequestBodySize{noop.Int64Histogram{}}, err
997 }
998 return ServerRequestBodySize{i}, nil
999 }
1000
1001 // Inst returns the underlying metric instrument.
1002 func (m ServerRequestBodySize) Inst() metric.Int64Histogram {
1003 return m.Int64Histogram
1004 }
1005
1006 // Name returns the semantic convention name of the instrument.
1007 func (ServerRequestBodySize) Name() string {
1008 return "http.server.request.body.size"
1009 }
1010
1011 // Unit returns the semantic convention unit of the instrument
1012 func (ServerRequestBodySize) Unit() string {
1013 return "By"
1014 }
1015
1016 // Description returns the semantic convention description of the instrument
1017 func (ServerRequestBodySize) Description() string {
1018 return "Size of HTTP server request bodies."
1019 }
1020
1021 // Record records val to the current distribution.
1022 //
1023 // The requestMethod is the HTTP request method.
1024 //
1025 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1026 //
1027 // All additional attrs passed are included in the recorded value.
1028 //
1029 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1030 //
1031 // The size of the request payload body in bytes. This is the number of bytes
1032 // transferred excluding headers and is often, but not always, present as the
1033 // [Content-Length] header. For requests using transport encoding, this should be
1034 // the compressed size.
1035 //
1036 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1037 func (m ServerRequestBodySize) Record(
1038 ctx context.Context,
1039 val int64,
1040 requestMethod RequestMethodAttr,
1041 urlScheme string,
1042 attrs ...attribute.KeyValue,
1043 ) {
1044 o := recOptPool.Get().(*[]metric.RecordOption)
1045 defer func() {
1046 *o = (*o)[:0]
1047 recOptPool.Put(o)
1048 }()
1049
1050 *o = append(
1051 *o,
1052 metric.WithAttributes(
1053 append(
1054 attrs,
1055 attribute.String("http.request.method", string(requestMethod)),
1056 attribute.String("url.scheme", urlScheme),
1057 )...,
1058 ),
1059 )
1060
1061 m.Int64Histogram.Record(ctx, val, *o...)
1062 }
1063
1064 // AttrErrorType returns an optional attribute for the "error.type" semantic
1065 // convention. It represents the describes a class of error the operation ended
1066 // with.
1067 func (ServerRequestBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1068 return attribute.String("error.type", string(val))
1069 }
1070
1071 // AttrResponseStatusCode returns an optional attribute for the
1072 // "http.response.status_code" semantic convention. It represents the
1073 // [HTTP response status code].
1074 //
1075 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1076 func (ServerRequestBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
1077 return attribute.Int("http.response.status_code", val)
1078 }
1079
1080 // AttrRoute returns an optional attribute for the "http.route" semantic
1081 // convention. It represents the matched route, that is, the path template in the
1082 // format used by the respective server framework.
1083 func (ServerRequestBodySize) AttrRoute(val string) attribute.KeyValue {
1084 return attribute.String("http.route", val)
1085 }
1086
1087 // AttrNetworkProtocolName returns an optional attribute for the
1088 // "network.protocol.name" semantic convention. It represents the
1089 // [OSI application layer] or non-OSI equivalent.
1090 //
1091 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1092 func (ServerRequestBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1093 return attribute.String("network.protocol.name", val)
1094 }
1095
1096 // AttrNetworkProtocolVersion returns an optional attribute for the
1097 // "network.protocol.version" semantic convention. It represents the actual
1098 // version of the protocol used for network communication.
1099 func (ServerRequestBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1100 return attribute.String("network.protocol.version", val)
1101 }
1102
1103 // AttrServerAddress returns an optional attribute for the "server.address"
1104 // semantic convention. It represents the name of the local HTTP server that
1105 // received the request.
1106 func (ServerRequestBodySize) AttrServerAddress(val string) attribute.KeyValue {
1107 return attribute.String("server.address", val)
1108 }
1109
1110 // AttrServerPort returns an optional attribute for the "server.port" semantic
1111 // convention. It represents the port of the local HTTP server that received the
1112 // request.
1113 func (ServerRequestBodySize) AttrServerPort(val int) attribute.KeyValue {
1114 return attribute.Int("server.port", val)
1115 }
1116
1117 // AttrUserAgentSyntheticType returns an optional attribute for the
1118 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1119 // the category of synthetic traffic, such as tests or bots.
1120 func (ServerRequestBodySize) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1121 return attribute.String("user_agent.synthetic.type", string(val))
1122 }
1123
1124 // ServerRequestDuration is an instrument used to record metric values conforming
1125 // to the "http.server.request.duration" semantic conventions. It represents the
1126 // duration of HTTP server requests.
1127 type ServerRequestDuration struct {
1128 metric.Float64Histogram
1129 }
1130
1131 // NewServerRequestDuration returns a new ServerRequestDuration instrument.
1132 func NewServerRequestDuration(
1133 m metric.Meter,
1134 opt ...metric.Float64HistogramOption,
1135 ) (ServerRequestDuration, error) {
1136 // Check if the meter is nil.
1137 if m == nil {
1138 return ServerRequestDuration{noop.Float64Histogram{}}, nil
1139 }
1140
1141 i, err := m.Float64Histogram(
1142 "http.server.request.duration",
1143 append([]metric.Float64HistogramOption{
1144 metric.WithDescription("Duration of HTTP server requests."),
1145 metric.WithUnit("s"),
1146 }, opt...)...,
1147 )
1148 if err != nil {
1149 return ServerRequestDuration{noop.Float64Histogram{}}, err
1150 }
1151 return ServerRequestDuration{i}, nil
1152 }
1153
1154 // Inst returns the underlying metric instrument.
1155 func (m ServerRequestDuration) Inst() metric.Float64Histogram {
1156 return m.Float64Histogram
1157 }
1158
1159 // Name returns the semantic convention name of the instrument.
1160 func (ServerRequestDuration) Name() string {
1161 return "http.server.request.duration"
1162 }
1163
1164 // Unit returns the semantic convention unit of the instrument
1165 func (ServerRequestDuration) Unit() string {
1166 return "s"
1167 }
1168
1169 // Description returns the semantic convention description of the instrument
1170 func (ServerRequestDuration) Description() string {
1171 return "Duration of HTTP server requests."
1172 }
1173
1174 // Record records val to the current distribution.
1175 //
1176 // The requestMethod is the HTTP request method.
1177 //
1178 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1179 //
1180 // All additional attrs passed are included in the recorded value.
1181 //
1182 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1183 func (m ServerRequestDuration) Record(
1184 ctx context.Context,
1185 val float64,
1186 requestMethod RequestMethodAttr,
1187 urlScheme string,
1188 attrs ...attribute.KeyValue,
1189 ) {
1190 o := recOptPool.Get().(*[]metric.RecordOption)
1191 defer func() {
1192 *o = (*o)[:0]
1193 recOptPool.Put(o)
1194 }()
1195
1196 *o = append(
1197 *o,
1198 metric.WithAttributes(
1199 append(
1200 attrs,
1201 attribute.String("http.request.method", string(requestMethod)),
1202 attribute.String("url.scheme", urlScheme),
1203 )...,
1204 ),
1205 )
1206
1207 m.Float64Histogram.Record(ctx, val, *o...)
1208 }
1209
1210 // AttrErrorType returns an optional attribute for the "error.type" semantic
1211 // convention. It represents the describes a class of error the operation ended
1212 // with.
1213 func (ServerRequestDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1214 return attribute.String("error.type", string(val))
1215 }
1216
1217 // AttrResponseStatusCode returns an optional attribute for the
1218 // "http.response.status_code" semantic convention. It represents the
1219 // [HTTP response status code].
1220 //
1221 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1222 func (ServerRequestDuration) AttrResponseStatusCode(val int) attribute.KeyValue {
1223 return attribute.Int("http.response.status_code", val)
1224 }
1225
1226 // AttrRoute returns an optional attribute for the "http.route" semantic
1227 // convention. It represents the matched route, that is, the path template in the
1228 // format used by the respective server framework.
1229 func (ServerRequestDuration) AttrRoute(val string) attribute.KeyValue {
1230 return attribute.String("http.route", val)
1231 }
1232
1233 // AttrNetworkProtocolName returns an optional attribute for the
1234 // "network.protocol.name" semantic convention. It represents the
1235 // [OSI application layer] or non-OSI equivalent.
1236 //
1237 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1238 func (ServerRequestDuration) AttrNetworkProtocolName(val string) attribute.KeyValue {
1239 return attribute.String("network.protocol.name", val)
1240 }
1241
1242 // AttrNetworkProtocolVersion returns an optional attribute for the
1243 // "network.protocol.version" semantic convention. It represents the actual
1244 // version of the protocol used for network communication.
1245 func (ServerRequestDuration) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1246 return attribute.String("network.protocol.version", val)
1247 }
1248
1249 // AttrServerAddress returns an optional attribute for the "server.address"
1250 // semantic convention. It represents the name of the local HTTP server that
1251 // received the request.
1252 func (ServerRequestDuration) AttrServerAddress(val string) attribute.KeyValue {
1253 return attribute.String("server.address", val)
1254 }
1255
1256 // AttrServerPort returns an optional attribute for the "server.port" semantic
1257 // convention. It represents the port of the local HTTP server that received the
1258 // request.
1259 func (ServerRequestDuration) AttrServerPort(val int) attribute.KeyValue {
1260 return attribute.Int("server.port", val)
1261 }
1262
1263 // AttrUserAgentSyntheticType returns an optional attribute for the
1264 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1265 // the category of synthetic traffic, such as tests or bots.
1266 func (ServerRequestDuration) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1267 return attribute.String("user_agent.synthetic.type", string(val))
1268 }
1269
1270 // ServerResponseBodySize is an instrument used to record metric values
1271 // conforming to the "http.server.response.body.size" semantic conventions. It
1272 // represents the size of HTTP server response bodies.
1273 type ServerResponseBodySize struct {
1274 metric.Int64Histogram
1275 }
1276
1277 // NewServerResponseBodySize returns a new ServerResponseBodySize instrument.
1278 func NewServerResponseBodySize(
1279 m metric.Meter,
1280 opt ...metric.Int64HistogramOption,
1281 ) (ServerResponseBodySize, error) {
1282 // Check if the meter is nil.
1283 if m == nil {
1284 return ServerResponseBodySize{noop.Int64Histogram{}}, nil
1285 }
1286
1287 i, err := m.Int64Histogram(
1288 "http.server.response.body.size",
1289 append([]metric.Int64HistogramOption{
1290 metric.WithDescription("Size of HTTP server response bodies."),
1291 metric.WithUnit("By"),
1292 }, opt...)...,
1293 )
1294 if err != nil {
1295 return ServerResponseBodySize{noop.Int64Histogram{}}, err
1296 }
1297 return ServerResponseBodySize{i}, nil
1298 }
1299
1300 // Inst returns the underlying metric instrument.
1301 func (m ServerResponseBodySize) Inst() metric.Int64Histogram {
1302 return m.Int64Histogram
1303 }
1304
1305 // Name returns the semantic convention name of the instrument.
1306 func (ServerResponseBodySize) Name() string {
1307 return "http.server.response.body.size"
1308 }
1309
1310 // Unit returns the semantic convention unit of the instrument
1311 func (ServerResponseBodySize) Unit() string {
1312 return "By"
1313 }
1314
1315 // Description returns the semantic convention description of the instrument
1316 func (ServerResponseBodySize) Description() string {
1317 return "Size of HTTP server response bodies."
1318 }
1319
1320 // Record records val to the current distribution.
1321 //
1322 // The requestMethod is the HTTP request method.
1323 //
1324 // The urlScheme is the the [URI scheme] component identifying the used protocol.
1325 //
1326 // All additional attrs passed are included in the recorded value.
1327 //
1328 // [URI scheme]: https://www.rfc-editor.org/rfc/rfc3986#section-3.1
1329 //
1330 // The size of the response payload body in bytes. This is the number of bytes
1331 // transferred excluding headers and is often, but not always, present as the
1332 // [Content-Length] header. For requests using transport encoding, this should be
1333 // the compressed size.
1334 //
1335 // [Content-Length]: https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length
1336 func (m ServerResponseBodySize) Record(
1337 ctx context.Context,
1338 val int64,
1339 requestMethod RequestMethodAttr,
1340 urlScheme string,
1341 attrs ...attribute.KeyValue,
1342 ) {
1343 o := recOptPool.Get().(*[]metric.RecordOption)
1344 defer func() {
1345 *o = (*o)[:0]
1346 recOptPool.Put(o)
1347 }()
1348
1349 *o = append(
1350 *o,
1351 metric.WithAttributes(
1352 append(
1353 attrs,
1354 attribute.String("http.request.method", string(requestMethod)),
1355 attribute.String("url.scheme", urlScheme),
1356 )...,
1357 ),
1358 )
1359
1360 m.Int64Histogram.Record(ctx, val, *o...)
1361 }
1362
1363 // AttrErrorType returns an optional attribute for the "error.type" semantic
1364 // convention. It represents the describes a class of error the operation ended
1365 // with.
1366 func (ServerResponseBodySize) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
1367 return attribute.String("error.type", string(val))
1368 }
1369
1370 // AttrResponseStatusCode returns an optional attribute for the
1371 // "http.response.status_code" semantic convention. It represents the
1372 // [HTTP response status code].
1373 //
1374 // [HTTP response status code]: https://tools.ietf.org/html/rfc7231#section-6
1375 func (ServerResponseBodySize) AttrResponseStatusCode(val int) attribute.KeyValue {
1376 return attribute.Int("http.response.status_code", val)
1377 }
1378
1379 // AttrRoute returns an optional attribute for the "http.route" semantic
1380 // convention. It represents the matched route, that is, the path template in the
1381 // format used by the respective server framework.
1382 func (ServerResponseBodySize) AttrRoute(val string) attribute.KeyValue {
1383 return attribute.String("http.route", val)
1384 }
1385
1386 // AttrNetworkProtocolName returns an optional attribute for the
1387 // "network.protocol.name" semantic convention. It represents the
1388 // [OSI application layer] or non-OSI equivalent.
1389 //
1390 // [OSI application layer]: https://wikipedia.org/wiki/Application_layer
1391 func (ServerResponseBodySize) AttrNetworkProtocolName(val string) attribute.KeyValue {
1392 return attribute.String("network.protocol.name", val)
1393 }
1394
1395 // AttrNetworkProtocolVersion returns an optional attribute for the
1396 // "network.protocol.version" semantic convention. It represents the actual
1397 // version of the protocol used for network communication.
1398 func (ServerResponseBodySize) AttrNetworkProtocolVersion(val string) attribute.KeyValue {
1399 return attribute.String("network.protocol.version", val)
1400 }
1401
1402 // AttrServerAddress returns an optional attribute for the "server.address"
1403 // semantic convention. It represents the name of the local HTTP server that
1404 // received the request.
1405 func (ServerResponseBodySize) AttrServerAddress(val string) attribute.KeyValue {
1406 return attribute.String("server.address", val)
1407 }
1408
1409 // AttrServerPort returns an optional attribute for the "server.port" semantic
1410 // convention. It represents the port of the local HTTP server that received the
1411 // request.
1412 func (ServerResponseBodySize) AttrServerPort(val int) attribute.KeyValue {
1413 return attribute.Int("server.port", val)
1414 }
1415
1416 // AttrUserAgentSyntheticType returns an optional attribute for the
1417 // "user_agent.synthetic.type" semantic convention. It represents the specifies
1418 // the category of synthetic traffic, such as tests or bots.
1419 func (ServerResponseBodySize) AttrUserAgentSyntheticType(val UserAgentSyntheticTypeAttr) attribute.KeyValue {
1420 return attribute.String("user_agent.synthetic.type", string(val))
1421 }