Skip to content

Commit 3a731ed

Browse files
author
Ignacio Bonafonte
authored
Merge pull request #194 from nachoBonafonte/Fix-jaeger-exporter
2 parents 555d8c3 + 9a911d9 commit 3a731ed

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

Sources/Exporters/Jaeger/Adapter.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ final class Adapter {
4141
let spanHex = span.spanId.hexString
4242
let spanId = Int64(spanHex, radix: 16) ?? 0
4343
let operationName = span.name
44-
let startTime = Int64(span.startTime.timeIntervalSince1970.toMilliseconds)
45-
let duration = Int64(span.endTime.timeIntervalSince(span.startTime).toMilliseconds)
44+
let startTime = Int64(span.startTime.timeIntervalSince1970.toMicroseconds)
45+
let duration = Int64(span.endTime.timeIntervalSince(span.startTime).toMicroseconds)
4646

4747
var parentSpanId: Int64 = 0
4848

@@ -66,15 +66,13 @@ final class Adapter {
6666
tags.append(Tag(key: Adapter.keySpanKind, vType: .string, vStr: span.kind.rawValue.uppercased(), vDouble: nil, vBool: nil, vLong: nil, vBinary: nil))
6767
if case let Status.error(description) = span.status {
6868
tags.append(Tag(key: Adapter.keySpanStatusMessage, vType: .string, vStr: description, vDouble: nil, vBool: nil, vLong: nil, vBinary: nil))
69+
tags.append(Tag(key: keyError, vType: .bool, vStr: nil, vDouble: nil, vBool: true, vLong: nil, vBinary: nil))
70+
6971
} else {
7072
tags.append(Tag(key: Adapter.keySpanStatusMessage, vType: .string, vStr: "", vDouble: nil, vBool: nil, vLong: nil, vBinary: nil))
7173
}
7274
tags.append(Tag(key: Adapter.keySpanStatusCode, vType: .long, vStr: nil, vDouble: nil, vBool: nil, vLong: Int64(span.status.code), vBinary: nil))
7375

74-
if span.status != .ok {
75-
tags.append(Tag(key: keyError, vType: .bool, vStr: nil, vDouble: nil, vBool: true, vLong: nil, vBinary: nil))
76-
}
77-
7876
return Span(traceIdLow: traceIdLow, traceIdHigh: traceIdHigh, spanId: spanId, parentSpanId: parentSpanId, operationName: operationName, references: references, flags: 0, startTime: startTime, duration: duration, tags: tags, logs: logs)
7977
}
8078

@@ -135,7 +133,7 @@ final class Adapter {
135133
}
136134

137135
static func toJaegerLog(event: SpanData.Event) -> Log {
138-
let timestamp = Int64(event.timestamp.timeIntervalSince1970.toMilliseconds)
136+
let timestamp = Int64(event.timestamp.timeIntervalSince1970.toMicroseconds)
139137

140138
var tags = TList<Tag>()
141139
tags.append(Tag(key: Adapter.keyLogMessage, vType: .string, vStr: event.name, vDouble: nil, vBool: nil, vLong: nil, vBinary: nil))

Tests/ExportersTests/DatadogExporter/Upload/HTTPClientTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HTTPClientTests: XCTestCase {
3636
case .success:
3737
break
3838
case .failure(let error):
39-
XCTAssertEqual((error as? ErrorMock)?.description, "no internet connection")
39+
XCTAssertNotNil(error)
4040
expectation.fulfill()
4141
}
4242
}

Tests/ExportersTests/Jaeger/AdapterTests.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)