Skip to content

Commit 2929500

Browse files
committed
Formatting
1 parent 5aa8dbb commit 2929500

File tree

4 files changed

+125
-96
lines changed

4 files changed

+125
-96
lines changed

Sources/GRPCInterceptors/Tracing/ClientOTelTracingInterceptor.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
public import GRPCCore
18-
internal import Tracing
1918
internal import Synchronization
19+
internal import Tracing
2020

2121
/// A client interceptor that injects tracing information into the request.
2222
///
@@ -96,7 +96,8 @@ public struct ClientOTelTracingInterceptor: ClientInterceptor {
9696
afterEachWrite: {
9797
var event = SpanEvent(name: "rpc.message")
9898
event.attributes.rpc.messageType = "SENT"
99-
event.attributes.rpc.messageID = messageSentCounter
99+
event.attributes.rpc.messageID =
100+
messageSentCounter
100101
.wrappingAdd(1, ordering: .sequentiallyConsistent)
101102
.oldValue
102103
span.addEvent(event)
@@ -122,7 +123,8 @@ public struct ClientOTelTracingInterceptor: ClientInterceptor {
122123
let onEachPartRecordingSequence = success.bodyParts.map { element in
123124
var event = SpanEvent(name: "rpc.message")
124125
event.attributes.rpc.messageType = "RECEIVED"
125-
event.attributes.rpc.messageID = messageReceivedCounter
126+
event.attributes.rpc.messageID =
127+
messageReceivedCounter
126128
.wrappingAdd(1, ordering: .sequentiallyConsistent)
127129
.oldValue
128130
span.addEvent(event)

Sources/GRPCInterceptors/Tracing/SpanAttributes+RPCAttributes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ package struct RPCAttributes: SpanAttributeNamespace {
3434
var messageType: Key<String> { "rpc.message.type" }
3535
var grpcStatusCode: Key<Int> { "rpc.grpc.status_code" }
3636

37-
var serverAddress: Key<String>{ "server.address" }
37+
var serverAddress: Key<String> { "server.address" }
3838
var serverPort: Key<Int> { "server.port" }
3939

4040
var clientAddress: Key<String> { "client.address" }
@@ -47,9 +47,9 @@ package struct RPCAttributes: SpanAttributeNamespace {
4747
}
4848
}
4949

50-
package extension SpanAttributes {
50+
extension SpanAttributes {
5151
/// Semantic conventions for RPC spans.
52-
var rpc: RPCAttributes {
52+
package var rpc: RPCAttributes {
5353
get {
5454
.init(attributes: self)
5555
}

Tests/GRPCInterceptorsTests/TracingInterceptorTests.swift

Lines changed: 115 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,31 @@ final class TracingInterceptorTests: XCTestCase {
7373
try await AssertStreamContentsEqual([["response"]], response.messages)
7474

7575
AssertTestSpanComponents(forMethod: methodDescriptor) { events in
76-
XCTAssertEqual(events.map({ $0.name }), [
77-
"Request started",
78-
"Request ended",
79-
"Received response start",
80-
"Received response end"
81-
])
76+
XCTAssertEqual(
77+
events.map({ $0.name }),
78+
[
79+
"Request started",
80+
"Request ended",
81+
"Received response start",
82+
"Received response end",
83+
]
84+
)
8285
} assertAttributes: { attributes in
83-
XCTAssertEqual(attributes, [
84-
"rpc.system": .string("grpc"),
85-
"rpc.method": .string(methodDescriptor.method),
86-
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
87-
"rpc.grpc.status_code": .int(0),
88-
"server.address": .string("someserver.com"),
89-
"server.port": .int(567),
90-
"network.peer.address": .string("10.1.2.80"),
91-
"network.peer.port": .int(567),
92-
"network.transport": .string("tcp"),
93-
"network.type": .string("ipv4")
94-
])
86+
XCTAssertEqual(
87+
attributes,
88+
[
89+
"rpc.system": .string("grpc"),
90+
"rpc.method": .string(methodDescriptor.method),
91+
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
92+
"rpc.grpc.status_code": .int(0),
93+
"server.address": .string("someserver.com"),
94+
"server.port": .int(567),
95+
"network.peer.address": .string("10.1.2.80"),
96+
"network.peer.port": .int(567),
97+
"network.transport": .string("tcp"),
98+
"network.type": .string("ipv4"),
99+
]
100+
)
95101
} assertStatus: { status in
96102
XCTAssertNil(status)
97103
} assertErrors: { errors in
@@ -152,23 +158,29 @@ final class TracingInterceptorTests: XCTestCase {
152158
try await AssertStreamContentsEqual([["response"]], response.messages)
153159

154160
AssertTestSpanComponents(forMethod: methodDescriptor) { events in
155-
XCTAssertEqual(events.map({ $0.name }), [
156-
"Request started",
157-
"Request ended",
158-
"Received response start",
159-
"Received response end"
160-
])
161+
XCTAssertEqual(
162+
events.map({ $0.name }),
163+
[
164+
"Request started",
165+
"Request ended",
166+
"Received response start",
167+
"Received response end",
168+
]
169+
)
161170
} assertAttributes: { attributes in
162-
XCTAssertEqual(attributes, [
163-
"rpc.system": .string("grpc"),
164-
"rpc.method": .string(methodDescriptor.method),
165-
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
166-
"rpc.grpc.status_code": .int(0),
167-
"server.address": .string("someserver.com"),
168-
"network.peer.address": .string("some-path"),
169-
"network.transport": .string("tcp"),
170-
"network.type": .string("unix")
171-
])
171+
XCTAssertEqual(
172+
attributes,
173+
[
174+
"rpc.system": .string("grpc"),
175+
"rpc.method": .string(methodDescriptor.method),
176+
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
177+
"rpc.grpc.status_code": .int(0),
178+
"server.address": .string("someserver.com"),
179+
"network.peer.address": .string("some-path"),
180+
"network.transport": .string("tcp"),
181+
"network.type": .string("unix"),
182+
]
183+
)
172184
} assertStatus: { status in
173185
XCTAssertNil(status)
174186
} assertErrors: { errors in
@@ -226,33 +238,39 @@ final class TracingInterceptorTests: XCTestCase {
226238
try await AssertStreamContentsEqual([["response"]], response.messages)
227239

228240
AssertTestSpanComponents(forMethod: methodDescriptor) { events in
229-
XCTAssertEqual(events, [
230-
TestSpanEvent("Request started", [:]),
231-
// Recorded when `request1` is sent
232-
TestSpanEvent("rpc.message", ["rpc.message.type": "SENT", "rpc.message.id": 1]),
233-
// Recorded when `request2` is sent
234-
TestSpanEvent("rpc.message", ["rpc.message.type": "SENT", "rpc.message.id": 2]),
235-
// Recorded after all request parts have been sent
236-
TestSpanEvent("Request ended", [:]),
237-
// Recorded when receiving response part
238-
TestSpanEvent("Received response start", [:]),
239-
TestSpanEvent("rpc.message", ["rpc.message.type": "RECEIVED", "rpc.message.id": 1]),
240-
// Recorded at end of response
241-
TestSpanEvent("Received response end", [:]),
242-
])
241+
XCTAssertEqual(
242+
events,
243+
[
244+
TestSpanEvent("Request started", [:]),
245+
// Recorded when `request1` is sent
246+
TestSpanEvent("rpc.message", ["rpc.message.type": "SENT", "rpc.message.id": 1]),
247+
// Recorded when `request2` is sent
248+
TestSpanEvent("rpc.message", ["rpc.message.type": "SENT", "rpc.message.id": 2]),
249+
// Recorded after all request parts have been sent
250+
TestSpanEvent("Request ended", [:]),
251+
// Recorded when receiving response part
252+
TestSpanEvent("Received response start", [:]),
253+
TestSpanEvent("rpc.message", ["rpc.message.type": "RECEIVED", "rpc.message.id": 1]),
254+
// Recorded at end of response
255+
TestSpanEvent("Received response end", [:]),
256+
]
257+
)
243258
} assertAttributes: { attributes in
244-
XCTAssertEqual(attributes, [
245-
"rpc.system": .string("grpc"),
246-
"rpc.method": .string(methodDescriptor.method),
247-
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
248-
"rpc.grpc.status_code": .int(0),
249-
"server.address": .string("someserver.com"),
250-
"server.port": .int(567),
251-
"network.peer.address": .string("10.1.2.80"),
252-
"network.peer.port": .int(567),
253-
"network.transport": .string("tcp"),
254-
"network.type": .string("ipv4")
255-
])
259+
XCTAssertEqual(
260+
attributes,
261+
[
262+
"rpc.system": .string("grpc"),
263+
"rpc.method": .string(methodDescriptor.method),
264+
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
265+
"rpc.grpc.status_code": .int(0),
266+
"server.address": .string("someserver.com"),
267+
"server.port": .int(567),
268+
"network.peer.address": .string("10.1.2.80"),
269+
"network.peer.port": .int(567),
270+
"network.transport": .string("tcp"),
271+
"network.type": .string("ipv4"),
272+
]
273+
)
256274
} assertStatus: { status in
257275
XCTAssertNil(status)
258276
} assertErrors: { errors in
@@ -312,17 +330,20 @@ final class TracingInterceptorTests: XCTestCase {
312330
XCTAssertEqual(events.map({ $0.name }), ["Request started"])
313331
} assertAttributes: { attributes in
314332
// The attributes should not contain a grpc status code, as the request was never even sent.
315-
XCTAssertEqual(attributes, [
316-
"rpc.system": .string("grpc"),
317-
"rpc.method": .string(methodDescriptor.method),
318-
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
319-
"server.address": .string("someserver.com"),
320-
"server.port": .int(567),
321-
"network.peer.address": .string("10.1.2.80"),
322-
"network.peer.port": .int(567),
323-
"network.transport": .string("tcp"),
324-
"network.type": .string("ipv4")
325-
])
333+
XCTAssertEqual(
334+
attributes,
335+
[
336+
"rpc.system": .string("grpc"),
337+
"rpc.method": .string(methodDescriptor.method),
338+
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
339+
"server.address": .string("someserver.com"),
340+
"server.port": .int(567),
341+
"network.peer.address": .string("10.1.2.80"),
342+
"network.peer.port": .int(567),
343+
"network.transport": .string("tcp"),
344+
"network.type": .string("ipv4"),
345+
]
346+
)
326347
} assertStatus: { status in
327348
XCTAssertNil(status)
328349
} assertErrors: { errors in
@@ -378,24 +399,30 @@ final class TracingInterceptorTests: XCTestCase {
378399
}
379400

380401
AssertTestSpanComponents(forMethod: methodDescriptor) { events in
381-
XCTAssertEqual(events.map({ $0.name }), [
382-
"Request started",
383-
"Request ended",
384-
"Received error response"
385-
])
402+
XCTAssertEqual(
403+
events.map({ $0.name }),
404+
[
405+
"Request started",
406+
"Request ended",
407+
"Received error response",
408+
]
409+
)
386410
} assertAttributes: { attributes in
387-
XCTAssertEqual(attributes, [
388-
"rpc.system": .string("grpc"),
389-
"rpc.method": .string(methodDescriptor.method),
390-
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
391-
"rpc.grpc.status_code": .int(14), // this is unavailable's raw code
392-
"server.address": .string("someserver.com"),
393-
"server.port": .int(567),
394-
"network.peer.address": .string("10.1.2.80"),
395-
"network.peer.port": .int(567),
396-
"network.transport": .string("tcp"),
397-
"network.type": .string("ipv4")
398-
])
411+
XCTAssertEqual(
412+
attributes,
413+
[
414+
"rpc.system": .string("grpc"),
415+
"rpc.method": .string(methodDescriptor.method),
416+
"rpc.service": .string(methodDescriptor.service.fullyQualifiedService),
417+
"rpc.grpc.status_code": .int(14), // this is unavailable's raw code
418+
"server.address": .string("someserver.com"),
419+
"server.port": .int(567),
420+
"network.peer.address": .string("10.1.2.80"),
421+
"network.peer.port": .int(567),
422+
"network.transport": .string("tcp"),
423+
"network.type": .string("ipv4"),
424+
]
425+
)
399426
} assertStatus: { status in
400427
XCTAssertEqual(status, .some(.init(code: .error)))
401428
} assertErrors: { errors in

Tests/GRPCInterceptorsTests/TracingTestsUtilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ struct TestSpanEvent: Equatable, CustomDebugStringConvertible {
217217
}
218218

219219
return """
220-
(name: \(self.name), attributes: [\(attributesDescription)])
221-
"""
220+
(name: \(self.name), attributes: [\(attributesDescription)])
221+
"""
222222
}
223223

224224
init(_ name: String, _ attributes: SpanAttributes) {

0 commit comments

Comments
 (0)