Skip to content

Commit 83a37b4

Browse files
authored
end() should take an autoclosure instant, not direct instant (#122)
1 parent 30631dd commit 83a37b4

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

Sources/Tracing/NoOpTracer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public struct NoOpTracer: LegacyTracer {
8484
}
8585
}
8686

87-
public func end<Instant: TracerInstant>(at instant: Instant) {
87+
public func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
8888
// ignore
8989
}
9090
}

Sources/Tracing/SpanProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public protocol Span: _SwiftTracingSendableSpan {
100100
/// - instant: the time instant at which the span ended
101101
///
102102
/// - SeeAlso: `Span.end()` which automatically uses the "current" time.
103-
func end<Instant: TracerInstant>(at instant: Instant)
103+
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant)
104104
}
105105

106106
extension Span {

Tests/TracingTests/DynamicTracepointTracerTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ extension DynamicTracepointTestTracer {
322322
// nothing
323323
}
324324

325-
func end<Instant: TracerInstant>(at instant: Instant) {
326-
self.endTimestampNanosSinceEpoch = instant.nanosecondsSinceEpoch
325+
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
326+
self.endTimestampNanosSinceEpoch = instant().nanosecondsSinceEpoch
327327
self.onEnd(self)
328328
}
329329
}

Tests/TracingTests/TestTracer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ final class TestSpan: Span {
181181
self.recordedErrors.append((error, attributes))
182182
}
183183

184-
func end<Instant: TracerInstant>(at instant: Instant) {
185-
self.endTimestampNanosSinceEpoch = instant.nanosecondsSinceEpoch
184+
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
185+
self.endTimestampNanosSinceEpoch = instant().nanosecondsSinceEpoch
186186
self.onEnd(self)
187187
}
188188
}

Tests/TracingTests/TracedLockTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ private final class TracedLockPrintlnTracer: LegacyTracer {
153153

154154
func recordError<Instant: TracerInstant>(_ error: Error, attributes: SpanAttributes, at instant: @autoclosure () -> Instant) {}
155155

156-
func end<Instant: TracerInstant>(at instant: Instant) {
157-
let time = instant
156+
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
157+
let time = instant()
158158
self.endTimeMillis = time.millisecondsSinceEpoch
159159
print(" span [\(self.operationName): \(self.baggage[TaskIDKey.self] ?? "no-name")] @ \(time): end")
160160
}

Tests/TracingTests/TracerTests+swift57.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ final class SampleSwift57Span: Span {
122122
self.recordedErrors.append((error, attributes))
123123
}
124124

125-
func end<Instant: TracerInstant>(at instant: Instant) {
126-
self.endTimeNanoseconds = instant.nanosecondsSinceEpoch
125+
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
126+
self.endTimeNanoseconds = instant().nanosecondsSinceEpoch
127127
self.onEnd(self)
128128
}
129129
}

0 commit comments

Comments
 (0)