Skip to content

end() should take an autoclosure instant, not direct instant #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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