Skip to content

Commit 61a1e3a

Browse files
committed
remove Timestamp type, use DispatchWallTime
1 parent 14f3547 commit 61a1e3a

File tree

12 files changed

+48
-168
lines changed

12 files changed

+48
-168
lines changed

Sources/Instrumentation/NoOpInstrument.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import CoreBaggage
1515

1616
/// A "no op" implementation of an `Instrument`.
1717
public struct NoOpInstrument: Instrument {
18-
public init() {
19-
}
18+
public init() {}
2019

2120
public func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
2221
where Inject: Injector, Carrier == Inject.Carrier {

Sources/Tracing/NoOpTracer.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
@_exported import Baggage
15+
import Dispatch
1516
@_exported import Instrumentation
1617

1718
/// No operation Tracer, used when no tracing is required.
@@ -20,7 +21,7 @@ public struct NoOpTracer: Tracer {
2021
_ operationName: String,
2122
baggage: Baggage,
2223
ofKind kind: SpanKind,
23-
at timestamp: Timestamp
24+
at time: DispatchWallTime
2425
) -> Span {
2526
return NoOpSpan(baggage: baggage)
2627
}
@@ -62,7 +63,7 @@ public struct NoOpTracer: Tracer {
6263
}
6364
}
6465

65-
public func end(at timestamp: Timestamp) {
66+
public func end(at time: DispatchWallTime) {
6667
// ignore
6768
}
6869
}

Sources/Tracing/Span.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
@_exported import Baggage
15+
import Dispatch
1516

1617
/// A `Span` type that follows the OpenTracing/OpenTelemetry spec. The span itself should not be
1718
/// initializable via its public interface. `Span` creation should instead go through `tracer.startSpan`
@@ -46,7 +47,7 @@ public protocol Span: AnyObject {
4647
/// - Parameter link: The `SpanLink` to add to this `Span`.
4748
func addLink(_ link: SpanLink)
4849

49-
/// End this `Span` at the given timestamp.
50+
/// End this `Span` at the given time.
5051
///
5152
/// ### Rules about ending Spans
5253
/// A Span must be ended only ONCE. Ending a Span multiple times or never at all is considered a programming error.
@@ -56,14 +57,14 @@ public protocol Span: AnyObject {
5657
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
5758
/// programming mistake to rely on this behavior.
5859
///
59-
/// - Parameter timestamp: The `Timestamp` at which the span ended.
60+
/// - Parameter time: The `DispatchWallTime` at which the span ended.
6061
///
61-
/// - SeeAlso: `Span.end()` which automatically uses the "current" time as timestamp.
62-
func end(at timestamp: Timestamp)
62+
/// - SeeAlso: `Span.end()` which automatically uses the "current" time.
63+
func end(at time: DispatchWallTime)
6364
}
6465

6566
extension Span {
66-
/// End this `Span` at the current timestamp.
67+
/// End this `Span` at the current time.
6768
///
6869
/// ### Rules about ending Spans
6970
/// A Span must be ended only ONCE. Ending a Span multiple times or never at all is considered a programming error.
@@ -73,9 +74,9 @@ extension Span {
7374
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
7475
/// programming mistake to rely on this behavior.
7576
///
76-
/// - Parameter timestamp: The `Timestamp` at which the span ended.
77+
/// - Parameter time: The `DispatchWallTime` at which the span ended.
7778
///
78-
/// - SeeAlso: `Span.end(at:)` which allows passing in a specific timestamp, e.g. if the operation was ended and recorded somewhere and we need to post-factum record it.
79+
/// - SeeAlso: `Span.end(at:)` which allows passing in a specific time, e.g. if the operation was ended and recorded somewhere and we need to post-factum record it.
7980
/// Generally though prefer using the `end()` version of this API in user code and structure your system such that it can be called in the right place and time.
8081
public func end() {
8182
self.end(at: .now())
@@ -100,18 +101,18 @@ public struct SpanEvent: Equatable {
100101
/// One or more `SpanAttribute`s with the same restrictions as defined for `Span` attributes.
101102
public var attributes: SpanAttributes
102103

103-
/// The `Timestamp` at which this event occurred.
104-
public let timestamp: Timestamp
104+
/// The `DispatchWallTime` at which this event occurred.
105+
public let time: DispatchWallTime
105106

106107
/// Create a new `SpanEvent`.
107108
/// - Parameters:
108109
/// - name: The human-readable name of this event.
109110
/// - attributes: attributes describing this event. Defaults to no attributes.
110-
/// - timestamp: The `Timestamp` at which this event occurred. Defaults to `.now()`.
111-
public init(name: String, attributes: SpanAttributes = [:], at timestamp: Timestamp = .now()) {
111+
/// - time: The `DispatchWallTime` at which this event occurred. Defaults to `.now()`.
112+
public init(name: String, attributes: SpanAttributes = [:], at time: DispatchWallTime = .now()) {
112113
self.name = name
113114
self.attributes = attributes
114-
self.timestamp = timestamp
115+
self.time = time
115116
}
116117
}
117118

Sources/Tracing/Timestamp.swift

Lines changed: 0 additions & 66 deletions
This file was deleted.

Sources/Tracing/Tracer.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
@_exported import Baggage
15+
import Dispatch
1516
@_exported import Instrumentation
1617

1718
/// An `Instrument` with added functionality for distributed tracing. Is uses the span-based tracing model and is
1819
/// based on the OpenTracing/OpenTelemetry spec.
1920
public protocol Tracer: Instrument {
20-
/// Start a new `Span` with the given `Baggage` at a given timestamp.
21+
/// Start a new `Span` with the given `Baggage` at a given time.
2122
///
2223
/// - Parameters:
2324
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
2425
/// - baggage: The `Baggage` providing information on where to start the new `Span`.
2526
/// - kind: The `SpanKind` of the new `Span`.
26-
/// - timestamp: The `DispatchTime` at which to start the new `Span`.
27+
/// - time: The `DispatchTime` at which to start the new `Span`.
2728
func startSpan(
2829
_ operationName: String,
2930
baggage: Baggage,
3031
ofKind kind: SpanKind,
31-
at timestamp: Timestamp
32+
at time: DispatchWallTime
3233
) -> Span
3334

3435
/// Export all ended spans to the configured backend that have not yet been exported.

Tests/LinuxMain.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class LinuxMainRunnerImpl: LinuxMainRunner {
3838
testCase(InstrumentationSystemTests.allTests),
3939
testCase(SpanAttributeSemanticsTests.allTests),
4040
testCase(SpanTests.allTests),
41-
testCase(TimestampTests.allTests),
4241
testCase(TracedLockTests.allTests),
4342
testCase(TracerTests.allTests),
4443
testCase(TracingInstrumentationSystemTests.allTests),

Tests/TracingTests/SpanTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ final class SpanTests: XCTestCase {
143143

144144
let parent = TestSpan(
145145
operationName: "client",
146-
startTimestamp: .now(),
146+
startTime: .now(),
147147
baggage: parentBaggage,
148148
kind: .client,
149149
onEnd: { _ in }
150150
)
151151
let childBaggage = Baggage.topLevel
152152
let child = TestSpan(
153153
operationName: "server",
154-
startTimestamp: .now(),
154+
startTime: .now(),
155155
baggage: childBaggage,
156156
kind: .server,
157157
onEnd: { _ in }

Tests/TracingTests/TestTracer.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
import Baggage
15+
import Dispatch
1516
import Foundation
1617
import Instrumentation
1718
import Tracing
@@ -23,11 +24,11 @@ final class TestTracer: Tracer {
2324
_ operationName: String,
2425
baggage: Baggage,
2526
ofKind kind: SpanKind,
26-
at timestamp: Timestamp
27+
at time: DispatchWallTime
2728
) -> Span {
2829
let span = TestSpan(
2930
operationName: operationName,
30-
startTimestamp: timestamp,
31+
startTime: time,
3132
baggage: baggage,
3233
kind: kind
3334
) { _ in }
@@ -77,8 +78,8 @@ final class TestSpan: Span {
7778

7879
private var status: SpanStatus?
7980

80-
private let startTimestamp: Timestamp
81-
private(set) var endTimestamp: Timestamp?
81+
private let startTime: DispatchWallTime
82+
private(set) var endTime: DispatchWallTime?
8283

8384
let baggage: Baggage
8485

@@ -102,13 +103,13 @@ final class TestSpan: Span {
102103

103104
init(
104105
operationName: String,
105-
startTimestamp: Timestamp,
106+
startTime: DispatchWallTime,
106107
baggage: Baggage,
107108
kind: SpanKind,
108109
onEnd: @escaping (Span) -> Void
109110
) {
110111
self.operationName = operationName
111-
self.startTimestamp = startTimestamp
112+
self.startTime = startTime
112113
self.baggage = baggage
113114
self.onEnd = onEnd
114115
self.kind = kind
@@ -129,8 +130,8 @@ final class TestSpan: Span {
129130

130131
func recordError(_ error: Error) {}
131132

132-
func end(at timestamp: Timestamp) {
133-
self.endTimestamp = timestamp
133+
func end(at time: DispatchWallTime) {
134+
self.endTime = time
134135
self.onEnd(self)
135136
}
136137
}

Tests/TracingTests/TimestampTests+XCTest.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

Tests/TracingTests/TimestampTests.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)