Skip to content

Commit 4ea3267

Browse files
authored
Merge branch 'main' into wip-docs-1.0
2 parents eb6fc21 + 8f5315e commit 4ea3267

12 files changed

+480
-21
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.3.0")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
1212
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1313
],
1414
targets: [

Package@swift-5.2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.3.0")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
1212
],
1313
targets: [
1414
// ==== --------------------------------------------------------------------------------------------------------

Package@swift-5.3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.3.0")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
1212
],
1313
targets: [
1414
// ==== --------------------------------------------------------------------------------------------------------

Package@swift-5.4.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.3.0")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
1212
],
1313
targets: [
1414
// ==== --------------------------------------------------------------------------------------------------------

Package@swift-5.5.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let package = Package(
88
.library(name: "Tracing", targets: ["Tracing"]),
99
],
1010
dependencies: [
11-
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.3.0")),
11+
.package(url: "https://github.com/apple/swift-distributed-tracing-baggage.git", .upToNextMinor(from: "0.4.1")),
1212
],
1313
targets: [
1414
// ==== --------------------------------------------------------------------------------------------------------

Sources/Tracing/NoOpTracer.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public struct NoOpTracer: TracerProtocol {
2424
_ operationName: String,
2525
baggage: Baggage,
2626
ofKind kind: SpanKind,
27-
at time: DispatchWallTime
27+
at time: DispatchWallTime,
28+
function: String,
29+
file fileID: String,
30+
line: UInt
2831
) -> Span {
2932
NoOpSpan(baggage: baggage)
3033
}

Sources/Tracing/Tracer.swift

Lines changed: 125 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,85 @@ public protocol TracerStartSpanOps {
4040
/// - baggage: The `Baggage` providing information on where to start the new ``Span``.
4141
/// - kind: The ``SpanKind`` of the new ``Span``.
4242
/// - time: The `DispatchTime` at which to start the new ``Span``.
43+
/// - function: The function name in which the span was started
44+
/// - fileID: The `fileID` where the span was started.
45+
/// - line: The file line where the span was started.
4346
func startSpan(
4447
_ operationName: String,
4548
baggage: Baggage,
4649
ofKind kind: SpanKind,
47-
at time: DispatchWallTime
50+
at time: DispatchWallTime,
51+
function: String,
52+
file fileID: String,
53+
line: UInt
4854
) -> Span
4955
}
5056

51-
extension TracerStartSpanOps {
52-
/// Start a new ``Span`` with the given `Baggage` starting at `DispatchWallTime.now()`.
57+
extension Tracer {
58+
#if swift(>=5.3.0)
59+
/// Start a new ``Span`` with the given `Baggage` starting "now".
60+
///
61+
/// - Parameters:
62+
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
63+
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
64+
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
65+
/// - function: The function name in which the span was started.
66+
/// - fileID: The `fileID` where the span was started.
67+
/// - line: The file line where the span was started.
68+
public func startSpan(
69+
_ operationName: String,
70+
baggage: Baggage,
71+
ofKind kind: SpanKind = .internal,
72+
function: String = #function,
73+
file fileID: String = #fileID,
74+
line: UInt = #line
75+
) -> Span {
76+
self.startSpan(
77+
operationName,
78+
baggage: baggage,
79+
ofKind: kind,
80+
at: .now(),
81+
function: function,
82+
file: fileID,
83+
line: line
84+
)
85+
}
86+
#else
87+
/// Start a new ``Span`` with the given `Baggage` starting "now".
5388
///
5489
/// - Parameters:
5590
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
5691
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
5792
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
93+
/// - function: The function name in which the span was started.
94+
/// - file: The `file` where the span was started.
95+
/// - line: The file line where the span was started.
5896
public func startSpan(
5997
_ operationName: String,
6098
baggage: Baggage,
61-
ofKind kind: SpanKind = .internal
99+
ofKind kind: SpanKind = .internal,
100+
function: String = #function,
101+
file: String = #file,
102+
line: UInt = #line
62103
) -> Span {
63-
self.startSpan(operationName, baggage: baggage, ofKind: kind, at: .now())
104+
self.startSpan(
105+
operationName,
106+
baggage: baggage,
107+
ofKind: kind,
108+
at: .now(),
109+
function: function,
110+
file: file,
111+
line: line
112+
)
64113
}
114+
#endif
65115
}
66116

67117
// ==== ----------------------------------------------------------------------------------------------------------------
68118
// MARK: Starting spans: `withSpan`
69119

70120
extension TracerStartSpanOps {
121+
#if swift(>=5.3.0)
71122
/// Execute a specific task within a newly created ``Span``.
72123
///
73124
/// DO NOT `end()` the passed in span manually. It will be ended automatically when the `operation` returns.
@@ -77,15 +128,29 @@ extension TracerStartSpanOps {
77128
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
78129
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
79130
/// - operation: operation to wrap in a span start/end and execute immediately
131+
/// - function: The function name in which the span was started.
132+
/// - fileID: The `fileID` where the span was started.
133+
/// - line: The file line where the span was started.
80134
/// - Returns: the value returned by `operation`
81135
/// - Throws: the error the `operation` has thrown (if any)
82136
public func withSpan<T>(
83137
_ operationName: String,
84138
baggage: Baggage,
85139
ofKind kind: SpanKind = .internal,
140+
function: String = #function,
141+
file fileID: String = #fileID,
142+
line: UInt = #line,
86143
_ operation: (Span) throws -> T
87144
) rethrows -> T {
88-
let span = self.startSpan(operationName, baggage: baggage, ofKind: kind)
145+
let span = self.startSpan(
146+
operationName,
147+
baggage: baggage,
148+
ofKind: kind,
149+
at: .now(),
150+
function: function,
151+
file: fileID,
152+
line: line
153+
)
89154
defer { span.end() }
90155
do {
91156
return try operation(span)
@@ -94,7 +159,7 @@ extension TracerStartSpanOps {
94159
throw error // rethrow
95160
}
96161
}
97-
162+
#else
98163
/// Execute a specific task within a newly created ``Span``.
99164
///
100165
/// DO NOT `end()` the passed in span manually. It will be ended automatically when the `operation` returns.
@@ -104,23 +169,38 @@ extension TracerStartSpanOps {
104169
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
105170
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
106171
/// - operation: operation to wrap in a span start/end and execute immediately
172+
/// - function: The function name in which the span was started.
173+
/// - file: The `#file` where the span was started.
174+
/// - line: The file line where the span was started.
107175
/// - Returns: the value returned by `operation`
108176
/// - Throws: the error the `operation` has thrown (if any)
109177
public func withSpan<T>(
110178
_ operationName: String,
111179
baggage: Baggage,
112180
ofKind kind: SpanKind = .internal,
113-
_ operation: () throws -> T
181+
function: String = #function,
182+
file: String = #file,
183+
line: UInt = #line,
184+
_ operation: (Span) throws -> T
114185
) rethrows -> T {
115-
let span = self.startSpan(operationName, baggage: baggage, ofKind: kind)
186+
let span = self.startSpan(
187+
operationName,
188+
baggage: baggage,
189+
ofKind: kind,
190+
at: .now(),
191+
function: function,
192+
file: file,
193+
line: line
194+
)
116195
defer { span.end() }
117196
do {
118-
return try operation()
197+
return try operation(span)
119198
} catch {
120199
span.recordError(error)
121200
throw error // rethrow
122201
}
123202
}
203+
#endif
124204
}
125205

126206
// ==== ----------------------------------------------------------------------------------------------------------------
@@ -138,14 +218,27 @@ extension TracerStartSpanOps {
138218
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
139219
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
140220
/// - operation: operation to wrap in a span start/end and execute immediately
221+
/// - function: The function name in which the span was started.
222+
/// - fileID: The `fileID` where the span was started.
223+
/// - line: The file line where the span was started.
141224
/// - Returns: the value returned by `operation`
142225
/// - Throws: the error the `operation` has thrown (if any)
143226
public func withSpan<T>(
144227
_ operationName: String,
145228
ofKind kind: SpanKind = .internal,
229+
function: String = #function,
230+
file fileID: String = #fileID,
231+
line: UInt = #line,
146232
_ operation: (Span) throws -> T
147233
) rethrows -> T {
148-
try self.withSpan(operationName, baggage: .current ?? .topLevel, ofKind: kind) { span in
234+
try self.withSpan(
235+
operationName,
236+
baggage: .current ?? .topLevel,
237+
ofKind: kind,
238+
function: function,
239+
file: fileID,
240+
line: line
241+
) { span in
149242
try Baggage.$current.withValue(span.baggage) {
150243
try operation(span)
151244
}
@@ -187,14 +280,27 @@ extension TracerStartSpanOps {
187280
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
188281
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
189282
/// - operation: operation to wrap in a span start/end and execute immediately
283+
/// - function: The function name in which the span was started.
284+
/// - fileID: The `fileID` where the span was started.
285+
/// - line: The file line where the span was started.
190286
/// - Returns: the value returned by `operation`
191287
/// - Throws: the error the `operation` has thrown (if any)
192288
public func withSpan<T>(
193289
_ operationName: String,
194290
ofKind kind: SpanKind = .internal,
291+
function: String = #function,
292+
file fileID: String = #fileID,
293+
line: UInt = #line,
195294
_ operation: (Span) async throws -> T
196295
) async rethrows -> T {
197-
let span = self.startSpan(operationName, baggage: .current ?? .topLevel, ofKind: kind)
296+
let span = self.startSpan(
297+
operationName,
298+
baggage: .current ?? .topLevel,
299+
ofKind: kind,
300+
function: function,
301+
file: fileID,
302+
line: line
303+
)
198304
defer { span.end() }
199305
do {
200306
return try await Baggage.$current.withValue(span.baggage) {
@@ -217,15 +323,21 @@ extension TracerStartSpanOps {
217323
// task local and modified before passing into this function. The baggage will be made the current task-local baggage for the duration of the `operation`.
218324
/// - kind: The `SpanKind` of the `Span` to be created. Defaults to `.internal`.
219325
/// - operation: operation to wrap in a span start/end and execute immediately
326+
/// - function: The function name in which the span was started.
327+
/// - fileID: The `fileID` where the span was started.
328+
/// - line: The file line where the span was started.
220329
/// - Returns: the value returned by `operation`
221330
/// - Throws: the error the `operation` has thrown (if any)
222331
public func withSpan<T>(
223332
_ operationName: String,
224333
baggage: Baggage,
225334
ofKind kind: SpanKind = .internal,
335+
function: String = #function,
336+
file fileID: String = #fileID,
337+
line: UInt = #line,
226338
_ operation: (Span) async throws -> T
227339
) async rethrows -> T {
228-
let span = self.startSpan(operationName, baggage: baggage, ofKind: kind)
340+
let span = self.startSpan(operationName, baggage: baggage, ofKind: kind, function: function, file: fileID, line: line)
229341
defer { span.end() }
230342
do {
231343
return try await Baggage.$current.withValue(span.baggage) {

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LinuxMainRunnerImpl: LinuxMainRunner {
3434
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
3535
func run() {
3636
XCTMain([
37+
testCase(DynamicTracepointTracerTests.allTests),
3738
testCase(InstrumentTests.allTests),
3839
testCase(InstrumentationSystemTests.allTests),
3940
testCase(SpanTests.allTests),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift Distributed Tracing open source project
4+
//
5+
// Copyright (c) 2020-2021 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+
// DynamicTracepointTracerTests+XCTest.swift
16+
//
17+
import XCTest
18+
///
19+
/// NOTE: This file was generated by generate_linux_tests.rb
20+
///
21+
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
22+
///
23+
24+
extension DynamicTracepointTracerTests {
25+
26+
@available(*, deprecated, message: "not actually deprecated. Just deprecated to allow deprecated tests (which test deprecated functionality) without warnings")
27+
static var allTests : [(String, (DynamicTracepointTracerTests) -> () throws -> Void)] {
28+
return [
29+
("test_adhoc_enableBySourceLoc", test_adhoc_enableBySourceLoc),
30+
("test_adhoc_enableByFunction", test_adhoc_enableByFunction),
31+
]
32+
}
33+
}
34+

0 commit comments

Comments
 (0)