Files
Konrad `ktoso` Malawski 8430dd49d4 Introduce built-in swift-distributed-tracing support (#857)
Co-authored-by: Moritz Lang <16192401+slashmo@users.noreply.github.com>
Co-authored-by: George Barnett <gbarnett@apple.com>
2025-10-07 16:30:31 +09:00

54 lines
1.5 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 Logging
import NIOConcurrencyHelpers
import NIOCore
import NIOHTTP1
import NIOSSL
import Tracing
// MARK: - Centralized span attribute handling
@usableFromInline
struct TracingSupport {
@inlinable
static func handleResponseStatusCode(
_ span: Span,
_ status: HTTPResponseStatus,
keys: HTTPClient.TracingConfiguration.AttributeKeys
) {
if status.code >= 400 {
span.setStatus(.init(code: .error))
}
span.attributes[keys.responseStatusCode] = SpanAttribute.int64(Int64(status.code))
}
}
// MARK: - HTTPHeadersInjector
struct HTTPHeadersInjector: Injector, @unchecked Sendable {
static let shared: HTTPHeadersInjector = HTTPHeadersInjector()
private init() {}
func inject(_ value: String, forKey name: String, into headers: inout HTTPHeaders) {
headers.add(name: name, value: value)
}
}
// MARK: - Errors
internal struct HTTPRequestCancellationError: Error {}