Skip to content

Commit a64a0ab

Browse files
authored
Add recordingSpan and currentSpan methods to TracerProtocol (#160)
1 parent 0b9ab66 commit a64a0ab

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sources/Tracing/TracerProtocol.swift

+17
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public protocol Tracer: LegacyTracer {
5959
file fileID: String,
6060
line: UInt
6161
) -> Self.Span
62+
63+
/// Retrieve the recording span for the given `ServiceContext`.
64+
///
65+
/// - Note: This API does not enable look up of already finished spans.
66+
/// It was added retroactively with a default implementation returning `nil` and therefore isn't guaranteed to be implemented by all `Tracer`s.
67+
/// - Parameter context: The context containing information that uniquely identifies the span being obtained.
68+
/// - Returns: The span identified by the given `ServiceContext` in case it's still recording.
69+
func activeSpan(identifiedBy context: ServiceContext) -> Span?
6270
}
6371

6472
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) // for TaskLocal ServiceContext
@@ -106,6 +114,15 @@ extension Tracer {
106114
line: line
107115
)
108116
}
117+
118+
/// Default implementation for ``activeSpan(identifiedBy:)`` which always returns `nil`.
119+
/// This default exists in order to facilitate source-compatible introduction of the ``activeSpan(identifiedBy:)`` protocol requirement.
120+
///
121+
/// - Parameter context: The context containing information that uniquely identifies the span being obtained.
122+
/// - Returns: `nil`.
123+
public func activeSpan(identifiedBy context: ServiceContext) -> Span? {
124+
nil
125+
}
109126
}
110127

111128
// ==== ----------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)