Skip to content

Commit abc2ce7

Browse files
slashmoktoso
andauthored
Add Key alias in NestedSpanAttributesProtocol (#26)
Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
1 parent 01d8514 commit abc2ce7

File tree

8 files changed

+41
-37
lines changed

8 files changed

+41
-37
lines changed

Sources/Tracing/Span.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ extension NestedSpanAttributesProtocol {
169169
}
170170
}
171171

172+
extension NestedSpanAttributesProtocol {
173+
public typealias Key = SpanAttributeKey
174+
}
175+
172176
extension SpanAttributeNamespace {
173177
public subscript<T>(dynamicMember dynamicMember: KeyPath<NestedSpanAttributes, SpanAttributeKey<T>>) -> T?
174178
where T: SpanAttributeConvertible {

Sources/TracingOpenTelemetrySupport/SpanAttribute+EndUser.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public struct EndUserAttributes: SpanAttributeNamespace {
5353
public init() {}
5454

5555
/// Username or client_id extracted from the access token or Authorization header in the inbound request from outside the system.
56-
public var id: SpanAttribute.Key<String> { .init(name: SpanAttributeName.EndUser.id) }
56+
public var id: Key<String> { .init(name: SpanAttributeName.EndUser.id) }
5757

5858
/// Actual/assumed role the client is making the request under extracted from token or application security context.
59-
public var role: SpanAttribute.Key<String> { .init(name: SpanAttributeName.EndUser.role) }
59+
public var role: Key<String> { .init(name: SpanAttributeName.EndUser.role) }
6060

6161
/// Scopes or granted authorities the client currently possesses extracted from token or application security context.
6262
/// 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.
63-
public var scope: SpanAttribute.Key<String> { .init(name: SpanAttributeName.EndUser.scope) }
63+
public var scope: Key<String> { .init(name: SpanAttributeName.EndUser.scope) }
6464
}
6565
}
6666
#endif

Sources/TracingOpenTelemetrySupport/SpanAttribute+GRPCSemantics.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ public struct GRPCAttributes: SpanAttributeNamespace {
5555
public init() {}
5656

5757
/// The type of message, e.g. "SENT" or "RECEIVED".
58-
public var messageType: SpanAttribute.Key<String> { .init(name: SpanAttributeName.GRPC.messageType) }
58+
public var messageType: Key<String> { .init(name: SpanAttributeName.GRPC.messageType) }
5959

6060
/// The message id calculated as two different counters starting from 1, one for sent messages and one for received messages.
61-
public var messageID: SpanAttribute.Key<Int> { .init(name: SpanAttributeName.GRPC.messageID) }
61+
public var messageID: Key<Int> { .init(name: SpanAttributeName.GRPC.messageID) }
6262

6363
/// The compressed message size in bytes.
64-
public var messageCompressedSize: SpanAttribute.Key<Int> {
64+
public var messageCompressedSize: Key<Int> {
6565
.init(name: SpanAttributeName.GRPC.messageCompressedSize)
6666
}
6767

6868
/// The uncompressed message size in bytes.
69-
public var messageUncompressedSize: SpanAttribute.Key<Int> {
69+
public var messageUncompressedSize: Key<Int> {
7070
.init(name: SpanAttributeName.GRPC.messageUncompressedSize)
7171
}
7272
}

Sources/TracingOpenTelemetrySupport/SpanAttribute+HTTPSemantics.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,68 +79,68 @@ public struct HTTPAttributes: SpanAttributeNamespace {
7979
public init() {}
8080

8181
/// HTTP request method. E.g. "GET".
82-
public var method: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.method) }
82+
public var method: Key<String> { .init(name: SpanAttributeName.HTTP.method) }
8383

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

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

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

9494
/// The URI scheme identifying the used protocol: "http" or "https"
95-
public var scheme: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.scheme) }
95+
public var scheme: Key<String> { .init(name: SpanAttributeName.HTTP.scheme) }
9696

9797
/// HTTP response status code. E.g. 200.
98-
public var statusCode: SpanAttribute.Key<Int> { .init(name: SpanAttributeName.HTTP.statusCode) }
98+
public var statusCode: Key<Int> { .init(name: SpanAttributeName.HTTP.statusCode) }
9999

100100
/// HTTP reason phrase. E.g. "OK".
101-
public var statusText: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.statusText) }
101+
public var statusText: Key<String> { .init(name: SpanAttributeName.HTTP.statusText) }
102102

103103
/// Kind of HTTP protocol used: "1.0", "1.1", "2", "SPDY" or "QUIC".
104-
public var flavor: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.flavor) }
104+
public var flavor: Key<String> { .init(name: SpanAttributeName.HTTP.flavor) }
105105

106106
/// Value of the HTTP User-Agent header sent by the client.
107-
public var userAgent: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.userAgent) }
107+
public var userAgent: Key<String> { .init(name: SpanAttributeName.HTTP.userAgent) }
108108

109109
/// The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often,
110110
/// but not always, present as the Content-Length header. For requests using transport encoding, this should be the
111111
/// compressed size.
112-
public var requestContentLength: SpanAttribute.Key<Int> {
112+
public var requestContentLength: Key<Int> {
113113
.init(name: SpanAttributeName.HTTP.requestContentLength)
114114
}
115115

116116
/// The size of the uncompressed request payload body after transport decoding. Not set if transport encoding not used.
117-
public var requestContentLengthUncompressed: SpanAttribute.Key<Int> {
117+
public var requestContentLengthUncompressed: Key<Int> {
118118
.init(name: SpanAttributeName.HTTP.requestContentLengthUncompressed)
119119
}
120120

121121
/// The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and
122122
/// is often, but not always, present as the Content-Length header. For requests using transport encoding, this
123123
/// should be the compressed size.
124-
public var responseContentLength: SpanAttribute.Key<Int> {
124+
public var responseContentLength: Key<Int> {
125125
.init(name: SpanAttributeName.HTTP.responseContentLength)
126126
}
127127

128128
/// The size of the uncompressed response payload body after transport decoding. Not set if transport encoding not used.
129-
public var responseContentLengthUncompressed: SpanAttribute.Key<Int> {
129+
public var responseContentLengthUncompressed: Key<Int> {
130130
.init(name: SpanAttributeName.HTTP.responseContentLengthUncompressed)
131131
}
132132

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

137137
/// The matched route (path template). E.g. "/users/:userID?".
138-
public var serverRoute: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.serverRoute) }
138+
public var serverRoute: Key<String> { .init(name: SpanAttributeName.HTTP.serverRoute) }
139139

140140
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
141141
/// Note that this is not necessarily the same as `net.peerIP`, which would identify the network-level peer,
142142
/// which may be a proxy.
143-
public var serverClientIP: SpanAttribute.Key<String> { .init(name: SpanAttributeName.HTTP.serverClientIP) }
143+
public var serverClientIP: Key<String> { .init(name: SpanAttributeName.HTTP.serverClientIP) }
144144
}
145145
}
146146
#endif

Sources/TracingOpenTelemetrySupport/SpanAttribute+NetSemantics.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ public struct NetAttributes: SpanAttributeNamespace {
6161
public init() {}
6262

6363
/// Transport protocol used.
64-
public var transport: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Net.transport) }
64+
public var transport: Key<String> { .init(name: SpanAttributeName.Net.transport) }
6565

6666
/// Remote address of the peer (dotted decimal for IPv4 or RFC5952 for IPv6).
67-
public var peerIP: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Net.peerIP) }
67+
public var peerIP: Key<String> { .init(name: SpanAttributeName.Net.peerIP) }
6868

6969
/// Remote port number as an integer. E.g., 80.
70-
public var peerPort: SpanAttribute.Key<Int> { .init(name: SpanAttributeName.Net.peerPort) }
70+
public var peerPort: Key<Int> { .init(name: SpanAttributeName.Net.peerPort) }
7171

7272
/// Remote hostname or similar.
73-
public var peerName: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Net.peerName) }
73+
public var peerName: Key<String> { .init(name: SpanAttributeName.Net.peerName) }
7474

7575
/// Like `peerIP` but for the host IP. Useful in case of a multi-IP host.
76-
public var hostIP: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Net.hostIP) }
76+
public var hostIP: Key<String> { .init(name: SpanAttributeName.Net.hostIP) }
7777

7878
/// Like `peerPort` but for the host port.
79-
public var hostPort: SpanAttribute.Key<Int> { .init(name: SpanAttributeName.Net.hostPort) }
79+
public var hostPort: Key<Int> { .init(name: SpanAttributeName.Net.hostPort) }
8080

8181
/// Local hostname or similar.
82-
public var hostName: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Net.hostName) }
82+
public var hostName: Key<String> { .init(name: SpanAttributeName.Net.hostName) }
8383
}
8484
}
8585
#endif

Sources/TracingOpenTelemetrySupport/SpanAttribute+PeerSemantics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public struct PeerAttributes: SpanAttributeNamespace {
4949
public init() {}
5050

5151
/// The service.name of the remote service. SHOULD be equal to the actual service.name resource attribute of the remote service if any.
52-
public var service: SpanAttribute.Key<String> { .init(name: SpanAttributeName.Peer.service) }
52+
public var service: Key<String> { .init(name: SpanAttributeName.Peer.service) }
5353
}
5454
}
5555
#endif

Sources/TracingOpenTelemetrySupport/SpanAttribute+RPCSemantics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ public struct RPCAttributes: SpanAttributeNamespace {
5353
public init() {}
5454

5555
/// A string identifying the remoting system, e.g., "grpc", "java_rmi" or "wcf".
56-
public var system: SpanAttribute.Key<String> { .init(name: SpanAttributeName.RPC.system) }
56+
public var system: Key<String> { .init(name: SpanAttributeName.RPC.system) }
5757

5858
/// The full name of the service being called, including its package name, if applicable.
59-
public var service: SpanAttribute.Key<String> { .init(name: SpanAttributeName.RPC.service) }
59+
public var service: Key<String> { .init(name: SpanAttributeName.RPC.service) }
6060

6161
/// The name of the method being called, must be equal to the $method part in the span name.
62-
public var method: SpanAttribute.Key<String> { .init(name: SpanAttributeName.RPC.method) }
62+
public var method: Key<String> { .init(name: SpanAttributeName.RPC.method) }
6363
}
6464
}
6565
#endif

Tests/TracingTests/SpanTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ public struct HTTPAttributes: SpanAttributeNamespace {
229229
public struct NestedSpanAttributes: NestedSpanAttributesProtocol {
230230
public init() {}
231231

232-
public var statusCode: SpanAttribute.Key<Int> {
232+
public var statusCode: Key<Int> {
233233
"http.status_code"
234234
}
235235

236-
public var codesArray: SpanAttribute.Key<[Int]> {
236+
public var codesArray: Key<[Int]> {
237237
"http.codes_array"
238238
}
239239

240-
public var customType: SpanAttribute.Key<CustomAttributeValue> {
240+
public var customType: Key<CustomAttributeValue> {
241241
"http.custom_value"
242242
}
243243
}

0 commit comments

Comments
 (0)