Skip to content

Commit d57e613

Browse files
authored
Merge pull request #136 from slashmo/feature/namespaced-attribute-names
Namespace SpanAttributeNames
2 parents 114fd64 + 4bf7abd commit d57e613

File tree

4 files changed

+89
-77
lines changed

4 files changed

+89
-77
lines changed

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+EndUser.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: EndUserAttributes
18-
public static let endUserID = "enduser.id"
19-
/// - See: EndUserAttributes
20-
public static let endUserRole = "enduser.role"
21-
/// - See: EndUserAttributes
22-
public static let endUserScope = "enduser.scope"
18+
public enum EndUser {
19+
/// - See: EndUserAttributes
20+
public static let id = "enduser.id"
21+
/// - See: EndUserAttributes
22+
public static let role = "enduser.role"
23+
/// - See: EndUserAttributes
24+
public static let scope = "enduser.scope"
25+
}
2326
}
2427

2528
#if swift(>=5.2)
@@ -50,14 +53,14 @@ public struct EndUserAttributes: SpanAttributeNamespace {
5053
public init() {}
5154

5255
/// Username or client_id extracted from the access token or Authorization header in the inbound request from outside the system.
53-
public var id: SpanAttributeKey<String> { .init(name: SpanAttributeName.endUserID) }
56+
public var id: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.id) }
5457

5558
/// Actual/assumed role the client is making the request under extracted from token or application security context.
56-
public var role: SpanAttributeKey<String> { .init(name: SpanAttributeName.endUserRole) }
59+
public var role: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.role) }
5760

5861
/// Scopes or granted authorities the client currently possesses extracted from token or application security context.
5962
/// The value would come from the scope associated with an OAuth 2.0 Access Token or an attribute value in a SAML 2.0 Assertion.
60-
public var scope: SpanAttributeKey<String> { .init(name: SpanAttributeName.endUserScope) }
63+
public var scope: SpanAttributeKey<String> { .init(name: SpanAttributeName.EndUser.scope) }
6164
}
6265
}
6366
#endif

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+HTTPSemantics.swift

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,40 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: HTTPAttributes
18-
public static let httpMethod = "http.method"
19-
/// - See: HTTPAttributes
20-
public static let httpURL = "http.url"
21-
/// - See: HTTPAttributes
22-
public static let httpTarget = "http.target"
23-
/// - See: HTTPAttributes
24-
public static let httpHost = "http.host"
25-
/// - See: HTTPAttributes
26-
public static let httpScheme = "http.scheme"
27-
/// - See: HTTPAttributes
28-
public static let httpStatusCode = "http.status_code"
29-
/// - See: HTTPAttributes
30-
public static let httpStatusText = "http.status_text"
31-
/// - See: HTTPAttributes
32-
public static let httpFlavor = "http.flavor"
33-
/// - See: HTTPAttributes
34-
public static let httpUserAgent = "http.user_agent"
35-
/// - See: HTTPAttributes
36-
public static let httpRequestContentLength = "http.request_content_length"
37-
/// - See: HTTPAttributes
38-
public static let httpRequestContentLengthUncompressed = "http.request_content_length_uncompressed"
39-
/// - See: HTTPAttributes
40-
public static let httpResponseContentLength = "http.response_content_length"
41-
/// - See: HTTPAttributes
42-
public static let httpResponseContentLengthUncompressed = "http.response_content_length_uncompressed"
43-
/// - See: HTTPAttributes
44-
public static let httpServerName = "http.server_name"
45-
/// - See: HTTPAttributes
46-
public static let httpServerRoute = "http.route"
47-
/// - See: HTTPAttributes
48-
public static let httpServerClientIP = "http.client_ip"
18+
public enum HTTP {
19+
/// - See: HTTPAttributes
20+
public static let method = "http.method"
21+
/// - See: HTTPAttributes
22+
public static let url = "http.url"
23+
/// - See: HTTPAttributes
24+
public static let target = "http.target"
25+
/// - See: HTTPAttributes
26+
public static let host = "http.host"
27+
/// - See: HTTPAttributes
28+
public static let scheme = "http.scheme"
29+
/// - See: HTTPAttributes
30+
public static let statusCode = "http.status_code"
31+
/// - See: HTTPAttributes
32+
public static let statusText = "http.status_text"
33+
/// - See: HTTPAttributes
34+
public static let flavor = "http.flavor"
35+
/// - See: HTTPAttributes
36+
public static let userAgent = "http.user_agent"
37+
/// - See: HTTPAttributes
38+
public static let requestContentLength = "http.request_content_length"
39+
/// - See: HTTPAttributes
40+
public static let requestContentLengthUncompressed = "http.request_content_length_uncompressed"
41+
/// - See: HTTPAttributes
42+
public static let responseContentLength = "http.response_content_length"
43+
/// - See: HTTPAttributes
44+
public static let responseContentLengthUncompressed = "http.response_content_length_uncompressed"
45+
/// - See: HTTPAttributes
46+
public static let serverName = "http.server_name"
47+
/// - See: HTTPAttributes
48+
public static let serverRoute = "http.route"
49+
/// - See: HTTPAttributes
50+
public static let serverClientIP = "http.client_ip"
51+
}
4952
}
5053

5154
#if swift(>=5.2)
@@ -76,68 +79,68 @@ public struct HTTPAttributes: SpanAttributeNamespace {
7679
public init() {}
7780

7881
/// HTTP request method. E.g. "GET".
79-
public var method: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpMethod) }
82+
public var method: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.method) }
8083

8184
/// Full HTTP request URL in the form scheme://host[:port]/path?query[#fragment].
8285
/// Usually the fragment is not transmitted over HTTP, but if it is known, it should be included nevertheless.
83-
public var url: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpURL) }
86+
public var url: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.url) }
8487

8588
/// The full request target as passed in a HTTP request line or equivalent, e.g. "/path/12314/?q=ddds#123".
86-
public var target: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpTarget) }
89+
public var target: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.target) }
8790

8891
/// The value of the HTTP host header. When the header is empty or not present, this attribute should be the same.
89-
public var host: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpHost) }
92+
public var host: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.host) }
9093

9194
/// The URI scheme identifying the used protocol: "http" or "https"
92-
public var scheme: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpScheme) }
95+
public var scheme: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.scheme) }
9396

9497
/// HTTP response status code. E.g. 200.
95-
public var statusCode: SpanAttributeKey<Int> { .init(name: SpanAttributeName.httpStatusCode) }
98+
public var statusCode: SpanAttributeKey<Int> { .init(name: SpanAttributeName.HTTP.statusCode) }
9699

97100
/// HTTP reason phrase. E.g. "OK".
98-
public var statusText: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpStatusText) }
101+
public var statusText: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.statusText) }
99102

100103
/// Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
101-
public var flavor: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpFlavor) }
104+
public var flavor: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.flavor) }
102105

103106
/// Value of the HTTP User-Agent header sent by the client.
104-
public var userAgent: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpUserAgent) }
107+
public var userAgent: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.userAgent) }
105108

106109
/// The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often,
107110
/// but not always, present as the Content-Length header. For requests using transport encoding, this should be the
108111
/// compressed size.
109112
public var requestContentLength: SpanAttributeKey<Int> {
110-
.init(name: SpanAttributeName.httpRequestContentLength)
113+
.init(name: SpanAttributeName.HTTP.requestContentLength)
111114
}
112115

113116
/// The size of the uncompressed request payload body after transport decoding. Not set if transport encoding not used.
114117
public var requestContentLengthUncompressed: SpanAttributeKey<Int> {
115-
.init(name: SpanAttributeName.httpRequestContentLengthUncompressed)
118+
.init(name: SpanAttributeName.HTTP.requestContentLengthUncompressed)
116119
}
117120

118121
/// The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and
119122
/// is often, but not always, present as the Content-Length header. For requests using transport encoding, this
120123
/// should be the compressed size.
121124
public var responseContentLength: SpanAttributeKey<Int> {
122-
.init(name: SpanAttributeName.httpResponseContentLength)
125+
.init(name: SpanAttributeName.HTTP.responseContentLength)
123126
}
124127

125128
/// The size of the uncompressed response payload body after transport decoding. Not set if transport encoding not used.
126129
public var responseContentLengthUncompressed: SpanAttributeKey<Int> {
127-
.init(name: SpanAttributeName.httpResponseContentLengthUncompressed)
130+
.init(name: SpanAttributeName.HTTP.responseContentLengthUncompressed)
128131
}
129132

130133
/// The primary server name of the matched virtual host. This should be obtained via configuration.
131134
/// If no such configuration can be obtained, this attribute MUST NOT be set (`net.hostName` should be used instead).
132-
public var serverName: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpServerName) }
135+
public var serverName: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.serverName) }
133136

134137
/// The matched route (path template). E.g. "/users/:userID?".
135-
public var serverRoute: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpServerRoute) }
138+
public var serverRoute: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.serverRoute) }
136139

137140
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
138141
/// Note that this is not necessarily the same as `net.peerIP`, which would identify the network-level peer,
139142
/// which may be a proxy.
140-
public var serverClientIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.httpServerClientIP) }
143+
public var serverClientIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.HTTP.serverClientIP) }
141144
}
142145
}
143146
#endif

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+NetSemantics.swift

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: NetAttributes
18-
public static let netTransport = "net.transport"
19-
/// - See: NetAttributes
20-
public static let netPeerIP = "net.peer.ip"
21-
/// - See: NetAttributes
22-
public static let netPeerPort = "net.peer.port"
23-
/// - See: NetAttributes
24-
public static let netPeerName = "net.peer.name"
25-
/// - See: NetAttributes
26-
public static let netHostIP = "net.host.ip"
27-
/// - See: NetAttributes
28-
public static let netHostPort = "net.host.port"
29-
/// - See: NetAttributes
30-
public static let netHostName = "net.host.name"
18+
public enum Net {
19+
/// - See: NetAttributes
20+
public static let transport = "net.transport"
21+
/// - See: NetAttributes
22+
public static let peerIP = "net.peer.ip"
23+
/// - See: NetAttributes
24+
public static let peerPort = "net.peer.port"
25+
/// - See: NetAttributes
26+
public static let peerName = "net.peer.name"
27+
/// - See: NetAttributes
28+
public static let hostIP = "net.host.ip"
29+
/// - See: NetAttributes
30+
public static let hostPort = "net.host.port"
31+
/// - See: NetAttributes
32+
public static let hostName = "net.host.name"
33+
}
3134
}
3235

3336
#if swift(>=5.2)
@@ -58,25 +61,25 @@ public struct NetAttributes: SpanAttributeNamespace {
5861
public init() {}
5962

6063
/// Transport protocol used.
61-
public var transport: SpanAttributeKey<String> { .init(name: SpanAttributeName.netTransport) }
64+
public var transport: SpanAttributeKey<String> { .init(name: SpanAttributeName.Net.transport) }
6265

6366
/// Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6).
64-
public var peerIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.netPeerIP) }
67+
public var peerIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.Net.peerIP) }
6568

6669
/// Remote port number as an integer. E.g., 80.
67-
public var peerPort: SpanAttributeKey<Int> { .init(name: SpanAttributeName.netPeerPort) }
70+
public var peerPort: SpanAttributeKey<Int> { .init(name: SpanAttributeName.Net.peerPort) }
6871

6972
/// Remote hostname or similar.
70-
public var peerName: SpanAttributeKey<String> { .init(name: SpanAttributeName.netPeerName) }
73+
public var peerName: SpanAttributeKey<String> { .init(name: SpanAttributeName.Net.peerName) }
7174

7275
/// Like `peerIP` but for the host IP. Useful in case of a multi-IP host.
73-
public var hostIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.netHostIP) }
76+
public var hostIP: SpanAttributeKey<String> { .init(name: SpanAttributeName.Net.hostIP) }
7477

7578
/// Like `peerPort` but for the host port.
76-
public var hostPort: SpanAttributeKey<Int> { .init(name: SpanAttributeName.netHostPort) }
79+
public var hostPort: SpanAttributeKey<Int> { .init(name: SpanAttributeName.Net.hostPort) }
7780

7881
/// Local hostname or similar.
79-
public var hostName: SpanAttributeKey<String> { .init(name: SpanAttributeName.netHostName) }
82+
public var hostName: SpanAttributeKey<String> { .init(name: SpanAttributeName.Net.hostName) }
8083
}
8184
}
8285
#endif

Sources/OpenTelemetryInstrumentationSupport/SpanAttribute+PeerSemantics.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import TracingInstrumentation
1515

1616
extension SpanAttributeName {
1717
/// - See: PeerAttributes
18-
public static let peerService = "peer.service"
18+
public enum Peer {
19+
/// - See: PeerAttributes
20+
public static let service = "peer.service"
21+
}
1922
}
2023

2124
#if swift(>=5.2)
@@ -46,7 +49,7 @@ public struct PeerAttributes: SpanAttributeNamespace {
4649
public init() {}
4750

4851
/// The service.name of the remote service. SHOULD be equal to the actual service.name resource attribute of the remote service if any.
49-
public var service: SpanAttributeKey<String> { .init(name: SpanAttributeName.peerService) }
52+
public var service: SpanAttributeKey<String> { .init(name: SpanAttributeName.Peer.service) }
5053
}
5154
}
5255
#endif

0 commit comments

Comments
 (0)