Skip to content

More docs on span end() via review #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Sources/Tracing/Span.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,35 @@ public protocol Span: AnyObject {

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

extension Span {
/// End this `Span` at the current timestamp.
///
/// ### Rules about ending Spans
/// A Span must be ended only ONCE. Ending a Span multiple times or never at all is considered a programming error.
///
/// A tracer implementation MAY decide to crash the application if e.g. running in debug mode and noticing such misuse.
///
/// Implementations SHOULD prevent double-emitting by marking a span as ended internally, however it still is a
/// programming mistake to rely on this behavior.
///
/// - Parameter timestamp: The `Timestamp` at which the span ended.
///
/// - 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.
/// 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.
public func end() {
self.end(at: .now())
}
Expand Down