Skip to content

Commit cd6c007

Browse files
authored
Merge pull request #114 from slashmo/fix/tracing-tests-naming
Rename OTelSpan & JaegerTracer for testing
2 parents 20988c7 + 6c92b18 commit cd6c007

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

Tests/TracingInstrumentationTests/SpanTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import XCTest
1818

1919
final class SpanTests: XCTestCase {
2020
func testAddingEventCreatesCopy() {
21-
// TODO: We should probably replace OTelSpan at some point with a NoOpSpan for testing things like this.
22-
let span = OTelSpan(
21+
let span = TestSpan(
2322
operationName: "test",
2423
startTimestamp: .now(),
2524
context: BaggageContext(),
@@ -160,15 +159,15 @@ final class SpanTests: XCTestCase {
160159
var parentContext = BaggageContext()
161160
parentContext[TestBaggageContextKey.self] = "test"
162161

163-
let parent = OTelSpan(
162+
let parent = TestSpan(
164163
operationName: "client",
165164
startTimestamp: .now(),
166165
context: parentContext,
167166
kind: .client,
168167
onEnd: { _ in }
169168
)
170169
let childContext = BaggageContext()
171-
var child = OTelSpan(
170+
var child = TestSpan(
172171
operationName: "server",
173172
startTimestamp: .now(),
174173
context: childContext,

Tests/TracingInstrumentationTests/TracingInstrumentTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import XCTest
1919

2020
final class TracingInstrumentTests: XCTestCase {
2121
func testPlayground() {
22-
let httpServer = FakeHTTPServer(instrument: JaegerTracer()) { context, _, client -> FakeHTTPResponse in
22+
let httpServer = FakeHTTPServer(instrument: TestTracer()) { context, _, client -> FakeHTTPResponse in
2323
context.logger.info("Make subsequent HTTP request")
2424
client.performRequest(context, request: FakeHTTPRequest(path: "/test", headers: []))
2525
return FakeHTTPResponse(status: 418)
@@ -29,38 +29,38 @@ final class TracingInstrumentTests: XCTestCase {
2929
}
3030

3131
func testItProvidesAccessToATracingInstrument() {
32-
let tracer = JaegerTracer()
32+
let tracer = TestTracer()
3333

34-
XCTAssertNil(InstrumentationSystem.tracingInstrument(of: JaegerTracer.self))
34+
XCTAssertNil(InstrumentationSystem.tracingInstrument(of: TestTracer.self))
3535

3636
InstrumentationSystem.bootstrapInternal(tracer)
3737
XCTAssertFalse(InstrumentationSystem.instrument is MultiplexInstrument)
38-
XCTAssert(InstrumentationSystem.instrument(of: JaegerTracer.self) === tracer)
38+
XCTAssert(InstrumentationSystem.instrument(of: TestTracer.self) === tracer)
3939
XCTAssertNil(InstrumentationSystem.instrument(of: NoOpInstrument.self))
4040

41-
XCTAssert(InstrumentationSystem.tracingInstrument(of: JaegerTracer.self) === tracer)
42-
XCTAssert(InstrumentationSystem.tracingInstrument is JaegerTracer)
41+
XCTAssert(InstrumentationSystem.tracingInstrument(of: TestTracer.self) === tracer)
42+
XCTAssert(InstrumentationSystem.tracingInstrument is TestTracer)
4343

4444
let multiplexInstrument = MultiplexInstrument([tracer])
4545
InstrumentationSystem.bootstrapInternal(multiplexInstrument)
4646
XCTAssert(InstrumentationSystem.instrument is MultiplexInstrument)
47-
XCTAssert(InstrumentationSystem.instrument(of: JaegerTracer.self) === tracer)
47+
XCTAssert(InstrumentationSystem.instrument(of: TestTracer.self) === tracer)
4848

49-
XCTAssert(InstrumentationSystem.tracingInstrument(of: JaegerTracer.self) === tracer)
50-
XCTAssert(InstrumentationSystem.tracingInstrument is JaegerTracer)
49+
XCTAssert(InstrumentationSystem.tracingInstrument(of: TestTracer.self) === tracer)
50+
XCTAssert(InstrumentationSystem.tracingInstrument is TestTracer)
5151
}
5252
}
5353

54-
// MARK: - JaegerTracer
54+
// MARK: - TestTracer
5555

56-
final class JaegerTracer: TracingInstrument {
56+
final class TestTracer: TracingInstrument {
5757
func startSpan(
5858
named operationName: String,
5959
context: BaggageContext,
6060
ofKind kind: SpanKind,
6161
at timestamp: Timestamp?
6262
) -> Span {
63-
let span = OTelSpan(
63+
let span = TestSpan(
6464
operationName: operationName,
6565
startTimestamp: timestamp ?? .now(),
6666
context: context,
@@ -100,7 +100,7 @@ final class JaegerTracer: TracingInstrument {
100100
}
101101
}
102102

103-
extension JaegerTracer {
103+
extension TestTracer {
104104
struct TraceParent {
105105
let traceID: String
106106
let parentID: String
@@ -111,9 +111,9 @@ extension JaegerTracer {
111111
}
112112
}
113113

114-
// MARK: - OTelSpan
114+
// MARK: - TestSpan
115115

116-
struct OTelSpan: Span {
116+
struct TestSpan: Span {
117117
let operationName: String
118118
let kind: SpanKind
119119

UseCases/Sources/InstrumentsAppTracing/OSSignpostTracing.swift

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

1414
import Baggage
15-
import Instrumentation
1615
import Foundation // string conversion for os_log seems to live here
16+
import Instrumentation
1717

1818
#if os(macOS) || os(tvOS) || os(iOS) || os(watchOS)
1919
import os.log
@@ -91,7 +91,7 @@ final class OSSignpostSpan: Span {
9191
public let startTimestamp: Timestamp
9292
public var endTimestamp: Timestamp?
9393

94-
public var status: SpanStatus? = nil
94+
public var status: SpanStatus?
9595
public let kind: SpanKind = .internal
9696

9797
public var baggage: BaggageContext {
@@ -147,7 +147,7 @@ final class OSSignpostSpan: Span {
147147
signpostID: self.signpostID,
148148
Self.beginFormat,
149149
self.signpostID.rawValue,
150-
"\(context.signpostTraceParentIDs.map({ "\($0.rawValue)" }).joined(separator: ","))",
150+
"\(context.signpostTraceParentIDs.map { "\($0.rawValue)" }.joined(separator: ","))",
151151
operationName
152152
)
153153
}
@@ -160,16 +160,15 @@ final class OSSignpostSpan: Span {
160160
defer { self.lock.lock() }
161161
if self.endTimestamp == nil {
162162
print("""
163-
warning:
164-
Span \(self.signpostID) (\(self.operationName)) \
165-
[todo:source location] \
166-
was dropped without end() being called!
167-
""")
163+
warning:
164+
Span \(self.signpostID) (\(self.operationName)) \
165+
[todo:source location] \
166+
was dropped without end() being called!
167+
""")
168168
}
169169
}
170170
#endif
171171

172-
173172
public func addLink(_ link: SpanLink) {
174173
guard self.isRecording else { return }
175174
self.lock.lock()
@@ -203,7 +202,6 @@ final class OSSignpostSpan: Span {
203202
}
204203
}
205204

206-
207205
public func end(at timestamp: Timestamp) {
208206
guard self.isRecording else { return }
209207
self.lock.lock()
@@ -236,6 +234,7 @@ enum OSSignpostTracingKeys {
236234
enum TraceParentIDs: BaggageContextKey {
237235
typealias Value = [OSSignpostID]
238236
}
237+
239238
enum SignpostID: BaggageContextKey {
240239
typealias Value = OSSignpostID
241240
}
@@ -254,6 +253,7 @@ extension BaggageContext {
254253
self[OSSignpostTracingKeys.TraceParentIDs.self] = newValue
255254
}
256255
}
256+
257257
var signpostID: OSSignpostTracingKeys.SignpostID.Value? {
258258
get {
259259
self[OSSignpostTracingKeys.SignpostID.self]

UseCases/Sources/InstrumentsAppTracing/main.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
import Instrumentation
1514
import Baggage
1615
import Dispatch
16+
import Instrumentation
1717

1818
// ==== ----------------------------------------------------------------------------------------------------------------
1919
// MARK: Setup
@@ -36,7 +36,7 @@ if #available(macOS 10.14, iOS 10.0, *) {
3636
let tracer = InstrumentationSystem.tracer
3737
let context = BaggageContext()
3838

39-
for i in 1...5 {
39+
for i in 1 ... 5 {
4040
print("Starting operation: op-\(i)")
4141
var parentSpan = tracer.startSpan(named: "op-\(i)", context: context)
4242
defer { parentSpan.end() }
@@ -60,4 +60,3 @@ print("done.")
6060
print("Demo only available on macOS / Apple platforms.")
6161

6262
#endif
63-

0 commit comments

Comments
 (0)