Skip to content

Commit a7e66b3

Browse files
committed
SpanProtocol -> Span after all
Rationale: since passing around any SpanProtocol a lot looked terrible; Also, less breakage in protocol renaming
1 parent 7586bdc commit a7e66b3

12 files changed

+57
-64
lines changed

Sources/Tracing/NoOpTracer.swift

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

1919
/// Tracer that ignores all operations, used when no tracing is required.
2020
public struct NoOpTracer: LegacyTracerProtocol {
21-
public typealias Span = NoOpSpan
21+
public typealias TracerSpan = NoOpSpan
2222

2323
public init() {}
2424

@@ -28,7 +28,7 @@ public struct NoOpTracer: LegacyTracerProtocol {
2828
at time: DispatchWallTime,
2929
function: String,
3030
file fileID: String,
31-
line: UInt) -> any SpanProtocol
31+
line: UInt) -> any Span
3232
{
3333
NoOpSpan(baggage: baggage())
3434
}
@@ -47,7 +47,7 @@ public struct NoOpTracer: LegacyTracerProtocol {
4747
// no-op
4848
}
4949

50-
public final class NoOpSpan: SpanProtocol {
50+
public final class NoOpSpan: Span {
5151
public let baggage: Baggage
5252
public var isRecording: Bool {
5353
false

Sources/Tracing/SpanProtocol.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import struct Dispatch.DispatchWallTime
2626
/// Creating a `Span` is delegated to a ``Tracer`` and end users should never create them directly.
2727
///
2828
/// - SeeAlso: For more details refer to the [OpenTelemetry Specification: Span](https://github.com/open-telemetry/opentelemetry-specification/blob/v0.7.0/specification/trace/api.md#span) which this type is compatible with.
29-
public protocol SpanProtocol: AnyObject, _SwiftTracingSendableSpan {
29+
public protocol Span: AnyObject, _SwiftTracingSendableSpan {
3030
/// The read-only `Baggage` of this `Span`, set when starting this `Span`.
3131
var baggage: Baggage { get }
3232

@@ -91,7 +91,7 @@ public protocol SpanProtocol: AnyObject, _SwiftTracingSendableSpan {
9191
func end(at time: DispatchWallTime)
9292
}
9393

94-
extension SpanProtocol {
94+
extension Span {
9595
/// End this `Span` at the current time.
9696
///
9797
/// ### Rules about ending Spans
@@ -114,12 +114,12 @@ extension SpanProtocol {
114114
///
115115
/// - Parameter other: The `Span` to link to.
116116
/// - Parameter attributes: The ``SpanAttributes`` describing this link. Defaults to no attributes.
117-
public func addLink(_ other: SpanProtocol, attributes: SpanAttributes = [:]) {
117+
public func addLink(_ other: Span, attributes: SpanAttributes = [:]) {
118118
self.addLink(SpanLink(baggage: other.baggage, attributes: attributes))
119119
}
120120
}
121121

122-
extension SpanProtocol {
122+
extension Span {
123123
/// Record a failure described by the given error.
124124
///
125125
/// - Parameters:
@@ -176,7 +176,6 @@ public struct SpanAttributeKey<T>: Hashable, ExpressibleByStringLiteral where T:
176176
}
177177
}
178178

179-
#if swift(>=5.2)
180179
@dynamicMemberLookup
181180
public protocol SpanAttributeNamespace {
182181
/// Type that contains the nested attributes, e.g. HTTPAttributes which would contain `statusCode` and similar vars.
@@ -247,7 +246,6 @@ extension SpanAttributeNamespace {
247246
SpanAttribute.int(0)[keyPath: dynamicMember]
248247
}
249248
}
250-
#endif
251249

252250
/// The value of an attribute used to describe a ``Span`` or ``SpanEvent``.
253251
///

Sources/Tracing/Tracer.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension Tracer {
5858
function: String = #function,
5959
file fileID: String = #fileID,
6060
line: UInt = #line
61-
) -> any SpanProtocol {
61+
) -> any Span {
6262
// Effectively these end up calling the same method, however
6363
// we try to not use the deprecated methods ourselves anyway
6464
#if swift(>=5.7.0)
@@ -90,7 +90,7 @@ extension Tracer {
9090
/// we're about to start a top-level span, or if a span should be started from a different,
9191
/// stored away previously,
9292
///
93-
/// - Warning: You MUST NOT ``SpanProtocol/end()`` the span explicitly, because at the end of the `withSpan`
93+
/// - Warning: You MUST NOT ``Span/end()`` the span explicitly, because at the end of the `withSpan`
9494
/// operation closure returning the span will be closed automatically.
9595
///
9696
/// - Parameters:
@@ -111,7 +111,7 @@ extension Tracer {
111111
function: String = #function,
112112
file fileID: String = #fileID,
113113
line: UInt = #line,
114-
_ operation: (any SpanProtocol) throws -> T
114+
_ operation: (any Span) throws -> T
115115
) rethrows -> T {
116116
#if swift(>=5.7.0)
117117
try InstrumentationSystem.legacyTracer.withAnySpan(
@@ -145,7 +145,7 @@ extension Tracer {
145145
/// we're about to start a top-level span, or if a span should be started from a different,
146146
/// stored away previously,
147147
///
148-
/// - Warning: You MUST NOT ``SpanProtocol/end()`` the span explicitly, because at the end of the `withSpan`
148+
/// - Warning: You MUST NOT ``Span/end()`` the span explicitly, because at the end of the `withSpan`
149149
/// operation closure returning the span will be closed automatically.
150150
///
151151
/// - Parameters:
@@ -170,7 +170,7 @@ extension Tracer {
170170
function: String = #function,
171171
file fileID: String = #fileID,
172172
line: UInt = #line,
173-
_ operation: (any SpanProtocol) async throws -> T
173+
_ operation: (any Span) async throws -> T
174174
) async rethrows -> T {
175175
try await InstrumentationSystem.legacyTracer.withAnySpan(
176176
operationName,
@@ -194,7 +194,7 @@ extension Tracer {
194194
function: String = #function,
195195
file fileID: String = #fileID,
196196
line: UInt = #line,
197-
_ operation: (any SpanProtocol) async throws -> T
197+
_ operation: (any Span) async throws -> T
198198
) async rethrows -> T {
199199
try await InstrumentationSystem.legacyTracer.withAnySpan(
200200
operationName,

Sources/Tracing/TracerProtocol+Legacy.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Dispatch
1818

1919
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
2020
public protocol LegacyTracerProtocol: InstrumentProtocol {
21-
/// Start a new span returning an existential ``SpanProtocol`` reference.
21+
/// Start a new span returning an existential ``Span`` reference.
2222
///
2323
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
2424
/// is recommended instead.
@@ -55,7 +55,7 @@ public protocol LegacyTracerProtocol: InstrumentProtocol {
5555
function: String,
5656
file fileID: String,
5757
line: UInt
58-
) -> any SpanProtocol
58+
) -> any Span
5959

6060
/// Export all ended spans to the configured backend that have not yet been exported.
6161
///
@@ -71,7 +71,7 @@ public protocol LegacyTracerProtocol: InstrumentProtocol {
7171

7272
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
7373
extension LegacyTracerProtocol {
74-
/// Start a new span returning an existential ``SpanProtocol`` reference.
74+
/// Start a new span returning an existential ``Span`` reference.
7575
///
7676
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
7777
/// is recommended instead.
@@ -108,7 +108,7 @@ extension LegacyTracerProtocol {
108108
function: String = #function,
109109
file fileID: String = #fileID,
110110
line: UInt = #line
111-
) -> any SpanProtocol {
111+
) -> any Span {
112112
self.startAnySpan(
113113
operationName,
114114
baggage: baggage(),
@@ -120,7 +120,7 @@ extension LegacyTracerProtocol {
120120
)
121121
}
122122

123-
/// Start a new ``SpanProtocol`` and automatically end when the `operation` completes,
123+
/// Start a new ``Span`` and automatically end when the `operation` completes,
124124
/// including recording the `error` in case the operation throws.
125125
///
126126
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
@@ -161,7 +161,7 @@ extension LegacyTracerProtocol {
161161
function: String = #function,
162162
file fileID: String = #fileID,
163163
line: UInt = #line,
164-
_ operation: (any SpanProtocol) throws -> T
164+
_ operation: (any Span) throws -> T
165165
) rethrows -> T {
166166
let span = self.startAnySpan(operationName, baggage: baggage(), ofKind: kind, at: time, function: function, file: fileID, line: line)
167167
defer { span.end() }
@@ -175,7 +175,7 @@ extension LegacyTracerProtocol {
175175
}
176176
}
177177

178-
/// Start a new ``SpanProtocol`` and automatically end when the `operation` completes,
178+
/// Start a new ``Span`` and automatically end when the `operation` completes,
179179
/// including recording the `error` in case the operation throws.
180180
///
181181
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
@@ -216,7 +216,7 @@ extension LegacyTracerProtocol {
216216
function: String = #function,
217217
file fileID: String = #fileID,
218218
line: UInt = #line,
219-
_ operation: (any SpanProtocol) async throws -> T
219+
_ operation: (any Span) async throws -> T
220220
) async rethrows -> T {
221221
let span = self.startAnySpan(operationName, baggage: baggage(), ofKind: kind, at: time, function: function, file: fileID, line: line)
222222
defer { span.end() }
@@ -236,7 +236,7 @@ extension LegacyTracerProtocol {
236236

237237
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
238238
extension TracerProtocol {
239-
/// Start a new span returning an existential ``SpanProtocol`` reference.
239+
/// Start a new span returning an existential ``Span`` reference.
240240
///
241241
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
242242
/// is recommended instead.
@@ -273,7 +273,7 @@ extension TracerProtocol {
273273
function: String = #function,
274274
file fileID: String = #fileID,
275275
line: UInt = #line
276-
) -> any SpanProtocol {
276+
) -> any Span {
277277
self.startSpan(
278278
operationName,
279279
baggage: baggage(),
@@ -285,7 +285,7 @@ extension TracerProtocol {
285285
)
286286
}
287287

288-
/// Start a new ``SpanProtocol`` and automatically end when the `operation` completes,
288+
/// Start a new ``Span`` and automatically end when the `operation` completes,
289289
/// including recording the `error` in case the operation throws.
290290
///
291291
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
@@ -326,7 +326,7 @@ extension TracerProtocol {
326326
function: String = #function,
327327
file fileID: String = #fileID,
328328
line: UInt = #line,
329-
_ operation: (any SpanProtocol) throws -> T
329+
_ operation: (any Span) throws -> T
330330
) rethrows -> T {
331331
try self.withSpan(
332332
operationName,
@@ -341,7 +341,7 @@ extension TracerProtocol {
341341
}
342342
}
343343

344-
/// Start a new ``SpanProtocol`` and automatically end when the `operation` completes,
344+
/// Start a new ``Span`` and automatically end when the `operation` completes,
345345
/// including recording the `error` in case the operation throws.
346346
///
347347
/// This API will be deprecated as soon as Swift 5.9 is released, and the Swift 5.7 requiring `TracerProtocol`
@@ -384,7 +384,7 @@ extension TracerProtocol {
384384
function: String = #function,
385385
file fileID: String = #fileID,
386386
line: UInt = #line,
387-
_ operation: (any SpanProtocol) async throws -> T
387+
_ operation: (any Span) async throws -> T
388388
) async rethrows -> T {
389389
try await self.withSpan(
390390
operationName,
@@ -408,7 +408,7 @@ extension TracerProtocol {
408408
function: String = #function,
409409
file fileID: String = #fileID,
410410
line: UInt = #line,
411-
_ operation: (any SpanProtocol) async throws -> T
411+
_ operation: (any Span) async throws -> T
412412
) async rethrows -> T {
413413
try await self.withSpan(
414414
operationName,

Sources/Tracing/TracerProtocol.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import Dispatch
2222
#if swift(>=5.7.0)
2323
/// A tracer capable of creating new trace spans.
2424
///
25-
/// A tracer is a special kind of instrument with the added ability to start a ``SpanProtocol``.
25+
/// A tracer is a special kind of instrument with the added ability to start a ``Span``.
2626
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
2727
public protocol TracerProtocol: LegacyTracerProtocol {
2828
/// The concrete type of span this tracer will be producing/
29-
associatedtype Span: SpanProtocol
29+
associatedtype TracerSpan: Span
3030

3131
/// Start a new ``Span`` with the given `Baggage`.
3232
///
@@ -60,7 +60,7 @@ public protocol TracerProtocol: LegacyTracerProtocol {
6060
function: String,
6161
file fileID: String,
6262
line: UInt
63-
) -> Self.Span
63+
) -> TracerSpan
6464
}
6565

6666
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal Baggage
@@ -97,7 +97,7 @@ extension TracerProtocol {
9797
function: String = #function,
9898
file fileID: String = #fileID,
9999
line: UInt = #line
100-
) -> Self.Span {
100+
) -> TracerSpan {
101101
self.startSpan(
102102
operationName,
103103
baggage: baggage(),
@@ -124,7 +124,7 @@ extension TracerProtocol {
124124
/// we're about to start a top-level span, or if a span should be started from a different,
125125
/// stored away previously,
126126
///
127-
/// - Warning: You MUST NOT ``SpanProtocol/end()`` the span explicitly, because at the end of the `withSpan`
127+
/// - Warning: You MUST NOT ``Span/end()`` the span explicitly, because at the end of the `withSpan`
128128
/// operation closure returning the span will be closed automatically.
129129
///
130130
/// - Parameters:
@@ -146,7 +146,7 @@ extension TracerProtocol {
146146
function: String = #function,
147147
file fileID: String = #fileID,
148148
line: UInt = #line,
149-
_ operation: (Self.Span) throws -> T
149+
_ operation: (TracerSpan) throws -> T
150150
) rethrows -> T {
151151
let span = self.startSpan(
152152
operationName,
@@ -177,7 +177,7 @@ extension TracerProtocol {
177177
/// we're about to start a top-level span, or if a span should be started from a different,
178178
/// stored away previously,
179179
///
180-
/// - Warning: You MUST NOT ``SpanProtocol/end()`` the span explicitly, because at the end of the `withSpan`
180+
/// - Warning: You MUST NOT ``Span/end()`` the span explicitly, because at the end of the `withSpan`
181181
/// operation closure returning the span will be closed automatically.
182182
///
183183
/// - Parameters:
@@ -200,7 +200,7 @@ extension TracerProtocol {
200200
function: String = #function,
201201
file fileID: String = #fileID,
202202
line: UInt = #line,
203-
_ operation: (Self.Span) async throws -> T
203+
_ operation: (TracerSpan) async throws -> T
204204
) async rethrows -> T {
205205
let span = self.startSpan(
206206
operationName,

Sources/_TracingBenchmarks/SpanAttributesDSLBenchmark.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public let SpanAttributesDSLBenchmarks: [BenchmarkInfo] = [
6969
),
7070
]
7171

72-
private var span: (any SpanProtocol)!
72+
private var span: (any Span)!
7373

7474
private func setUp() {
7575
span = InstrumentationSystem.legacyTracer.startAnySpan("something", baggage: .topLevel)

Tests/TracingTests/DynamicTracepointTracerTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ final class DynamicTracepointTestTracer: LegacyTracerProtocol {
164164
}
165165

166166
private(set) var spans: [TracepointSpan] = []
167-
var onEndSpan: (SpanProtocol) -> Void = { _ in
167+
var onEndSpan: (Span) -> Void = { _ in
168168
}
169169

170170
func startAnySpan(
@@ -175,7 +175,7 @@ final class DynamicTracepointTestTracer: LegacyTracerProtocol {
175175
function: String,
176176
file fileID: String,
177177
line: UInt
178-
) -> any SpanProtocol {
178+
) -> any Span {
179179
let tracepoint = TracepointID(function: function, fileID: fileID, line: line)
180180
guard self.shouldRecord(tracepoint: tracepoint) else {
181181
return TracepointSpan.notRecording(file: fileID, line: line)
@@ -255,7 +255,7 @@ final class DynamicTracepointTestTracer: LegacyTracerProtocol {
255255

256256
extension DynamicTracepointTestTracer {
257257
/// Only intended to be used in single-threaded testing.
258-
final class TracepointSpan: Tracing.SpanProtocol {
258+
final class TracepointSpan: Tracing.Span {
259259
private let kind: SpanKind
260260

261261
private var status: SpanStatus?
@@ -333,7 +333,7 @@ extension DynamicTracepointTestTracer {
333333

334334
#if compiler(>=5.7.0)
335335
extension DynamicTracepointTestTracer: TracerProtocol {
336-
typealias Span = TracepointSpan
336+
typealias TracerSpan = TracepointSpan
337337

338338
func startSpan(_ operationName: String,
339339
baggage: @autoclosure () -> Baggage,

0 commit comments

Comments
 (0)