@@ -30,13 +30,15 @@ public protocol Tracer: Instrument {
30
30
/// - baggage: The `Baggage` providing information on where to start the new ``Span``.
31
31
/// - kind: The ``SpanKind`` of the new ``Span``.
32
32
/// - time: The `DispatchTime` at which to start the new ``Span``.
33
- /// - file: The `fileID` where the span was started.
33
+ /// - function: The function name in which the span was started
34
+ /// - fileID: The `fileID` where the span was started.
34
35
/// - line: The file line where the span was started.
35
36
func startSpan(
36
37
_ operationName: String ,
37
38
baggage: Baggage ,
38
39
ofKind kind: SpanKind ,
39
40
at time: DispatchWallTime ,
41
+ function: String ,
40
42
file fileID: String ,
41
43
line: UInt
42
44
) -> Span
@@ -57,14 +59,19 @@ extension Tracer {
57
59
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
58
60
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
59
61
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
62
+ /// - function: The function name in which the span was started
63
+ /// - fileID: The `fileID` where the span was started.
64
+ /// - line: The file line where the span was started.
60
65
public func startSpan(
61
66
_ operationName: String ,
62
67
baggage: Baggage ,
63
68
ofKind kind: SpanKind = . internal,
69
+ function: String = #function,
64
70
file fileID: String = #fileID,
65
71
line: UInt = #line
66
72
) -> Span {
67
- self . startSpan ( operationName, baggage: baggage, ofKind: kind, at: . now( ) , file: fileID, line: line)
73
+ self . startSpan ( operationName, baggage: baggage, ofKind: kind, at: . now( ) ,
74
+ function: function, file: fileID, line: line)
68
75
}
69
76
}
70
77
@@ -81,17 +88,22 @@ extension Tracer {
81
88
/// - baggage: Baggage potentially containing trace identifiers of a parent ``Span``.
82
89
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
83
90
/// - operation: operation to wrap in a span start/end and execute immediately
91
+ /// - function: The function name in which the span was started
92
+ /// - fileID: The `fileID` where the span was started.
93
+ /// - line: The file line where the span was started.
84
94
/// - Returns: the value returned by `operation`
85
95
/// - Throws: the error the `operation` has thrown (if any)
86
96
public func withSpan< T> (
87
97
_ operationName: String ,
88
98
baggage: Baggage ,
89
99
ofKind kind: SpanKind = . internal,
100
+ function: String = #function,
90
101
file fileID: String = #fileID,
91
102
line: UInt = #line,
92
103
_ operation: ( Span ) throws -> T
93
104
) rethrows -> T {
94
- let span = self . startSpan ( operationName, baggage: baggage, ofKind: kind, at: . now( ) , file: fileID, line: line)
105
+ let span = self . startSpan ( operationName, baggage: baggage, ofKind: kind, at: . now( ) ,
106
+ function: function, file: fileID, line: line)
95
107
defer { span. end ( ) }
96
108
do {
97
109
return try operation ( span)
@@ -117,16 +129,21 @@ extension Tracer {
117
129
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
118
130
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
119
131
/// - operation: operation to wrap in a span start/end and execute immediately
132
+ /// - function: The function name in which the span was started
133
+ /// - fileID: The `fileID` where the span was started.
134
+ /// - line: The file line where the span was started.
120
135
/// - Returns: the value returned by `operation`
121
136
/// - Throws: the error the `operation` has thrown (if any)
122
137
public func withSpan< T> (
123
138
_ operationName: String ,
124
139
ofKind kind: SpanKind = . internal,
140
+ function: String = #function,
125
141
file fileID: String = #fileID,
126
142
line: UInt = #line,
127
143
_ operation: ( Span ) throws -> T
128
144
) rethrows -> T {
129
- try self . withSpan ( operationName, baggage: . current ?? . topLevel, ofKind: kind, file: fileID, line: line) { span in
145
+ try self . withSpan ( operationName, baggage: . current ?? . topLevel, ofKind: kind,
146
+ function: function, file: fileID, line: line) { span in
130
147
try Baggage . $current. withValue ( span. baggage) {
131
148
try operation ( span)
132
149
}
@@ -142,16 +159,21 @@ extension Tracer {
142
159
/// - operationName: The name of the operation being traced. This may be a handler function, database call, ...
143
160
/// - kind: The ``SpanKind`` of the ``Span`` to be created. Defaults to ``SpanKind/internal``.
144
161
/// - operation: operation to wrap in a span start/end and execute immediately
162
+ /// - function: The function name in which the span was started
163
+ /// - fileID: The `fileID` where the span was started.
164
+ /// - line: The file line where the span was started.
145
165
/// - Returns: the value returned by `operation`
146
166
/// - Throws: the error the `operation` has thrown (if any)
147
167
public func withSpan< T> (
148
168
_ operationName: String ,
149
169
ofKind kind: SpanKind = . internal,
170
+ function: String = #function,
150
171
file fileID: String = #fileID,
151
172
line: UInt = #line,
152
173
_ operation: ( Span ) async throws -> T
153
174
) async rethrows -> T {
154
- let span = self . startSpan ( operationName, baggage: . current ?? . topLevel, ofKind: kind, file: fileID, line: line)
175
+ let span = self . startSpan ( operationName, baggage: . current ?? . topLevel, ofKind: kind,
176
+ function: function, file: fileID, line: line)
155
177
defer { span. end ( ) }
156
178
do {
157
179
return try await Baggage . $current. withValue ( span. baggage) {
@@ -174,17 +196,21 @@ extension Tracer {
174
196
// 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`.
175
197
/// - kind: The `SpanKind` of the `Span` to be created. Defaults to `.internal`.
176
198
/// - operation: operation to wrap in a span start/end and execute immediately
199
+ /// - function: The function name in which the span was started
200
+ /// - fileID: The `fileID` where the span was started.
201
+ /// - line: The file line where the span was started.
177
202
/// - Returns: the value returned by `operation`
178
203
/// - Throws: the error the `operation` has thrown (if any)
179
204
public func withSpan< T> (
180
205
_ operationName: String ,
181
206
baggage: Baggage ,
182
207
ofKind kind: SpanKind = . internal,
208
+ function: String = #function,
183
209
file fileID: String = #fileID,
184
210
line: UInt = #line,
185
211
_ operation: ( Span ) async throws -> T
186
212
) async rethrows -> T {
187
- let span = self . startSpan ( operationName, baggage: baggage, ofKind: kind, file: fileID, line: line)
213
+ let span = self . startSpan ( operationName, baggage: baggage, ofKind: kind, function : function , file: fileID, line: line)
188
214
defer { span. end ( ) }
189
215
do {
190
216
return try await Baggage . $current. withValue ( span. baggage) {
0 commit comments