Debian Codegraph @

semconv/v1.7.0/http.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package semconv // import "go.opentelemetry.io/otel/semconv/v1.7.0"
5
6 import (
7 "net/http"
8
9 "go.opentelemetry.io/otel/attribute"
10 "go.opentelemetry.io/otel/codes"
11 "go.opentelemetry.io/otel/semconv/internal"
12 "go.opentelemetry.io/otel/trace"
13 )
14
15 // HTTP scheme attributes.
16 var (
17 HTTPSchemeHTTP = HTTPSchemeKey.String("http")
18 HTTPSchemeHTTPS = HTTPSchemeKey.String("https")
19 )
20
21 var sc = &internal.SemanticConventions{
22 EnduserIDKey: EnduserIDKey,
23 HTTPClientIPKey: HTTPClientIPKey,
24 HTTPFlavorKey: HTTPFlavorKey,
25 HTTPHostKey: HTTPHostKey,
26 HTTPMethodKey: HTTPMethodKey,
27 HTTPRequestContentLengthKey: HTTPRequestContentLengthKey,
28 HTTPRouteKey: HTTPRouteKey,
29 HTTPSchemeHTTP: HTTPSchemeHTTP,
30 HTTPSchemeHTTPS: HTTPSchemeHTTPS,
31 HTTPServerNameKey: HTTPServerNameKey,
32 HTTPStatusCodeKey: HTTPStatusCodeKey,
33 HTTPTargetKey: HTTPTargetKey,
34 HTTPURLKey: HTTPURLKey,
35 HTTPUserAgentKey: HTTPUserAgentKey,
36 NetHostIPKey: NetHostIPKey,
37 NetHostNameKey: NetHostNameKey,
38 NetHostPortKey: NetHostPortKey,
39 NetPeerIPKey: NetPeerIPKey,
40 NetPeerNameKey: NetPeerNameKey,
41 NetPeerPortKey: NetPeerPortKey,
42 NetTransportIP: NetTransportIP,
43 NetTransportOther: NetTransportOther,
44 NetTransportTCP: NetTransportTCP,
45 NetTransportUDP: NetTransportUDP,
46 NetTransportUnix: NetTransportUnix,
47 }
48
49 // NetAttributesFromHTTPRequest generates attributes of the net
50 // namespace as specified by the OpenTelemetry specification for a
51 // span. The network parameter is a string that net.Dial function
52 // from standard library can understand.
53 func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue {
54 return sc.NetAttributesFromHTTPRequest(network, request)
55 }
56
57 // EndUserAttributesFromHTTPRequest generates attributes of the
58 // enduser namespace as specified by the OpenTelemetry specification
59 // for a span.
60 func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
61 return sc.EndUserAttributesFromHTTPRequest(request)
62 }
63
64 // HTTPClientAttributesFromHTTPRequest generates attributes of the
65 // http namespace as specified by the OpenTelemetry specification for
66 // a span on the client side.
67 func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
68 return sc.HTTPClientAttributesFromHTTPRequest(request)
69 }
70
71 // HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes
72 // to be used with server-side HTTP metrics.
73 func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue {
74 return sc.HTTPServerMetricAttributesFromHTTPRequest(serverName, request)
75 }
76
77 // HTTPServerAttributesFromHTTPRequest generates attributes of the
78 // http namespace as specified by the OpenTelemetry specification for
79 // a span on the server side. Currently, only basic authentication is
80 // supported.
81 func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue {
82 return sc.HTTPServerAttributesFromHTTPRequest(serverName, route, request)
83 }
84
85 // HTTPAttributesFromHTTPStatusCode generates attributes of the http
86 // namespace as specified by the OpenTelemetry specification for a
87 // span.
88 func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue {
89 return sc.HTTPAttributesFromHTTPStatusCode(code)
90 }
91
92 // SpanStatusFromHTTPStatusCode generates a status code and a message
93 // as specified by the OpenTelemetry specification for a span.
94 func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) {
95 return internal.SpanStatusFromHTTPStatusCode(code)
96 }
97
98 // SpanStatusFromHTTPStatusCodeAndSpanKind generates a status code and a message
99 // as specified by the OpenTelemetry specification for a span.
100 // Exclude 4xx for SERVER to set the appropriate status.
101 func SpanStatusFromHTTPStatusCodeAndSpanKind(code int, spanKind trace.SpanKind) (codes.Code, string) {
102 return internal.SpanStatusFromHTTPStatusCodeAndSpanKind(code, spanKind)
103 }