-
Notifications
You must be signed in to change notification settings - Fork 2
Design composable Carrier protocols #22
Description
Library authors expressed the wish to use composable Carrier protocol types, so let's explore this.
It is a way to express that a context "has to" provide some values, it is most notably used today for:
- event loop preference
- baggage + logger
We need to be careful with those however...
Libraries SHOULD only expect shared standard carrier types.
Libraries MUST NOT invent their own carrier protocols,
✅
typealias MyLibContext = EventLoopPreferenceCarrier | LoggerCarrier | BaggageCarrier
func get(..., context: MyLibContext)
is ok, because any framework or other library is able to pass its own context:
✅
let context: Lambda.Context
get(..., context: context)
while the following is NOT:
❌
struct MyContext: EventLoopPreferenceCarrier | LoggerCarrier | BaggageCarrier
func get(..., context: MyLibContext)
because it is a real type and thus it is not possible to:
let context: Lambda.Context
get(...: context: oh no)
More notes to be done here...
Please note to NOT USE carriers as general throw everything in there. To be honest I'm also really in love with about the event loop being in the context, as it can absolutely be passed explicitly. Let's discuss this though. There should NOT be more protocols for carriers then a few "really core" things. EventLoops today are everywhere, thus we say it may be okey to specialize those with a carrier as well but we highly suspect those may be going away once a swift concurrency story would unfold?
Frameworks MAY define their own context types when they hand them out to users, but should do their best to accept the widely generic carriers for purposes of tracing and contex propagation without incuring too much noise on end users.
Frameworks SHOULD accept the most general carrier type possible for APIs, specifically for carrying contexts across boundaries -- e.g. "making requests" and IPC calls etc. Otherwise say when "framework specific reasons" are needed then of course passing the framework context is okey.
TODO: this needs more notes and is a rough outcome of a sync up we had with @tanner0101, @tomerd