You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is introducing multiple layers of nesting, and we have un-necessarily restored, picked-up, and restored the context again. In order to avoid this duplicate work, it is beneficial to use the ``withSpan(_:context:ofKind:at:function:file:line:_:)-4o2b`` overload, which also accepts a `ServiceContext` as parameter, rather than picking it up from the task-local value:
241
+
This is introducing multiple layers of nesting, and we have un-necessarily restored, picked-up, and restored the context again. In order to avoid this duplicate work, it is beneficial to use the ``withSpan(_:context:ofKind:at:function:file:line:_:)-8gw3v`` overload, which also accepts a `ServiceContext` as parameter, rather than picking it up from the task-local value:
242
242
243
243
```swift
244
244
// BETTER
@@ -257,7 +257,7 @@ This method will only restore the context once, after the tracer has had a chanc
257
257
258
258
#### Manual Span Lifetime Management
259
259
260
-
While the ``withSpan(_:context:ofKind:at:function:file:line:_:)-4o2b`` API is preferable in most situations, it may not be possible to use when the lifetime of a span only terminates in yet another callback API. In such situations, it may be impossible to "wrap" the entire piece of code that would logically represent "the span" using a `withSpan(...) { ... }` call.
260
+
While the ``withSpan(_:context:ofKind:at:function:file:line:_:)-8gw3v`` API is preferable in most situations, it may not be possible to use when the lifetime of a span only terminates in yet another callback API. In such situations, it may be impossible to "wrap" the entire piece of code that would logically represent "the span" using a `withSpan(...) { ... }` call.
261
261
262
262
In such situations you can resort to using the ``startSpan(_:context:ofKind:at:function:file:line:)`` and ``Span/end()`` APIs explicitly. Those APIs can then be used like this:
Copy file name to clipboardExpand all lines: Sources/Tracing/Docs.docc/Guides/TraceYourApplication.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -258,7 +258,7 @@ This was just a quick introduction to tracing, but hopefully you are now excited
258
258
259
259
### Efficiently working with Spans
260
260
261
-
We already saw the basic API to spawn a trace span, the ``withSpan(_:context:ofKind:at:function:file:line:_:)-4o2b`` method, but we didn't discuss it in depth yet. In this section we'll discuss how to efficiently work with spans and some common patterns and practices.
261
+
We already saw the basic API to spawn a trace span, the ``withSpan(_:context:ofKind:at:function:file:line:_:)-8gw3v`` method, but we didn't discuss it in depth yet. In this section we'll discuss how to efficiently work with spans and some common patterns and practices.
262
262
263
263
Firstly, spans are created using a `withSpan` call and performing the operation contained within the span in the trailing operation closure body. This is important because it automatically, and correctly, delimits the lifetime of the span: from its creation, until the operation closure returns:
Copy file name to clipboardExpand all lines: Sources/Tracing/SpanProtocol.swift
+1-1
Original file line number
Diff line number
Diff line change
@@ -136,7 +136,7 @@ extension Span {
136
136
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
137
137
/// programming mistake to rely on this behavior.
138
138
///
139
-
/// - SeeAlso: ``end(clock:)`` which allows passing in a specific time, e.g. if the operation was ended and recorded somewhere and we need to post-factum record it.
139
+
/// - SeeAlso: ``end(at:)`` which allows passing in a specific time, e.g. if the operation was ended and recorded somewhere and we need to post-factum record it.
140
140
/// Generally though prefer using the ``end()`` version of this API in user code and structure your system such that it can be called in the right place and time.
0 commit comments