xraysink icon indicating copy to clipboard operation
xraysink copied to clipboard

Support async+thread context propagation in FastAPI

Open garyd203 opened this issue 3 years ago • 0 comments

When FastAPI runs a non-async dependency or handler, it puts it into an internal thread pool so that the async execution doesn't get blocked. I'm pretty sure that the trace context doesn't get propagated into that thread pool (see Sean's problem in #88), which is obviously undesirable. It'd be nice if this worked seamlessly instead.

We probably need a new context (or just extend the existing no-bugs AsyncContext in xraysink) which can hook into FastAPI's specific non-async dispatch in order to add the trace context to those calls. This work could be fairly large!

Possibly related, but probably different piece of work: Support calling an instrumented sync function from async code (eg. see https://github.com/aws/aws-xray-sdk-python/issues/164#issuecomment-1717925072)

https://github.com/encode/starlette/pull/1258 may be a helpful starting point

garyd203 avatar May 24 '22 07:05 garyd203