13
13
//===----------------------------------------------------------------------===//
14
14
15
15
import Baggage
16
+ import BaggageLogging
16
17
import Foundation
17
18
import Instrumentation
18
19
import TracingInstrumentation
@@ -232,7 +233,7 @@ public class HTTPClient {
232
233
/// - url: Remote URL.
233
234
/// - context: Baggage context associated with this request
234
235
/// - deadline: Point in time by which the request must complete.
235
- public func get( url: String , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
236
+ public func get( url: String , context: LoggingBaggageContextCarrier , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
236
237
return self . execute ( . GET, url: url, context: context, deadline: deadline)
237
238
}
238
239
@@ -243,7 +244,7 @@ public class HTTPClient {
243
244
/// - context: Baggage context associated with this request
244
245
/// - body: Request body.
245
246
/// - deadline: Point in time by which the request must complete.
246
- public func post( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
247
+ public func post( url: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
247
248
return self . execute ( . POST, url: url, context: context, body: body, deadline: deadline)
248
249
}
249
250
@@ -254,7 +255,7 @@ public class HTTPClient {
254
255
/// - context: Baggage context associated with this request
255
256
/// - body: Request body.
256
257
/// - deadline: Point in time by which the request must complete.
257
- public func patch( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
258
+ public func patch( url: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
258
259
return self . execute ( . PATCH, url: url, context: context, body: body, deadline: deadline)
259
260
}
260
261
@@ -265,7 +266,7 @@ public class HTTPClient {
265
266
/// - context: Baggage context associated with this request
266
267
/// - body: Request body.
267
268
/// - deadline: Point in time by which the request must complete.
268
- public func put( url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
269
+ public func put( url: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
269
270
return self . execute ( . PUT, url: url, context: context, body: body, deadline: deadline)
270
271
}
271
272
@@ -275,7 +276,7 @@ public class HTTPClient {
275
276
/// - url: Remote URL.
276
277
/// - context: Baggage context associated with this request
277
278
/// - deadline: The time when the request must have been completed by.
278
- public func delete( url: String , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
279
+ public func delete( url: String , context: LoggingBaggageContextCarrier , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
279
280
return self . execute ( . DELETE, url: url, context: context, deadline: deadline)
280
281
}
281
282
@@ -287,7 +288,7 @@ public class HTTPClient {
287
288
/// - context: Baggage context associated with this request
288
289
/// - body: Request body.
289
290
/// - deadline: Point in time by which the request must complete.
290
- public func execute( _ method: HTTPMethod = . GET, url: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
291
+ public func execute( _ method: HTTPMethod = . GET, url: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
291
292
do {
292
293
let request = try Request ( url: url, method: method, body: body)
293
294
return self . execute ( request: request, context: context, deadline: deadline)
@@ -305,7 +306,7 @@ public class HTTPClient {
305
306
/// - context: Baggage context associated with this request
306
307
/// - body: Request body.
307
308
/// - deadline: Point in time by which the request must complete.
308
- public func execute( _ method: HTTPMethod = . GET, socketPath: String , urlPath: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
309
+ public func execute( _ method: HTTPMethod = . GET, socketPath: String , urlPath: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
309
310
do {
310
311
guard let url = URL ( httpURLWithSocketPath: socketPath, uri: urlPath) else {
311
312
throw HTTPClientError . invalidURL
@@ -327,7 +328,7 @@ public class HTTPClient {
327
328
/// - body: Request body.
328
329
/// - deadline: Point in time by which the request must complete.
329
330
/// - logger: The logger to use for this request.
330
- public func execute( _ method: HTTPMethod = . GET, secureSocketPath: String , urlPath: String , context: BaggageContext , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
331
+ public func execute( _ method: HTTPMethod = . GET, secureSocketPath: String , urlPath: String , context: LoggingBaggageContextCarrier , body: Body ? = nil , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
331
332
do {
332
333
guard let url = URL ( httpsURLWithSocketPath: secureSocketPath, uri: urlPath) else {
333
334
throw HTTPClientError . invalidURL
@@ -345,7 +346,7 @@ public class HTTPClient {
345
346
/// - request: HTTP request to execute.
346
347
/// - context: Baggage context associated with this request
347
348
/// - deadline: Point in time by which the request must complete.
348
- public func execute( request: Request , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
349
+ public func execute( request: Request , context: LoggingBaggageContextCarrier , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
349
350
let accumulator = ResponseAccumulator ( request: request)
350
351
return self . execute ( request: request, delegate: accumulator, context: context, deadline: deadline) . futureResult
351
352
}
@@ -357,7 +358,7 @@ public class HTTPClient {
357
358
/// - eventLoop: NIO Event Loop preference.
358
359
/// - context: Baggage context associated with this request
359
360
/// - deadline: Point in time by which the request must complete.
360
- public func execute( request: Request , eventLoop: EventLoopPreference , context: BaggageContext , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
361
+ public func execute( request: Request , eventLoop: EventLoopPreference , context: LoggingBaggageContextCarrier , deadline: NIODeadline ? = nil ) -> EventLoopFuture < Response > {
361
362
let accumulator = ResponseAccumulator ( request: request)
362
363
return self . execute ( request: request, delegate: accumulator, eventLoop: eventLoop, context: context, deadline: deadline) . futureResult
363
364
}
@@ -371,7 +372,7 @@ public class HTTPClient {
371
372
/// - deadline: Point in time by which the request must complete.
372
373
public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
373
374
delegate: Delegate ,
374
- context: BaggageContext ,
375
+ context: LoggingBaggageContextCarrier ,
375
376
deadline: NIODeadline ? = nil ) -> Task < Delegate . Response > {
376
377
return self . execute ( request: request, delegate: delegate, eventLoop: . indifferent, context: context, deadline: deadline)
377
378
}
@@ -387,7 +388,7 @@ public class HTTPClient {
387
388
public func execute< Delegate: HTTPClientResponseDelegate > ( request: Request ,
388
389
delegate: Delegate ,
389
390
eventLoop eventLoopPreference: EventLoopPreference ,
390
- context: BaggageContext ,
391
+ context: LoggingBaggageContextCarrier ,
391
392
deadline: NIODeadline ? = nil ) -> Task < Delegate . Response > {
392
393
var span = InstrumentationSystem . tracingInstrument. startSpan ( named: request. method. rawValue, context: context, ofKind: . client, at: nil )
393
394
span. attributes. http. method = request. method. rawValue
@@ -401,10 +402,10 @@ public class HTTPClient {
401
402
// TODO: net.peer.ip / Not required, but recommended
402
403
403
404
var request = request
404
- InstrumentationSystem . instrument. inject ( context, into: & request. headers, using: HTTPHeadersInjector ( ) )
405
+ InstrumentationSystem . instrument. inject ( context. baggage, into: & request. headers, using: HTTPHeadersInjector ( ) )
406
+
407
+ let logger = context. logger. attachingRequestInformation ( request, requestID: globalRequestID. add ( 1 ) )
405
408
406
- // let logger = (originalLogger ?? HTTPClient.loggingDisabled).attachingRequestInformation(request, requestID: globalRequestID.add(1))
407
- let logger = HTTPClient . loggingDisabled
408
409
let taskEL : EventLoop
409
410
switch eventLoopPreference. preference {
410
411
case . indifferent:
@@ -418,16 +419,16 @@ public class HTTPClient {
418
419
case . testOnly_exact( _, delegateOn: let delegateEL) :
419
420
taskEL = delegateEL
420
421
}
421
- // logger.trace("selected EventLoop for task given the preference",
422
- // metadata: ["ahc-eventloop": "\(taskEL)",
423
- // "ahc-el-preference": "\(eventLoopPreference)"])
422
+ logger. trace ( " selected EventLoop for task given the preference " ,
423
+ metadata: [ " ahc-eventloop " : " \( taskEL) " ,
424
+ " ahc-el-preference " : " \( eventLoopPreference) " ] )
424
425
425
426
let failedTask : Task < Delegate . Response > ? = self . stateLock. withLock {
426
427
switch state {
427
428
case . upAndRunning:
428
429
return nil
429
430
case . shuttingDown, . shutDown:
430
- // logger.debug("client is shutting down, failing request")
431
+ logger. debug ( " client is shutting down, failing request " )
431
432
return Task< Delegate . Response> . failedTask( eventLoop: taskEL,
432
433
error: HTTPClientError . alreadyShutdown,
433
434
logger: logger)
0 commit comments