Skip to content

Commit

Permalink
Remove LegacyTracer (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Jan 24, 2024
1 parent 7f7dbef commit c795631
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Sources/Hummingbird/Server/ServiceContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -143,7 +143,7 @@ extension HBRequest {
ofKind kind: SpanKind = .internal,
_ operation: (HBRequest, Span) -> EventLoopFuture<Return>
) -> EventLoopFuture<Return> {
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
Expand Down
30 changes: 3 additions & 27 deletions Tests/HummingbirdTests/TestTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ 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<Instant: TracerInstant>(
func startSpan<Instant: TracerInstant>(
_ operationName: String,
context: @autoclosure () -> ServiceContext,
ofKind kind: SpanKind,
at instant: @autoclosure () -> Instant,
function: String,
file fileID: String,
line: UInt
) -> any Span {
) -> TestSpan {
let span = TestSpan(
operationName: operationName,
at: instant(),
Expand Down Expand Up @@ -77,30 +77,6 @@ final class TestTracer: LegacyTracer {
}
}

#if swift(>=5.7.0)
extension TestTracer: Tracer {
func startSpan<Instant: TracerInstant>(
_ 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
Expand Down
6 changes: 3 additions & 3 deletions Tests/HummingbirdTests/TracingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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)
}
}
Expand Down

0 comments on commit c795631

Please sign in to comment.