11
11
//
12
12
//===----------------------------------------------------------------------===//
13
13
14
- #if swift(>=5.2)
15
14
import TracingInstrumentation
16
15
16
+ extension SpanAttributeName {
17
+ public static let httpMethod = " http.method "
18
+ public static let httpURL = " http.url "
19
+ public static let httpTarget = " http.target "
20
+ public static let httpHost = " http.host "
21
+ public static let httpScheme = " http.scheme "
22
+ public static let httpStatusCode = " http.status_code "
23
+ public static let httpStatusText = " http.status_text "
24
+ public static let httpFlavor = " http.flavor "
25
+ public static let httpUserAgent = " http.user_agent "
26
+ public static let httpRequestContentLength = " http.request_content_length "
27
+ public static let httpRequestContentLengthUncompressed = " http.request_content_length_uncompressed "
28
+ public static let httpResponseContentLength = " http.response_content_length "
29
+ public static let httpResponseContentLengthUncompressed = " http.response_content_length_uncompressed "
30
+ public static let httpServerName = " http.server_name "
31
+ public static let httpServerRoute = " http.route "
32
+ public static let httpServerClientIP = " http.client_ip "
33
+ }
34
+
35
+ #if swift(>=5.2)
17
36
extension SpanAttributes {
18
37
/// Semantic conventions for HTTP spans.
19
38
public var http : HTTPAttributes {
@@ -39,64 +58,68 @@ public struct HTTPAttributes: SpanAttributeNamespace {
39
58
public init ( ) { }
40
59
41
60
/// HTTP request method. E.g. "GET".
42
- public var method : SpanAttributeKey < String > { " http.method " }
61
+ public var method : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpMethod ) }
43
62
44
63
/// Full HTTP request URL in the form scheme://host[:port]/path?query[#fragment].
45
64
/// Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless.
46
- public var url : SpanAttributeKey < String > { " http.url " }
65
+ public var url : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpURL ) }
47
66
48
67
/// The full request target as passed in a HTTP request line or equivalent, e.g. "/path/12314/?q=ddds#123".
49
- public var target : SpanAttributeKey < String > { " http.target " }
68
+ public var target : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpTarget ) }
50
69
51
70
/// The value of the HTTP host header. When the header is empty or not present, this attribute should be the same.
52
- public var host : SpanAttributeKey < String > { " http.host " }
71
+ public var host : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpHost ) }
53
72
54
73
/// The URI scheme identifying the used protocol: "http" or "https"
55
- public var scheme : SpanAttributeKey < String > { " http.scheme " }
74
+ public var scheme : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpScheme ) }
56
75
57
76
/// HTTP response status code. E.g. 200.
58
- public var statusCode : SpanAttributeKey < Int > { " http.status_code " }
77
+ public var statusCode : SpanAttributeKey < Int > { . init ( name : SpanAttributeName . httpStatusCode ) }
59
78
60
79
/// HTTP reason phrase. E.g. "OK".
61
- public var statusText : SpanAttributeKey < String > { " http.status_text " }
80
+ public var statusText : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpStatusText ) }
62
81
63
82
/// Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
64
- public var flavor : SpanAttributeKey < String > { " http.flavor " }
83
+ public var flavor : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpFlavor ) }
65
84
66
85
/// Value of the HTTP User-Agent header sent by the client.
67
- public var userAgent : SpanAttributeKey < String > { " http.user_agent " }
86
+ public var userAgent : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpUserAgent ) }
68
87
69
88
/// The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often,
70
89
/// but not always, present as the Content-Length header. For requests using transport encoding, this should be the
71
90
/// compressed size.
72
- public var requestContentLength : SpanAttributeKey < Int > { " http.request_content_length " }
91
+ public var requestContentLength : SpanAttributeKey < Int > {
92
+ . init( name: SpanAttributeName . httpRequestContentLength)
93
+ }
73
94
74
95
/// The size of the uncompressed request payload body after transport decoding. Not set if transport encoding not used.
75
96
public var requestContentLengthUncompressed : SpanAttributeKey < Int > {
76
- " http.request_content_length_uncompressed "
97
+ . init ( name : SpanAttributeName . httpRequestContentLengthUncompressed )
77
98
}
78
99
79
100
/// The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and
80
101
/// is often, but not always, present as the Content-Length header. For requests using transport encoding, this
81
102
/// should be the compressed size.
82
- public var responseContentLength : SpanAttributeKey < Int > { " http.response_content_length " }
103
+ public var responseContentLength : SpanAttributeKey < Int > {
104
+ . init( name: SpanAttributeName . httpResponseContentLength)
105
+ }
83
106
84
107
/// The size of the uncompressed response payload body after transport decoding. Not set if transport encoding not used.
85
108
public var responseContentLengthUncompressed : SpanAttributeKey < Int > {
86
- " http.response_content_length_uncompressed "
109
+ . init ( name : SpanAttributeName . httpResponseContentLengthUncompressed )
87
110
}
88
111
89
112
/// The primary server name of the matched virtual host. This should be obtained via configuration.
90
113
/// If no such configuration can be obtained, this attribute MUST NOT be set (`net.hostName` should be used instead).
91
- public var serverName : SpanAttributeKey < String > { " http.server_name " }
114
+ public var serverName : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpServerName ) }
92
115
93
116
/// The matched route (path template). E.g. "/users/:userID?".
94
- public var serverRoute : SpanAttributeKey < String > { " http.route " }
117
+ public var serverRoute : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpServerRoute ) }
95
118
96
119
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
97
120
/// Note that this is not necessarily the same as `net.peerIP`, which would identify the network-level peer,
98
121
/// which may be a proxy.
99
- public var serverClientIP : SpanAttributeKey < String > { " http.client_ip " }
122
+ public var serverClientIP : SpanAttributeKey < String > { . init ( name : SpanAttributeName . httpServerClientIP ) }
100
123
}
101
124
}
102
125
#endif
0 commit comments