Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+tracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ extension HTTPClient {
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

// set url attributes
if let deconstructedURL = try? DeconstructedURL(url: request.url) {
span.attributes[keys.urlScheme] = deconstructedURL.scheme.rawValue
span.attributes[keys.urlPath] = deconstructedURL.uri
span.attributes[keys.serverHostname] = deconstructedURL.connectionTarget.host
span.attributes[keys.serverPort] = deconstructedURL.connectionTarget.port
}

let response = try await body()

// set response span attributes
TracingSupport.handleResponseStatusCode(span, response.status, keys: tracing.attributeKeys)

// set network protocol version
span.attributes[keys.networkProtocolVersion] = "\(response.version.major).\(response.version.minor)"

return response
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/AsyncHTTPClient/ConnectionTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import enum NIOCore.SocketAddress

enum ConnectionTarget: Equatable, Hashable {
@usableFromInline
enum ConnectionTarget: Equatable, Hashable, Sendable {
// We keep the IP address serialization precisely as it is in the URL.
// Some platforms have quirks in their implementations of 'ntop', for example
// writing IPv6 addresses as having embedded IPv4 sections (e.g. [::192.168.0.1] vs [::c0a8:1]).
Expand Down Expand Up @@ -44,6 +45,7 @@ enum ConnectionTarget: Equatable, Hashable {
extension ConnectionTarget {
/// The host name which will be send as an HTTP `Host` header.
/// Only returns nil if the `self` is a `unixSocket`.
@usableFromInline
var host: String? {
switch self {
case .ipAddress(let serialization, _): return serialization
Expand All @@ -54,6 +56,7 @@ extension ConnectionTarget {

/// The host name which will be send as an HTTP host header.
/// Only returns nil if the `self` is a `unixSocket`.
@usableFromInline
var port: Int? {
switch self {
case .ipAddress(_, let address): return address.port!
Expand Down
8 changes: 7 additions & 1 deletion Sources/AsyncHTTPClient/DeconstructedURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@

import struct Foundation.URL

struct DeconstructedURL {
@usableFromInline
struct DeconstructedURL: Sendable {
@usableFromInline
var scheme: Scheme
@usableFromInline
var connectionTarget: ConnectionTarget
@usableFromInline
var uri: String

@usableFromInline
init(
scheme: Scheme,
connectionTarget: ConnectionTarget,
Expand All @@ -31,6 +36,7 @@ struct DeconstructedURL {
}

extension DeconstructedURL {
@usableFromInline
init(url: String) throws {
guard let url = URL(string: url) else {
throw HTTPClientError.invalidURL
Expand Down
10 changes: 9 additions & 1 deletion Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,15 @@ public final class HTTPClient: Sendable {
@usableFromInline package var requestBodySize: String = "http.request.body.size"

@usableFromInline package var responseBodySize: String = "http.response.body.size"
@usableFromInline package var responseStatusCode: String = "http.status_code"
@usableFromInline package var responseStatusCode: String = "http.response.status_code"

@usableFromInline package var networkProtocolVersion: String = "network.protocol.version"

@usableFromInline package var urlPath: String = "url.path"
@usableFromInline package var urlScheme: String = "url.scheme"

@usableFromInline package var serverHostname: String = "server.hostname"
@usableFromInline package var serverPort: String = "server.port"
Comment thread
fabianfett marked this conversation as resolved.

@usableFromInline package var httpFlavor: String = "http.flavor"

Expand Down
3 changes: 2 additions & 1 deletion Sources/AsyncHTTPClient/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
//===----------------------------------------------------------------------===//

/// List of schemes `HTTPClient` currently supports
enum Scheme: String {
@usableFromInline
enum Scheme: String, Sendable {
case http
case https
case unix
Expand Down