From 7965574dc96e649a891ec0738e1dee8d1cc3b988 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Thu, 18 Dec 2025 13:35:47 +0000 Subject: [PATCH 1/2] Add updateAttributes as Span protocol requirement --- .gitignore | 1 + Sources/Tracing/NoOpTracer.swift | 7 +++++++ Sources/Tracing/SpanProtocol.swift | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/.gitignore b/.gitignore index e613a742..71707ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ xcuserdata/ .swiftpm /Package.resolved +.vscode/ \ No newline at end of file diff --git a/Sources/Tracing/NoOpTracer.swift b/Sources/Tracing/NoOpTracer.swift index e270051c..c0c01e09 100644 --- a/Sources/Tracing/NoOpTracer.swift +++ b/Sources/Tracing/NoOpTracer.swift @@ -139,6 +139,13 @@ public struct NoOpTracer: LegacyTracer { } } + + /// Update the span attributes in a block instead of individually. + /// + /// The NoOpSpan implementation does not call the closure as setting attributes + /// on a NoOpSpan does nothing. + public func updateAttributes(_ update: (inout SpanAttributes) -> Void) {} + /// Finishes the span. /// - Parameter instant: the time instant the span completed. public func end(at instant: @autoclosure () -> Instant) { diff --git a/Sources/Tracing/SpanProtocol.swift b/Sources/Tracing/SpanProtocol.swift index 275fa2fc..f05f4998 100644 --- a/Sources/Tracing/SpanProtocol.swift +++ b/Sources/Tracing/SpanProtocol.swift @@ -92,6 +92,17 @@ public protocol Span: Sendable { nonmutating set } + /// Update the span attributes in a block instead of individually. + /// + /// Updating a span attribute involves some type of thread synchronisation + /// primitive to avoid multiple threads updating the attributes at the same + /// time. If you update each attribute individually, this can cause slowdown. + /// This function updates the attributes in one call to avoid hitting the + /// thread synchronisation code multiple times. + /// + /// - Parameter update: closure used to update span attributes + func updateAttributes(_ update: (inout SpanAttributes) -> Void) + /// A Boolean value that indicates whether the span is recording information such as events, attributes, status, and so on. var isRecording: Bool { get } From ca14bdec80f9053600714d2f5bf4fafda3c4850e Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Fri, 19 Dec 2025 11:58:59 +0900 Subject: [PATCH 2/2] fix formatting --- Sources/Tracing/NoOpTracer.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Tracing/NoOpTracer.swift b/Sources/Tracing/NoOpTracer.swift index c0c01e09..4b108290 100644 --- a/Sources/Tracing/NoOpTracer.swift +++ b/Sources/Tracing/NoOpTracer.swift @@ -139,9 +139,8 @@ public struct NoOpTracer: LegacyTracer { } } - /// Update the span attributes in a block instead of individually. - /// + /// /// The NoOpSpan implementation does not call the closure as setting attributes /// on a NoOpSpan does nothing. public func updateAttributes(_ update: (inout SpanAttributes) -> Void) {}