Skip to content

Commit a3f8d50

Browse files
authored
Merge branch 'main' into drop_swift_5_6
2 parents b806831 + b80af1b commit a3f8d50

File tree

13 files changed

+232
-1294
lines changed

13 files changed

+232
-1294
lines changed

Benchmarks/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build/

Benchmarks/.gitkeep

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2023 Apple Inc. and the Swift Distributed Tracing project
6+
// authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Benchmark
16+
import Tracing
17+
18+
let benchmarks = {
19+
let defaultMetrics: [BenchmarkMetric] = [
20+
.mallocCountTotal,
21+
]
22+
23+
Benchmark(
24+
"NoopTracing.startSpan/endSpan",
25+
configuration: .init(
26+
metrics: defaultMetrics,
27+
timeUnits: .nanoseconds,
28+
scalingFactor: .mega
29+
)
30+
) { benchmark in
31+
let span = startSpan("name")
32+
defer { span.end() }
33+
}
34+
35+
Benchmark(
36+
"NoopTracing.attribute: set, span.attributes['http.status_code'] = 200",
37+
configuration: .init(
38+
metrics: defaultMetrics,
39+
timeUnits: .nanoseconds,
40+
scalingFactor: .mega
41+
)
42+
) { benchmark in
43+
let span = startSpan("name")
44+
span.attributes["http.status_code"] = 200
45+
defer { span.end() }
46+
}
47+
48+
Benchmark(
49+
"NoopTracing.attribute: set, span.attributes.http.status_code = 200",
50+
configuration: .init(
51+
metrics: defaultMetrics,
52+
timeUnits: .nanoseconds,
53+
scalingFactor: .mega
54+
)
55+
) { benchmark in
56+
let span = startSpan("name")
57+
span.attributes.http.statusCode = 200
58+
defer { span.end() }
59+
}
60+
}
61+
62+
@dynamicMemberLookup
63+
struct HTTPAttributes: SpanAttributeNamespace {
64+
var attributes: SpanAttributes
65+
66+
init(attributes: SpanAttributes) {
67+
self.attributes = attributes
68+
}
69+
70+
struct NestedSpanAttributes: NestedSpanAttributesProtocol {
71+
init() {}
72+
73+
var method: Key<String> { "http.method" }
74+
var statusCode: Key<Int> { "http.status_code" }
75+
}
76+
}
77+
78+
extension SpanAttributes {
79+
var http: HTTPAttributes {
80+
get {
81+
.init(attributes: self)
82+
}
83+
set {
84+
self = newValue.attributes
85+
}
86+
}
87+
}

Benchmarks/Package.resolved

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Benchmarks/Package.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// swift-tools-version: 5.9
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftCertificates open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
let package = Package(
19+
name: "benchmarks",
20+
platforms: [
21+
.macOS("14"),
22+
],
23+
dependencies: [
24+
.package(path: "../"),
25+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.0"),
26+
],
27+
targets: [
28+
.executableTarget(
29+
name: "TracingBenchmarks",
30+
dependencies: [
31+
.product(name: "Benchmark", package: "package-benchmark"),
32+
.product(name: "Tracing", package: "swift-distributed-tracing"),
33+
],
34+
path: "Benchmarks/TracingBenchmarks",
35+
plugins: [
36+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
37+
]
38+
),
39+
]
40+
)

Package.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,5 @@ let package = Package(
4343
.target(name: "Tracing"),
4444
]
4545
),
46-
47-
// ==== --------------------------------------------------------------------------------------------------------
48-
// MARK: Performance / Benchmarks
49-
50-
.executableTarget(
51-
name: "_TracingBenchmarks",
52-
dependencies: [
53-
.product(name: "ServiceContextModule", package: "swift-service-context"),
54-
.target(name: "Tracing"),
55-
.target(name: "_TracingBenchmarkTools"),
56-
]
57-
),
58-
.target(
59-
name: "_TracingBenchmarkTools",
60-
dependencies: [
61-
.target(name: "Instrumentation"),
62-
],
63-
exclude: ["README_SWIFT.md"]
64-
),
6546
]
6647
)

Sources/Tracing/Tracer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public func withSpan<T, Instant: TracerInstant>(
193193
) rethrows -> T {
194194
try InstrumentationSystem.legacyTracer.withAnySpan(
195195
operationName,
196-
at: DefaultTracerClock.now,
196+
at: instant(),
197197
context: context(),
198198
ofKind: kind,
199199
function: function,
@@ -334,7 +334,7 @@ public func withSpan<T, Instant: TracerInstant>(
334334
) async rethrows -> T {
335335
try await InstrumentationSystem.legacyTracer.withAnySpan(
336336
operationName,
337-
at: DefaultTracerClock.now,
337+
at: instant(),
338338
context: context(),
339339
ofKind: kind,
340340
function: function,

0 commit comments

Comments
 (0)