Replace FTNetworkTracer with observer middleware#110
Conversation
…ware - Remove hard dependency on FTNetworkTracer package - Introduce NetworkObserver protocol with type-safe associated Context - Support array of middlewares for multiple observers - Zero overhead when no observers configured (empty array = no work) - Use RequestToken pattern for type erasure while preserving type safety Breaking change: `networkTracer: FTNetworkTracer?` replaced with `networkObservers: [any NetworkObserver]`
Explicitly document that `didReceiveResponse` is always invoked with raw data, and `didFail` is an additional callback for errors occurring after the response is received. Update tests to assert this behavior.
72cbaaa to
87b0bb2
Compare
Looks much better. I do not understand the need for the context and generating artificial request ID. This could be handled by using |
Thanks for the feedback and for pointing me to URLSessionTaskMetrics - I wasn't familiar with that API before. On Context and request ID: On URLSessionTaskMetrics: |
Refactor network observation mechanism from a single tracer to a flexible observer protocol. This change replaces the concrete
FTNetworkTracerdependency with a newNetworkObserverprotocol, allowing for multiple custom observers. TheURLServernow supports an array of observers that receive lifecycle callbacks for each request.Key Features:
FTNetworkTracerdependency with a protocol-orientedNetworkObserver, enhancing flexibility and extensibility.URLServernow manages an array ofNetworkObserverinstances, enabling different modules to independently observe network events.NetworkObserverprotocol uses anassociatedtype Contextto pass correlation data (e.g., request ID, start time) betweenwillSendRequestand subsequent completion callbacks.NetworkObserverTestsand aMockNetworkObserverdemonstrate better test isolation and clarity.Package.swift: Removed the external dependency onFTNetworkTracer.Changes Summary:
FTNetworkTracer?[any NetworkObserver]FTNetworkTracerNetworkObserverprotocolrequestId,startTimeassociatedtype Contextmanaged by observerNetworkTracerIntegrationTests(deleted)NetworkObserverTests(new)