Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Jan 23, 2025
1 parent b697ad5 commit b7ce62f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public struct ServerOTelTracingInterceptor: ServerInterceptor {
request: StreamingServerRequest<Input>,
context: ServerContext,
next: @Sendable (StreamingServerRequest<Input>, ServerContext) async throws ->
StreamingServerResponse<Output>
StreamingServerResponse<Output>
) async throws -> StreamingServerResponse<Output> where Input: Sendable, Output: Sendable {
try await self.intercept(
tracer: InstrumentationSystem.tracer,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
46 changes: 26 additions & 20 deletions Tests/GRPCInterceptorsTests/OTelTracingInterceptorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import GRPCCore
import GRPCInterceptors
import Testing
import Tracing

import struct Foundation.UUID

@Suite("OTel Tracing Client Interceptor Tests")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -811,7 +817,7 @@ fileprivate func assertTestSpanComponents(
assertErrors(span.errors)
}

fileprivate func assertStreamContentsEqual<T: Equatable>(
private func assertStreamContentsEqual<T: Equatable>(
_ array: [T],
_ stream: any AsyncSequence<T, any Error>
) async throws {
Expand All @@ -822,7 +828,7 @@ fileprivate func assertStreamContentsEqual<T: Equatable>(
#expect(streamElements == array)
}

fileprivate func assertStreamContentsEqual<T: Equatable>(
private func assertStreamContentsEqual<T: Equatable>(
_ array: [T],
_ stream: any AsyncSequence<T, Never>
) async {
Expand Down

0 comments on commit b7ce62f

Please sign in to comment.