Skip to content

Commit 49b7617

Browse files
authored
Remove platform requirement from Package.swift (#130)
1 parent ba07967 commit 49b7617

8 files changed

+125
-120
lines changed

Package.swift

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import PackageDescription
33

44
let package = Package(
55
name: "swift-distributed-tracing",
6-
platforms: [
7-
.macOS(.v10_15),
8-
.iOS(.v13),
9-
.tvOS(.v13),
10-
.watchOS(.v6),
11-
],
126
products: [
137
.library(name: "Instrumentation", targets: ["Instrumentation"]),
148
.library(name: "Tracing", targets: ["Tracing"]),

Sources/Tracing/InstrumentationSystem+Tracing.swift

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@_exported import Instrumentation
1616

17+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
1718
extension InstrumentationSystem {
1819
#if swift(>=5.7.0)
1920
/// Returns the ``Tracer`` bootstrapped as part of the `InstrumentationSystem`.

Sources/Tracing/NoOpTracer.swift

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public struct NoOpTracer: LegacyTracer {
9191
}
9292

9393
#if swift(>=5.7.0)
94+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
9495
extension NoOpTracer: Tracer {
9596
public func startSpan<Instant: TracerInstant>(
9697
_ operationName: String,

Sources/Tracing/Tracer.swift

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public func withSpan<T>(
276276
/// - operation: The operation that this span should be measuring
277277
/// - Returns: the value returned by `operation`
278278
/// - Throws: the error the `operation` has thrown (if any)
279+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
279280
public func withSpan<T>(
280281
_ operationName: String,
281282
context: @autoclosure () -> ServiceContext = .current ?? .topLevel,
@@ -418,6 +419,7 @@ public func withSpan<T>(
418419
/// - operation: The operation that this span should be measuring
419420
/// - Returns: the value returned by `operation`
420421
/// - Throws: the error the `operation` has thrown (if any)
422+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
421423
public func withSpan<T>(
422424
_ operationName: String,
423425
context: @autoclosure () -> ServiceContext = .current ?? .topLevel,

Sources/Tracing/TracerProtocol+Legacy.swift

+1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ extension LegacyTracer {
388388
#if swift(>=5.7.0)
389389
// Provide compatibility shims of the `...AnySpan` APIs to the 5.7 requiring `Tracer`.
390390

391+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
391392
extension Tracer {
392393
/// Start a new span returning an existential ``Span`` reference.
393394
///

Sources/Tracing/TracerProtocol.swift

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extension Tracer {
113113
// ==== ----------------------------------------------------------------------------------------------------------------
114114
// MARK: Starting spans: `withSpan`
115115

116+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
116117
extension Tracer {
117118
/// Start a new ``Span`` and automatically end when the `operation` completes,
118119
/// including recording the `error` in case the operation throws.

Sources/_TracingBenchmarks/SpanAttributesDSLBenchmark.swift

+115-111
Original file line numberDiff line numberDiff line change
@@ -15,121 +15,141 @@
1515
import _TracingBenchmarkTools
1616
import Tracing
1717

18-
public let SpanAttributesDSLBenchmarks: [BenchmarkInfo] = [
19-
BenchmarkInfo(
20-
name: "SpanAttributesDSLBenchmarks.000_bench_empty",
21-
runFunction: { _ in try! bench_empty(times: 100) },
22-
tags: [],
23-
setUpFunction: { setUp() },
24-
tearDownFunction: tearDown
25-
),
26-
BenchmarkInfo(
27-
name: "SpanAttributesDSLBenchmarks.001_bench_makeSpan",
28-
runFunction: { _ in try! bench_makeSpan(times: 100) },
29-
tags: [],
30-
setUpFunction: { setUp() },
31-
tearDownFunction: tearDown
32-
),
33-
BenchmarkInfo(
34-
name: "SpanAttributesDSLBenchmarks.002_bench_startSpan_end",
35-
runFunction: { _ in try! bench_makeSpan(times: 100) },
36-
tags: [],
37-
setUpFunction: { setUp() },
38-
tearDownFunction: tearDown
39-
),
40-
41-
BenchmarkInfo(
42-
name: "SpanAttributesDSLBenchmarks.00_bench_set_String_raw",
43-
runFunction: { _ in try! bench_set_String_raw(times: 100) },
44-
tags: [],
45-
setUpFunction: { setUp() },
46-
tearDownFunction: tearDown
47-
),
48-
BenchmarkInfo(
49-
name: "SpanAttributesDSLBenchmarks.01_bench_set_String_dsl",
50-
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
51-
tags: [],
52-
setUpFunction: { setUp() },
53-
tearDownFunction: tearDown
54-
),
55-
56-
BenchmarkInfo(
57-
name: "SpanAttributesDSLBenchmarks.02_bench_set_Int_raw",
58-
runFunction: { _ in try! bench_set_String_raw(times: 100) },
59-
tags: [],
60-
setUpFunction: { setUp() },
61-
tearDownFunction: tearDown
62-
),
63-
BenchmarkInfo(
64-
name: "SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl",
65-
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
66-
tags: [],
67-
setUpFunction: { setUp() },
68-
tearDownFunction: tearDown
69-
),
70-
]
71-
72-
private var span: (any Tracing.Span)!
73-
74-
private func setUp() {
75-
span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
76-
}
18+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
19+
enum DSLBenchmarks {
20+
public static let SpanAttributesDSLBenchmarks: [BenchmarkInfo] = [
21+
BenchmarkInfo(
22+
name: "SpanAttributesDSLBenchmarks.000_bench_empty",
23+
runFunction: { _ in try! bench_empty(times: 100) },
24+
tags: [],
25+
setUpFunction: { setUp() },
26+
tearDownFunction: tearDown
27+
),
28+
BenchmarkInfo(
29+
name: "SpanAttributesDSLBenchmarks.001_bench_makeSpan",
30+
runFunction: { _ in try! bench_makeSpan(times: 100) },
31+
tags: [],
32+
setUpFunction: { setUp() },
33+
tearDownFunction: tearDown
34+
),
35+
BenchmarkInfo(
36+
name: "SpanAttributesDSLBenchmarks.002_bench_startSpan_end",
37+
runFunction: { _ in try! bench_makeSpan(times: 100) },
38+
tags: [],
39+
setUpFunction: { setUp() },
40+
tearDownFunction: tearDown
41+
),
42+
43+
BenchmarkInfo(
44+
name: "SpanAttributesDSLBenchmarks.00_bench_set_String_raw",
45+
runFunction: { _ in try! bench_set_String_raw(times: 100) },
46+
tags: [],
47+
setUpFunction: { setUp() },
48+
tearDownFunction: tearDown
49+
),
50+
BenchmarkInfo(
51+
name: "SpanAttributesDSLBenchmarks.01_bench_set_String_dsl",
52+
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
53+
tags: [],
54+
setUpFunction: { setUp() },
55+
tearDownFunction: tearDown
56+
),
57+
58+
BenchmarkInfo(
59+
name: "SpanAttributesDSLBenchmarks.02_bench_set_Int_raw",
60+
runFunction: { _ in try! bench_set_String_raw(times: 100) },
61+
tags: [],
62+
setUpFunction: { setUp() },
63+
tearDownFunction: tearDown
64+
),
65+
BenchmarkInfo(
66+
name: "SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl",
67+
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
68+
tags: [],
69+
setUpFunction: { setUp() },
70+
tearDownFunction: tearDown
71+
),
72+
]
73+
74+
fileprivate static var span: (any Tracing.Span)!
75+
76+
fileprivate static func setUp() {
77+
self.span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
78+
}
7779

78-
private func tearDown() {
79-
span = nil
80-
}
80+
fileprivate static func tearDown() {
81+
self.span = nil
82+
}
8183

82-
// ==== ----------------------------------------------------------------------------------------------------------------
83-
// MARK: make span
84+
// ==== ----------------------------------------------------------------------------------------------------------------
85+
// MARK: make span
8486

85-
func bench_empty(times: Int) throws {}
87+
static func bench_empty(times: Int) throws {}
8688

87-
func bench_makeSpan(times: Int) throws {
88-
for _ in 0 ..< times {
89-
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
90-
_ = span
89+
static func bench_makeSpan(times: Int) throws {
90+
for _ in 0 ..< times {
91+
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
92+
_ = span
93+
}
9194
}
92-
}
9395

94-
func bench_startSpan_end(times: Int) throws {
95-
for _ in 0 ..< times {
96-
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
97-
span.end()
96+
static func bench_startSpan_end(times: Int) throws {
97+
for _ in 0 ..< times {
98+
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
99+
span.end()
100+
}
98101
}
99-
}
100102

101-
// ==== ----------------------------------------------------------------------------------------------------------------
102-
// MARK: set String
103+
// ==== ----------------------------------------------------------------------------------------------------------------
104+
// MARK: set String
103105

104-
func bench_set_String_raw(times: Int) throws {
105-
for _ in 0 ..< times {
106-
span.attributes["http.method"] = "POST"
106+
static func bench_set_String_raw(times: Int) throws {
107+
for _ in 0 ..< times {
108+
self.span.attributes["http.method"] = "POST"
109+
}
107110
}
108-
}
109111

110-
func bench_set_String_dsl(times: Int) throws {
111-
for _ in 0 ..< times {
112-
span.attributes.http.method = "POST"
112+
static func bench_set_String_dsl(times: Int) throws {
113+
for _ in 0 ..< times {
114+
self.span.attributes.http.method = "POST"
115+
}
113116
}
114-
}
115117

116-
// ==== ----------------------------------------------------------------------------------------------------------------
117-
// MARK: set Int
118+
// ==== ----------------------------------------------------------------------------------------------------------------
119+
// MARK: set Int
118120

119-
func bench_set_Int_raw(times: Int) throws {
120-
for _ in 0 ..< times {
121-
span.attributes["http.status_code"] = 200
121+
static func bench_set_Int_raw(times: Int) throws {
122+
for _ in 0 ..< times {
123+
self.span.attributes["http.status_code"] = 200
124+
}
122125
}
123-
}
124126

125-
func bench_set_Int_dsl(times: Int) throws {
126-
for _ in 0 ..< times {
127-
span.attributes.http.statusCode = 200
127+
static func bench_set_Int_dsl(times: Int) throws {
128+
for _ in 0 ..< times {
129+
self.span.attributes.http.statusCode = 200
130+
}
131+
}
132+
133+
@dynamicMemberLookup
134+
struct HTTPAttributes: SpanAttributeNamespace {
135+
var attributes: SpanAttributes
136+
137+
init(attributes: SpanAttributes) {
138+
self.attributes = attributes
139+
}
140+
141+
struct NestedSpanAttributes: NestedSpanAttributesProtocol {
142+
init() {}
143+
144+
var method: Key<String> { "http.method" }
145+
var statusCode: Key<Int> { "http.status_code" }
146+
}
128147
}
129148
}
130149

150+
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
131151
extension SpanAttributes {
132-
var http: HTTPAttributes {
152+
var http: DSLBenchmarks.HTTPAttributes {
133153
get {
134154
.init(attributes: self)
135155
}
@@ -138,19 +158,3 @@ extension SpanAttributes {
138158
}
139159
}
140160
}
141-
142-
@dynamicMemberLookup
143-
struct HTTPAttributes: SpanAttributeNamespace {
144-
var attributes: SpanAttributes
145-
146-
init(attributes: SpanAttributes) {
147-
self.attributes = attributes
148-
}
149-
150-
struct NestedSpanAttributes: NestedSpanAttributesProtocol {
151-
init() {}
152-
153-
var method: Key<String> { "http.method" }
154-
var statusCode: Key<Int> { "http.status_code" }
155-
}
156-
}

Sources/_TracingBenchmarks/main.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private func registerBenchmark(_ name: String, _ function: @escaping (Int) -> Vo
3737
registerBenchmark(BenchmarkInfo(name: name, runFunction: function, tags: tags))
3838
}
3939

40-
registerBenchmark(SpanAttributesDSLBenchmarks)
41-
42-
main()
40+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) { // for TaskLocal ServiceContext
41+
registerBenchmark(DSLBenchmarks.SpanAttributesDSLBenchmarks)
42+
main()
43+
}

0 commit comments

Comments
 (0)