Skip to content

Commit fbf54bc

Browse files
ktosoyim-lee
andauthored
More docs on span end() via review (#11)
* review feedback, accept Int64 in attributes * more docs on span end() * Update Sources/Tracing/Span.swift Co-authored-by: Yim Lee <[email protected]> * Update Sources/Tracing/Span.swift Co-authored-by: Yim Lee <[email protected]> Co-authored-by: Yim Lee <[email protected]>
1 parent 92c5f2d commit fbf54bc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Sources/Tracing/Span.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,35 @@ public protocol Span: AnyObject {
4848

4949
/// End this `Span` at the given timestamp.
5050
///
51-
/// Ending a `Span` MUST be idempotent.
51+
/// ### Rules about ending Spans
52+
/// A Span must be ended only ONCE. Ending a Span multiple times or never at all is considered a programming error.
53+
///
54+
/// A tracer implementation MAY decide to crash the application if e.g. running in debug mode and noticing such misuse.
55+
///
56+
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
57+
/// programming mistake to rely on this behavior.
58+
///
5259
/// - Parameter timestamp: The `Timestamp` at which the span ended.
60+
///
61+
/// - SeeAlso: `Span.end()` which automatically uses the "current" time as timestamp.
5362
func end(at timestamp: Timestamp)
5463
}
5564

5665
extension Span {
5766
/// End this `Span` at the current timestamp.
67+
///
68+
/// ### Rules about ending Spans
69+
/// A Span must be ended only ONCE. Ending a Span multiple times or never at all is considered a programming error.
70+
///
71+
/// A tracer implementation MAY decide to crash the application if e.g. running in debug mode and noticing such misuse.
72+
///
73+
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
74+
/// programming mistake to rely on this behavior.
75+
///
76+
/// - Parameter timestamp: The `Timestamp` at which the span ended.
77+
///
78+
/// - SeeAlso: `Span.end(at:)` which allows passing in a specific timestamp, e.g. if the operation was ended and recorded somewhere and we need to post-factum record it.
79+
/// 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.
5880
public func end() {
5981
self.end(at: .now())
6082
}

0 commit comments

Comments
 (0)