Skip to content

Commit 7a41c20

Browse files
authored
Use Span.updateAttributes from swift-distributed-tracing (#646)
1 parent 507c56e commit 7a41c20

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"),
2525
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
2626
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.5.0"),
27-
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.0.1"),
27+
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.1.0"),
2828
.package(url: "https://github.com/apple/swift-nio.git", from: "2.63.0"),
2929
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.20.0"),
3030
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.34.1"),

Sources/Hummingbird/Middleware/TracingMiddleware.swift

+1-18
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public struct TracingMiddleware<Context: RequestContext>: RouterMiddleware {
5151
// span name is updated after route has run
5252
let operationName = "HTTP \(request.method.rawValue) route not found"
5353

54-
let span = InstrumentationSystem.tracer.startSpan(operationName, context: serviceContext, ofKind: .server)
54+
let span = startSpan(operationName, context: serviceContext, ofKind: .server)
5555
span.updateAttributes { attributes in
5656
if let staticAttributes = self.attributes {
5757
attributes.merge(staticAttributes)
@@ -176,20 +176,3 @@ private struct HTTPHeadersExtractor: Extractor {
176176
return headers[headerName]
177177
}
178178
}
179-
180-
extension Span {
181-
/// Update Span attributes in a block instead of individually
182-
///
183-
/// Updating a span attribute will involve some type of thread synchronisation
184-
/// primitive to avoid multiple threads updating the attributes at the same
185-
/// time. If you update each attributes individually this could cause slowdown.
186-
/// This function updates the attributes in one call to avoid hitting the
187-
/// thread synchronisation code multiple times
188-
///
189-
/// - Parameter update: closure used to update span attributes
190-
func updateAttributes(_ update: (inout SpanAttributes) -> Void) {
191-
var attributes = self.attributes
192-
update(&attributes)
193-
self.attributes = attributes
194-
}
195-
}

0 commit comments

Comments
 (0)