Skip to content

Commit 714771f

Browse files
committed
Add recordError method to Span
Use default Equatable conformance for SpanEvent
1 parent cd6c007 commit 714771f

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Sources/TracingInstrumentation/NoOpTracingInstrument.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public struct NoOpTracingInstrument: TracingInstrument {
5454

5555
public mutating func addEvent(_ event: SpanEvent) {}
5656

57+
public func recordError(_ error: Error) {}
58+
5759
public var attributes: SpanAttributes {
5860
get {
5961
[:]

Sources/TracingInstrumentation/Span.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public protocol Span {
4141
/// - Parameter event: The `SpanEvent` to add to this `Span`.
4242
mutating func addEvent(_ event: SpanEvent)
4343

44+
/// Record an error of the given type described by the the given message.
45+
///
46+
/// - Parameters:
47+
/// - error: The error to be recorded.
48+
mutating func recordError(_ error: Error)
49+
4450
/// The attributes describing this `Span`.
4551
var attributes: SpanAttributes { get set }
4652

@@ -83,7 +89,7 @@ extension Span {
8389
// MARK: Span Event
8490

8591
/// An event that occurred during a `Span`.
86-
public struct SpanEvent {
92+
public struct SpanEvent: Equatable {
8793
/// The human-readable name of this `SpanEvent`.
8894
public let name: String
8995

@@ -299,7 +305,7 @@ extension SpanAttribute: ExpressibleByArrayLiteral {
299305

300306
/// A collection of `SpanAttribute`s.
301307
@dynamicMemberLookup
302-
public struct SpanAttributes {
308+
public struct SpanAttributes: Equatable {
303309
private var _attributes = [String: SpanAttribute]()
304310

305311
/// Create a set of attributes by wrapping the given dictionary.

Tests/TracingInstrumentationTests/TracedLockTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ private final class TracedLockPrintlnTracer: TracingInstrument {
131131
self.events.append(event)
132132
}
133133

134+
func recordError(_ error: Error) {}
135+
134136
mutating func end(at timestamp: Timestamp) {
135137
self.endTimestamp = timestamp
136138
print(" span [\(self.operationName): \(self.context[TaskIDKey.self] ?? "no-name")] @ \(timestamp): end")

Tests/TracingInstrumentationTests/TracingInstrumentTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ struct TestSpan: Span {
168168
self.events.append(event)
169169
}
170170

171+
func recordError(_ error: Error) {}
172+
171173
mutating func end(at timestamp: Timestamp) {
172174
self.endTimestamp = timestamp
173175
self.onEnd(self)

0 commit comments

Comments
 (0)