open-telemetry / open-telemetry/opentelemetry-python-contrib

Use weak reference in langchain instrumentation span map

Open
#3,735 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.