Skip to content

Remove platform requirement from Package.swift #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import PackageDescription

let package = Package(
name: "swift-distributed-tracing",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
.library(name: "Instrumentation", targets: ["Instrumentation"]),
.library(name: "Tracing", targets: ["Tracing"]),
Expand Down
1 change: 1 addition & 0 deletions Sources/Tracing/InstrumentationSystem+Tracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@_exported import Instrumentation

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension InstrumentationSystem {
#if swift(>=5.7.0)
/// Returns the ``Tracer`` bootstrapped as part of the `InstrumentationSystem`.
Expand Down
1 change: 1 addition & 0 deletions Sources/Tracing/NoOpTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public struct NoOpTracer: LegacyTracer {
}

#if swift(>=5.7.0)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension NoOpTracer: Tracer {
public func startSpan<Instant: TracerInstant>(
_ operationName: String,
Expand Down
2 changes: 2 additions & 0 deletions Sources/Tracing/Tracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public func withSpan<T>(
/// - operation: The operation that this span should be measuring
/// - Returns: the value returned by `operation`
/// - Throws: the error the `operation` has thrown (if any)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func withSpan<T>(
_ operationName: String,
context: @autoclosure () -> ServiceContext = .current ?? .topLevel,
Expand Down Expand Up @@ -418,6 +419,7 @@ public func withSpan<T>(
/// - operation: The operation that this span should be measuring
/// - Returns: the value returned by `operation`
/// - Throws: the error the `operation` has thrown (if any)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func withSpan<T>(
_ operationName: String,
context: @autoclosure () -> ServiceContext = .current ?? .topLevel,
Expand Down
1 change: 1 addition & 0 deletions Sources/Tracing/TracerProtocol+Legacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ extension LegacyTracer {
#if swift(>=5.7.0)
// Provide compatibility shims of the `...AnySpan` APIs to the 5.7 requiring `Tracer`.

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Tracer {
/// Start a new span returning an existential ``Span`` reference.
///
Expand Down
1 change: 1 addition & 0 deletions Sources/Tracing/TracerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ extension Tracer {
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: Starting spans: `withSpan`

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Tracer {
/// Start a new ``Span`` and automatically end when the `operation` completes,
/// including recording the `error` in case the operation throws.
Expand Down
226 changes: 115 additions & 111 deletions Sources/_TracingBenchmarks/SpanAttributesDSLBenchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,121 +15,141 @@
import _TracingBenchmarkTools
import Tracing

public let SpanAttributesDSLBenchmarks: [BenchmarkInfo] = [
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.000_bench_empty",
runFunction: { _ in try! bench_empty(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.001_bench_makeSpan",
runFunction: { _ in try! bench_makeSpan(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.002_bench_startSpan_end",
runFunction: { _ in try! bench_makeSpan(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),

BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.00_bench_set_String_raw",
runFunction: { _ in try! bench_set_String_raw(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.01_bench_set_String_dsl",
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),

BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.02_bench_set_Int_raw",
runFunction: { _ in try! bench_set_String_raw(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl",
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
]

private var span: (any Tracing.Span)!

private func setUp() {
span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
}
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
enum DSLBenchmarks {
public static let SpanAttributesDSLBenchmarks: [BenchmarkInfo] = [
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.000_bench_empty",
runFunction: { _ in try! bench_empty(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.001_bench_makeSpan",
runFunction: { _ in try! bench_makeSpan(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.002_bench_startSpan_end",
runFunction: { _ in try! bench_makeSpan(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),

BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.00_bench_set_String_raw",
runFunction: { _ in try! bench_set_String_raw(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.01_bench_set_String_dsl",
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),

BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.02_bench_set_Int_raw",
runFunction: { _ in try! bench_set_String_raw(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
BenchmarkInfo(
name: "SpanAttributesDSLBenchmarks.03_bench_set_Int_dsl",
runFunction: { _ in try! bench_set_String_dsl(times: 100) },
tags: [],
setUpFunction: { setUp() },
tearDownFunction: tearDown
),
]

fileprivate static var span: (any Tracing.Span)!

fileprivate static func setUp() {
self.span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
}

private func tearDown() {
span = nil
}
fileprivate static func tearDown() {
self.span = nil
}

// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: make span
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: make span

func bench_empty(times: Int) throws {}
static func bench_empty(times: Int) throws {}

func bench_makeSpan(times: Int) throws {
for _ in 0 ..< times {
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
_ = span
static func bench_makeSpan(times: Int) throws {
for _ in 0 ..< times {
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
_ = span
}
}
}

func bench_startSpan_end(times: Int) throws {
for _ in 0 ..< times {
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
span.end()
static func bench_startSpan_end(times: Int) throws {
for _ in 0 ..< times {
let span = InstrumentationSystem.legacyTracer.startAnySpan("something", context: .topLevel)
span.end()
}
}
}

// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: set String
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: set String

func bench_set_String_raw(times: Int) throws {
for _ in 0 ..< times {
span.attributes["http.method"] = "POST"
static func bench_set_String_raw(times: Int) throws {
for _ in 0 ..< times {
self.span.attributes["http.method"] = "POST"
}
}
}

func bench_set_String_dsl(times: Int) throws {
for _ in 0 ..< times {
span.attributes.http.method = "POST"
static func bench_set_String_dsl(times: Int) throws {
for _ in 0 ..< times {
self.span.attributes.http.method = "POST"
}
}
}

// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: set Int
// ==== ----------------------------------------------------------------------------------------------------------------
// MARK: set Int

func bench_set_Int_raw(times: Int) throws {
for _ in 0 ..< times {
span.attributes["http.status_code"] = 200
static func bench_set_Int_raw(times: Int) throws {
for _ in 0 ..< times {
self.span.attributes["http.status_code"] = 200
}
}
}

func bench_set_Int_dsl(times: Int) throws {
for _ in 0 ..< times {
span.attributes.http.statusCode = 200
static func bench_set_Int_dsl(times: Int) throws {
for _ in 0 ..< times {
self.span.attributes.http.statusCode = 200
}
}

@dynamicMemberLookup
struct HTTPAttributes: SpanAttributeNamespace {
var attributes: SpanAttributes

init(attributes: SpanAttributes) {
self.attributes = attributes
}

struct NestedSpanAttributes: NestedSpanAttributesProtocol {
init() {}

var method: Key<String> { "http.method" }
var statusCode: Key<Int> { "http.status_code" }
}
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
extension SpanAttributes {
var http: HTTPAttributes {
var http: DSLBenchmarks.HTTPAttributes {
get {
.init(attributes: self)
}
Expand All @@ -138,19 +158,3 @@ extension SpanAttributes {
}
}
}

@dynamicMemberLookup
struct HTTPAttributes: SpanAttributeNamespace {
var attributes: SpanAttributes

init(attributes: SpanAttributes) {
self.attributes = attributes
}

struct NestedSpanAttributes: NestedSpanAttributesProtocol {
init() {}

var method: Key<String> { "http.method" }
var statusCode: Key<Int> { "http.status_code" }
}
}
7 changes: 4 additions & 3 deletions Sources/_TracingBenchmarks/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private func registerBenchmark(_ name: String, _ function: @escaping (Int) -> Vo
registerBenchmark(BenchmarkInfo(name: name, runFunction: function, tags: tags))
}

registerBenchmark(SpanAttributesDSLBenchmarks)

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