From b7ce62f920c8091f2999ca20fcb089fa0f6caf7b Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Thu, 23 Jan 2025 16:52:37 +0000 Subject: [PATCH] Formatting --- .../ServerOTelTracingInterceptor.swift | 8 ++-- .../OTelTracingInterceptorTests.swift | 46 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Sources/GRPCInterceptors/Tracing/ServerOTelTracingInterceptor.swift b/Sources/GRPCInterceptors/Tracing/ServerOTelTracingInterceptor.swift index 67a2f88..9fa271d 100644 --- a/Sources/GRPCInterceptors/Tracing/ServerOTelTracingInterceptor.swift +++ b/Sources/GRPCInterceptors/Tracing/ServerOTelTracingInterceptor.swift @@ -68,7 +68,7 @@ public struct ServerOTelTracingInterceptor: ServerInterceptor { request: StreamingServerRequest, context: ServerContext, next: @Sendable (StreamingServerRequest, ServerContext) async throws -> - StreamingServerResponse + StreamingServerResponse ) async throws -> StreamingServerResponse where Input: Sendable, Output: Sendable { try await self.intercept( tracer: InstrumentationSystem.tracer, @@ -116,7 +116,8 @@ public struct ServerOTelTracingInterceptor: ServerInterceptor { wrapping: request.messages.map { element in var event = SpanEvent(name: "rpc.message") event.attributes[GRPCTracingKeys.rpcMessageType] = "RECEIVED" - event.attributes[GRPCTracingKeys.rpcMessageID] = messageReceivedCounter + event.attributes[GRPCTracingKeys.rpcMessageID] = + messageReceivedCounter .wrappingAdd(1, ordering: .sequentiallyConsistent) .oldValue span.addEvent(event) @@ -139,7 +140,8 @@ public struct ServerOTelTracingInterceptor: ServerInterceptor { afterEachWrite: { var event = SpanEvent(name: "rpc.message") event.attributes[GRPCTracingKeys.rpcMessageType] = "SENT" - event.attributes[GRPCTracingKeys.rpcMessageID] = messageSentCounter + event.attributes[GRPCTracingKeys.rpcMessageID] = + messageSentCounter .wrappingAdd(1, ordering: .sequentiallyConsistent) .oldValue span.addEvent(event) diff --git a/Tests/GRPCInterceptorsTests/OTelTracingInterceptorTests.swift b/Tests/GRPCInterceptorsTests/OTelTracingInterceptorTests.swift index a8843c7..fcedac5 100644 --- a/Tests/GRPCInterceptorsTests/OTelTracingInterceptorTests.swift +++ b/Tests/GRPCInterceptorsTests/OTelTracingInterceptorTests.swift @@ -18,6 +18,7 @@ import GRPCCore import GRPCInterceptors import Testing import Tracing + import struct Foundation.UUID @Suite("OTel Tracing Client Interceptor Tests") @@ -605,8 +606,8 @@ struct OTelTracingServerInterceptorTests { await assertStreamContentsEqual(["response1", "response2"], responseStream) assertTestSpanComponents(forMethod: methodDescriptor, tracer: self.tracer) { events in - #expect(events == - [ + #expect( + events == [ // Recorded when request is received TestSpanEvent("rpc.message", ["rpc.message.type": "RECEIVED", "rpc.message.id": 1]), // Recorded when `response1` is sent @@ -708,20 +709,22 @@ struct OTelTracingServerInterceptorTests { assertTestSpanComponents(forMethod: methodDescriptor, tracer: self.tracer) { events in #expect(events.isEmpty) } assertAttributes: { attributes in - #expect(attributes == [ - "rpc.system": "grpc", - "rpc.method": .string(methodDescriptor.method), - "rpc.service": .string(methodDescriptor.service.fullyQualifiedService), - "rpc.grpc.status_code": 14, // this is unavailable's raw code - "server.address": "someserver.com", - "server.port": 123, - "network.peer.address": "10.1.2.90", - "network.peer.port": 123, - "network.transport": "tcp", - "network.type": "ipv4", - "client.address": "10.1.2.80", - "client.port": 567, - ]) + #expect( + attributes == [ + "rpc.system": "grpc", + "rpc.method": .string(methodDescriptor.method), + "rpc.service": .string(methodDescriptor.service.fullyQualifiedService), + "rpc.grpc.status_code": 14, // this is unavailable's raw code + "server.address": "someserver.com", + "server.port": 123, + "network.peer.address": "10.1.2.90", + "network.peer.port": 123, + "network.transport": "tcp", + "network.type": "ipv4", + "client.address": "10.1.2.80", + "client.port": 567, + ] + ) } assertStatus: { status in #expect(status == .some(.init(code: .error))) } assertErrors: { errors in @@ -792,11 +795,14 @@ struct OTelTracingServerInterceptorTests { // - MARK: Utilities -fileprivate func getTestSpanForMethod(tracer: TestTracer, methodDescriptor: MethodDescriptor) -> TestSpan { +private func getTestSpanForMethod( + tracer: TestTracer, + methodDescriptor: MethodDescriptor +) -> TestSpan { tracer.getSpan(ofOperation: methodDescriptor.fullyQualifiedMethod)! } -fileprivate func assertTestSpanComponents( +private func assertTestSpanComponents( forMethod method: MethodDescriptor, tracer: TestTracer, assertEvents: ([TestSpanEvent]) -> Void, @@ -811,7 +817,7 @@ fileprivate func assertTestSpanComponents( assertErrors(span.errors) } -fileprivate func assertStreamContentsEqual( +private func assertStreamContentsEqual( _ array: [T], _ stream: any AsyncSequence ) async throws { @@ -822,7 +828,7 @@ fileprivate func assertStreamContentsEqual( #expect(streamElements == array) } -fileprivate func assertStreamContentsEqual( +private func assertStreamContentsEqual( _ array: [T], _ stream: any AsyncSequence ) async {