Skip to content

Commit

Permalink
end() should take an autoclosure instant, not direct instant (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktoso authored Apr 13, 2023
1 parent 30631dd commit 83a37b4
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/Tracing/NoOpTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct NoOpTracer: LegacyTracer {
}
}

public func end<Instant: TracerInstant>(at instant: Instant) {
public func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
// ignore
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tracing/SpanProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public protocol Span: _SwiftTracingSendableSpan {
/// - instant: the time instant at which the span ended
///
/// - SeeAlso: `Span.end()` which automatically uses the "current" time.
func end<Instant: TracerInstant>(at instant: Instant)
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant)
}

extension Span {
Expand Down
4 changes: 2 additions & 2 deletions Tests/TracingTests/DynamicTracepointTracerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ extension DynamicTracepointTestTracer {
// nothing
}

func end<Instant: TracerInstant>(at instant: Instant) {
self.endTimestampNanosSinceEpoch = instant.nanosecondsSinceEpoch
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
self.endTimestampNanosSinceEpoch = instant().nanosecondsSinceEpoch
self.onEnd(self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TracingTests/TestTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ final class TestSpan: Span {
self.recordedErrors.append((error, attributes))
}

func end<Instant: TracerInstant>(at instant: Instant) {
self.endTimestampNanosSinceEpoch = instant.nanosecondsSinceEpoch
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
self.endTimestampNanosSinceEpoch = instant().nanosecondsSinceEpoch
self.onEnd(self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TracingTests/TracedLockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ private final class TracedLockPrintlnTracer: LegacyTracer {

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

func end<Instant: TracerInstant>(at instant: Instant) {
let time = instant
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
let time = instant()
self.endTimeMillis = time.millisecondsSinceEpoch
print(" span [\(self.operationName): \(self.baggage[TaskIDKey.self] ?? "no-name")] @ \(time): end")
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/TracingTests/TracerTests+swift57.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ final class SampleSwift57Span: Span {
self.recordedErrors.append((error, attributes))
}

func end<Instant: TracerInstant>(at instant: Instant) {
self.endTimeNanoseconds = instant.nanosecondsSinceEpoch
func end<Instant: TracerInstant>(at instant: @autoclosure () -> Instant) {
self.endTimeNanoseconds = instant().nanosecondsSinceEpoch
self.onEnd(self)
}
}
Expand Down

0 comments on commit 83a37b4

Please sign in to comment.