@@ -18,12 +18,14 @@ class AdapterTests: XCTestCase {
1818 static let spanId = " 0000000000def456 "
1919 static let parentSpanId = " 0000000000aef789 "
2020
21+ let microsecondsInSecond : Double = 1000000
22+
2123 func testProtoSpans( ) {
22- let duration = 900 // ms
23- let startMs = UInt64 ( Date ( ) . timeIntervalSince1970 * 1000 )
24- let endMs = startMs + UInt64( duration)
24+ let duration = 900 // microseconds
25+ let startMicroseconds = UInt64 ( Date ( ) . timeIntervalSince1970 * microsecondsInSecond )
26+ let endMicroseconds = startMicroseconds + UInt64( duration)
2527
26- let span = getSpanData ( startMs : startMs , endMs : endMs )
28+ let span = getSpanData ( startMicroseconds : startMicroseconds , endMicroseconds : endMicroseconds )
2729 let spans = [ span]
2830
2931 let jaegerSpans = Adapter . toJaeger ( spans: spans)
@@ -33,19 +35,19 @@ class AdapterTests: XCTestCase {
3335 }
3436
3537 func testProtoSpan( ) {
36- let duration = 900 // ms
37- let startMs = UInt64 ( Date ( ) . timeIntervalSince1970 * 1000 )
38- let endMs = startMs + UInt64( duration)
38+ let duration = 900 // microseconds
39+ let startMicroseconds = UInt64 ( Date ( ) . timeIntervalSince1970 * microsecondsInSecond )
40+ let endMicroseconds = startMicroseconds + UInt64( duration)
3941
40- let span = getSpanData ( startMs : startMs , endMs : endMs )
42+ let span = getSpanData ( startMicroseconds : startMicroseconds , endMicroseconds : endMicroseconds )
4143
4244 // test
4345 let jaegerSpan = Adapter . toJaeger ( span: span)
4446
4547 XCTAssertEqual ( span. traceId. hexString, String ( format: " %016llx " , jaegerSpan. traceIdHigh) + String( format: " %016llx " , jaegerSpan. traceIdLow) )
4648 XCTAssertEqual ( span. spanId. hexString, String ( format: " %016llx " , jaegerSpan. spanId) )
4749 XCTAssertEqual ( " GET /api/endpoint " , jaegerSpan. operationName)
48- XCTAssertEqual ( Int64 ( startMs ) , jaegerSpan. startTime)
50+ XCTAssertEqual ( Int64 ( startMicroseconds ) , jaegerSpan. startTime)
4951 XCTAssertEqual ( duration, Int ( jaegerSpan. duration) )
5052
5153 XCTAssertEqual ( jaegerSpan. tags? . count, 4 )
@@ -181,8 +183,8 @@ class AdapterTests: XCTestCase {
181183 }
182184
183185 func testStatusNotOk( ) {
184- let startMs = UInt64 ( Date ( ) . timeIntervalSince1970 * 1000 )
185- let endMs = startMs + 900
186+ let startMicroseconds = UInt64 ( Date ( ) . timeIntervalSince1970 * microsecondsInSecond )
187+ let endMicroseconds = startMicroseconds + 900
186188
187189 let span = SpanData ( traceId: TraceId ( fromHexString: AdapterTests . traceId) ,
188190 spanId: SpanId ( fromHexString: AdapterTests . spanId) ,
@@ -192,9 +194,9 @@ class AdapterTests: XCTestCase {
192194 instrumentationLibraryInfo: InstrumentationLibraryInfo ( ) ,
193195 name: " GET /api/endpoint " ,
194196 kind: . server,
195- startTime: Date ( timeIntervalSince1970: Double ( startMs ) / 1000 ) ,
197+ startTime: Date ( timeIntervalSince1970: Double ( startMicroseconds ) / microsecondsInSecond ) ,
196198 status: . error( description: " GenericError " ) ,
197- endTime: Date ( timeIntervalSince1970: Double ( endMs ) / 1000 ) ,
199+ endTime: Date ( timeIntervalSince1970: Double ( endMicroseconds ) / microsecondsInSecond ) ,
198200 hasRemoteParent: false )
199201
200202 XCTAssertNotNil ( Adapter . toJaeger ( span: span) )
@@ -203,15 +205,15 @@ class AdapterTests: XCTestCase {
203205 func testSpanError( ) {
204206 let attributes = [ " error.type " : AttributeValue . string ( self . name) ,
205207 " error.message " : AttributeValue . string ( " server error " ) ]
206- let startMs = UInt64 ( Date ( ) . timeIntervalSince1970 * 1000 )
207- let endMs = startMs + 900
208+ let startMicroseconds = UInt64 ( Date ( ) . timeIntervalSince1970 * microsecondsInSecond )
209+ let endMicroseconds = startMicroseconds + 900
208210
209211 var span = SpanData ( traceId: TraceId ( fromHexString: AdapterTests . traceId) ,
210212 spanId: SpanId ( fromHexString: AdapterTests . spanId) ,
211213 name: " GET /api/endpoint " ,
212214 kind: . server,
213- startTime: Date ( timeIntervalSince1970: Double ( startMs ) / 1000 ) ,
214- endTime: Date ( timeIntervalSince1970: Double ( endMs ) / 1000 ) )
215+ startTime: Date ( timeIntervalSince1970: Double ( startMicroseconds ) / microsecondsInSecond ) ,
216+ endTime: Date ( timeIntervalSince1970: Double ( endMicroseconds ) / microsecondsInSecond ) )
215217 span. settingHasEnded ( true )
216218 span. settingStatus ( . error( description: " GenericError " ) )
217219 span. settingAttributes ( attributes)
@@ -230,7 +232,7 @@ class AdapterTests: XCTestCase {
230232 return SpanData . Event ( name: " the log message " , timestamp: Date ( ) , attributes: attributes)
231233 }
232234
233- private func getSpanData( startMs : UInt64 , endMs : UInt64 ) -> SpanData {
235+ private func getSpanData( startMicroseconds : UInt64 , endMicroseconds : UInt64 ) -> SpanData {
234236 let valueB = AttributeValue . bool ( true )
235237 let attributes = [ " valueB " : valueB]
236238
@@ -245,12 +247,12 @@ class AdapterTests: XCTestCase {
245247 instrumentationLibraryInfo: InstrumentationLibraryInfo ( ) ,
246248 name: " GET /api/endpoint " ,
247249 kind: . server,
248- startTime: Date ( timeIntervalSince1970: Double ( startMs ) / 1000 ) ,
250+ startTime: Date ( timeIntervalSince1970: Double ( startMicroseconds ) / microsecondsInSecond ) ,
249251 attributes: attributes,
250252 events: [ getTimedEvent ( ) ] ,
251253 links: [ link] ,
252254 status: Status . ok,
253- endTime: Date ( timeIntervalSince1970: Double ( endMs ) / 1000 ) ,
255+ endTime: Date ( timeIntervalSince1970: Double ( endMicroseconds ) / microsecondsInSecond ) ,
254256 hasRemoteParent: false )
255257 }
256258
0 commit comments