diff --git a/Sources/Hummingbird/Server/ServiceContext.swift b/Sources/Hummingbird/Server/ServiceContext.swift index 3aae848f1..d6f6f57a1 100644 --- a/Sources/Hummingbird/Server/ServiceContext.swift +++ b/Sources/Hummingbird/Server/ServiceContext.swift @@ -91,7 +91,7 @@ extension HBRequest { ofKind kind: SpanKind = .internal, _ operation: (HBRequest, Span) throws -> Return ) rethrows -> Return { - let span = InstrumentationSystem.legacyTracer.startAnySpan(operationName, context: context, ofKind: kind) + let span = InstrumentationSystem.tracer.startAnySpan(operationName, context: context, ofKind: kind) defer { span.end() } return try self.withServiceContext(span.context) { request in do { @@ -143,7 +143,7 @@ extension HBRequest { ofKind kind: SpanKind = .internal, _ operation: (HBRequest, Span) -> EventLoopFuture ) -> EventLoopFuture { - let span = InstrumentationSystem.legacyTracer.startAnySpan(operationName, context: context, ofKind: kind) + let span = InstrumentationSystem.tracer.startAnySpan(operationName, context: context, ofKind: kind) return self.withServiceContext(span.context) { request in return operation(request, span) .flatMapErrorThrowing { error in diff --git a/Tests/HummingbirdTests/TestTracer.swift b/Tests/HummingbirdTests/TestTracer.swift index 2bbeb7172..cacd79d2c 100644 --- a/Tests/HummingbirdTests/TestTracer.swift +++ b/Tests/HummingbirdTests/TestTracer.swift @@ -32,11 +32,11 @@ import ServiceContextModule import Tracing /// Only intended to be used in single-threaded testing. -final class TestTracer: LegacyTracer { +final class TestTracer: Tracer { private(set) var spans = [TestSpan]() var onEndSpan: (TestSpan) -> Void = { _ in } - func startAnySpan( + func startSpan( _ operationName: String, context: @autoclosure () -> ServiceContext, ofKind kind: SpanKind, @@ -44,7 +44,7 @@ final class TestTracer: LegacyTracer { function: String, file fileID: String, line: UInt - ) -> any Span { + ) -> TestSpan { let span = TestSpan( operationName: operationName, at: instant(), @@ -77,30 +77,6 @@ final class TestTracer: LegacyTracer { } } -#if swift(>=5.7.0) -extension TestTracer: Tracer { - func startSpan( - _ operationName: String, - context: @autoclosure () -> ServiceContext, - ofKind kind: SpanKind, - at instant: @autoclosure () -> Instant, - function: String, - file fileID: String, - line: UInt - ) -> TestSpan { - let span = TestSpan( - operationName: operationName, - at: instant(), - context: context(), - kind: kind, - onEnd: self.onEndSpan - ) - self.spans.append(span) - return span - } -} -#endif - extension TestTracer { enum TraceIDKey: ServiceContextKey { typealias Value = String diff --git a/Tests/HummingbirdTests/TracingTests.swift b/Tests/HummingbirdTests/TracingTests.swift index 5255e04e1..0b34cca3e 100644 --- a/Tests/HummingbirdTests/TracingTests.swift +++ b/Tests/HummingbirdTests/TracingTests.swift @@ -289,7 +289,7 @@ final class TracingTests: XCTestCase { app.router.get("/") { request -> HTTPResponseStatus in var serviceContext = request.serviceContext serviceContext.testID = "test" - let span = InstrumentationSystem.legacyTracer.startAnySpan("testing", context: serviceContext, ofKind: .server) + let span = InstrumentationSystem.tracer.startAnySpan("testing", context: serviceContext, ofKind: .server) span.end() return .ok } @@ -406,7 +406,7 @@ extension TracingTests { app.middleware.add(HBTracingMiddleware()) app.router.get("/") { _ -> HTTPResponseStatus in try await Task.sleep(nanoseconds: 1000) - return InstrumentationSystem.legacyTracer.withAnySpan("testing", ofKind: .server) { _ in + return InstrumentationSystem.tracer.withSpan("testing", ofKind: .server) { _ in return .ok } } @@ -433,7 +433,7 @@ extension TracingTests { public func apply(to request: HBRequest, next: HBResponder) async throws -> HBResponse { var serviceContext = request.serviceContext serviceContext.testID = "testAsyncMiddleware" - return try await InstrumentationSystem.legacyTracer.withAnySpan("TestSpan", context: serviceContext, ofKind: .server) { _ in + return try await InstrumentationSystem.tracer.withSpan("TestSpan", context: serviceContext, ofKind: .server) { _ in try await next.respond(to: request) } }