Skip to content

Support python contextvars based context propagation #931

@aabmass

Description

@aabmass

Based on #903, there is no specific python trace context correlation heuristic. The thread based correlation should work well for traditional WSGI frameworks like Flask and Django but not for asyncio.

Rather than focus on asyncio, I'm wondering if correlation can be done by the builtin contextvars api which provides generic context local storage and is well integrated with asyncio and can be plugged into other concurrency frameworks with context.run(). There is a C API for entering/exiting a context https://docs.python.org/3/c-api/contextvars.html#c.PyContext_Enter.

Let me know if you need more details or it's infeasible. We also use contextvars for the OTel Python context which might make integration with a live SDK feasible.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions