snok / asgi-correlation-id

Request ID propagation for ASGI apps
MIT License
369 stars 29 forks source link

Support for Litestar #83

Open jeanlst opened 5 months ago

jeanlst commented 5 months ago

Hello,

Great lib! I have been using it for a while with FastAPI but I have changed to using Litestar now. It apparently works out of the box but would you be able to add official support to it?

Litestar expects this type: Middleware: TypeAlias = "Union[Callable[..., ASGIApp], DefineMiddleware, Iterator[Tuple[ASGIApp, Dict[str, Any]]], Type[MiddlewareProtocol]]" meanwhile I'm passing 'Type[CorrelationIdMiddleware]'

Thank you!

sondrelg commented 5 months ago

I don't follow, could you please elaborate a little?

jeanlst commented 5 months ago

Sorry, I guess it does work out of the box! https://docs.litestar.dev/latest/migration/fastapi.html#middleware It's just the type hinting that's not working

euri10 commented 5 months ago

I think it goes along with this question https://github.com/snok/asgi-correlation-id/discussions/16

Currently the project is 99% asgi middleware in the sense it has a Starlette dependency for the headers iirc, and the types used come also from there.

If I get it correctly, removing that dependency would make it 100% compatible with all asgi frameworks, be it Litestar or Blacksheep or all the other amazing ones I don't know about :)

sondrelg commented 5 months ago

A PR is welcome 👍