Skip to content

Commit

Permalink
Add recordingSpan and currentSpan methods to TracerProtocol (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
slashmo authored Jan 14, 2025
1 parent 0b9ab66 commit a64a0ab
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/Tracing/TracerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public protocol Tracer: LegacyTracer {
file fileID: String,
line: UInt
) -> Self.Span

/// Retrieve the recording span for the given `ServiceContext`.
///
/// - Note: This API does not enable look up of already finished spans.
/// It was added retroactively with a default implementation returning `nil` and therefore isn't guaranteed to be implemented by all `Tracer`s.
/// - Parameter context: The context containing information that uniquely identifies the span being obtained.
/// - Returns: The span identified by the given `ServiceContext` in case it's still recording.
func activeSpan(identifiedBy context: ServiceContext) -> Span?
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
Expand Down Expand Up @@ -106,6 +114,15 @@ extension Tracer {
line: line
)
}

/// Default implementation for ``activeSpan(identifiedBy:)`` which always returns `nil`.
/// This default exists in order to facilitate source-compatible introduction of the ``activeSpan(identifiedBy:)`` protocol requirement.
///
/// - Parameter context: The context containing information that uniquely identifies the span being obtained.
/// - Returns: `nil`.
public func activeSpan(identifiedBy context: ServiceContext) -> Span? {
nil
}
}

// ==== ----------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit a64a0ab

Please sign in to comment.