slashmo / gsoc-swift-baggage-context

BaggageContext library, extracted from slashmo/gsoc-swift-tracing
https://github.com/slashmo/gsoc-swift-tracing
Apache License 2.0
4 stars 2 forks source link

Final API proposal - Baggage + Context #34

Closed ktoso closed 3 years ago

ktoso commented 3 years ago

This is a large PR, but in it I hope to finalize the API of this package.

It first and foremost acknowledges issues that we all felt already with the Carrier design -- it's too "wide open" and by being such, it actually hurts composability of libraries.


Short discussion:

In general we need to balance a number of needs here:

As such I propose the following simplification of the APIs:

Modules & Types

The package: swift-context

The baggage module:

The only user of this I really see being NIO, the team said it would not want to depend on SwiftLog.

And finally, tieing logging and context together in:

We also offer:

and

There are NO other types. The EventLoop we really tried hard to find a place for but we quickly devolve into complexities of various libraries wanting to accept or not wanting to accept it etc. The "...Carriers" design falls flat #28 on delivering good compositionality, in general remaining true to the:

Liberties constrain, constraints liberate.

In this proposal we choose MORE constraints what a context and baggage is, and thus end up with a more composable API.

The short version is:

Optional:

And finally:


As framework author e.g. "http server" or similar, where a widely used context object exists that holds many many values already (e.g. Vapor, Lambda Runtime)

As library author of a library which does not have it's own "context" and/or is mostly a client e.g. HTTPClient:

As library/framework user



The code is mostly "shuffling around" and naming, and making sure everything "fits".

The general "what is possible to express" remains the same and wider -- I made sure this will fit existing context types such as Vapor, soco (AWSSDK), NIO, HTTPClient, Redis. Yes, it does mean passing the event loop explicitly and I really can't find a truely good way to solve it. We end up in arbitrarily tying things together which should not be together if we try to do so.

Please have a look everyone: @adam-fowler @tomerd @lukasa @slashmo @fabianfett @tanner0101 @pokryfka

tomerd commented 3 years ago

over much nicer and clearer. some clarification question and feedback inline.

Mordil commented 3 years ago

Other than my latest comment, I think I'm on board with this PR 💯

ktoso commented 3 years ago

Thank you for your time and reviews @Mordil !

ktoso commented 3 years ago

Thank you everyone on this PR and privately and internally for the feedback, I really feel we're on the last few adjustments to the API and we'll be able to call if final!

Changes in this batch:

This has large (good for applications which log a lot) performance implications which can be seen here (and in the benchmarks added in https://github.com/slashmo/gsoc-swift-baggage-context/pull/34/commits/f0f91b7ae22f38fcc99ebd164724d7573338a2fc):

Screen Shot 2020-09-18 at 18 17 27

Next up:

ktoso commented 3 years ago

All things applied...

I also looked at @adam-fowler's adoption inside Soco and other projects and am confident we've arrived at something very good.

We're aiming to settle down the discussions this week and being the new repos shortly. Thank you everyone for your patience and reviews, hopefully we're "done" here soon.

ktoso commented 3 years ago

I'm waiting for some feedback from the SPM team about the package structure, once I get that I think we're ready to go here. Planning to land this end of this week.

ktoso commented 3 years ago

Okey folks, so it seems we'll need two repositories.

The exact package and module naming we have to run through some reviews... Until then I'd like to merge this so we're out of the limbo on the types themselves :-)