mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-05-03 07:32:29 +00:00
8430dd49d4
Co-authored-by: Moritz Lang <16192401+slashmo@users.noreply.github.com> Co-authored-by: George Barnett <gbarnett@apple.com>
42 lines
1.4 KiB
Swift
42 lines
1.4 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the AsyncHTTPClient open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIOHTTP1
|
|
import Tracing
|
|
|
|
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
|
extension HTTPClient {
|
|
@inlinable
|
|
func withRequestSpan(
|
|
_ request: HTTPClientRequest,
|
|
_ body: () async throws -> HTTPClientResponse
|
|
) async rethrows -> HTTPClientResponse {
|
|
guard let tracer = self.tracer else {
|
|
return try await body()
|
|
}
|
|
|
|
return try await tracer.withSpan(request.method.rawValue, ofKind: .client) { span in
|
|
let keys = self.configuration.tracing.attributeKeys
|
|
span.attributes[keys.requestMethod] = request.method.rawValue
|
|
// TODO: set more attributes on the span
|
|
let response = try await body()
|
|
|
|
// set response span attributes
|
|
TracingSupport.handleResponseStatusCode(span, response.status, keys: tracing.attributeKeys)
|
|
|
|
return response
|
|
}
|
|
}
|
|
}
|