open-telemetry / open-telemetry/opentelemetry-python-contrib
Use weak reference in langchain instrumentation span map
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
For added safety, src/opentelemetry/instrumentation/langchain/span_manager.py -> self.spans: Dict[UUID, _SpanState] = {} use a WeakMap (assuming the span can be safely garbage collected after LangChain no longer has reference to the UUID object) or some kind of LRU cache for bounded memory.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/opentelemetry/instrumentation/langchain/span_manager.py and inspect how self.spans stores and removes _SpanState entries, including how the UUID is used through the span lifecycle. Determine whether weak references are safe or whether an LRU cache is needed; done means the map no longer grows without bound while retaining state for active spans.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100