File tree 2 files changed +20
-4
lines changed
2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -149,8 +149,13 @@ public struct SpanEvent: Equatable {
149
149
150
150
/// The timestamp at which this event occurred.
151
151
///
152
- /// It should be expressed as the number of milliseconds since UNIX Epoch (January 1st 1970).
153
- public let millisecondsSinceEpoch : UInt64
152
+ /// It should be expressed as the number of nanoseconds since UNIX Epoch (January 1st 1970).
153
+ public let nanosecondsSinceEpoch : UInt64
154
+
155
+ /// Representation of the timestamp this event occured as the number of milliseconds since UNIX Epoch (January 1st 1970).
156
+ public var millisecondsSinceEpoch : UInt64 {
157
+ self . nanosecondsSinceEpoch / 1_000_000
158
+ }
154
159
155
160
/// Create a new `SpanEvent`.
156
161
/// - Parameters:
@@ -163,15 +168,15 @@ public struct SpanEvent: Equatable {
163
168
{
164
169
self . name = name
165
170
self . attributes = attributes
166
- self . millisecondsSinceEpoch = clock. now. millisecondsSinceEpoch
171
+ self . nanosecondsSinceEpoch = clock. now. nanosecondsSinceEpoch
167
172
}
168
173
169
174
public init ( name: String ,
170
175
attributes: SpanAttributes = [ : ] )
171
176
{
172
177
self . name = name
173
178
self . attributes = attributes
174
- self . millisecondsSinceEpoch = DefaultTracerClock . now. millisecondsSinceEpoch
179
+ self . nanosecondsSinceEpoch = DefaultTracerClock . now. nanosecondsSinceEpoch
175
180
}
176
181
}
177
182
Original file line number Diff line number Diff line change @@ -24,6 +24,17 @@ final class SpanTests: XCTestCase {
24
24
XCTAssertEqual ( event. name, " test " )
25
25
}
26
26
27
+ func testSpanEventUsesNanosecondsFromClock( ) {
28
+ let clock = MockClock ( )
29
+ clock. setTime ( 42_000_000 )
30
+
31
+ let event = SpanEvent ( name: " test " , clock: clock)
32
+
33
+ XCTAssertEqual ( event. name, " test " )
34
+ XCTAssertEqual ( event. nanosecondsSinceEpoch, 42_000_000 )
35
+ XCTAssertEqual ( event. millisecondsSinceEpoch, 42 )
36
+ }
37
+
27
38
func testSpanAttributeIsExpressibleByStringLiteral( ) {
28
39
let stringAttribute : SpanAttribute = " test "
29
40
guard case . string( let stringValue) = stringAttribute else {
You can’t perform that action at this time.
0 commit comments