Skip to content

Commit 7a27383

Browse files
authored
fix: Store ended span to reserve parent span context (#2020)
Fix issue #2005 Issue: We introduced the memory leak fix in previous PR to Only store spans that are still active (not already ended), but this had caused side-effect issue when child span cannot find the parent span context. Fix: Partially revert the previous change and keeps (a bit dangerously from memory perspective) all spans from _create_span_for_run even though span already ended. Rely on span TTL (3600 sec by default, configurable). Note: This is like a bandaid unfortunatley. The fundamental fix instead should be a large re-architect of combine_serialized_queue_operations to make sure parent's don't merge _Creation+Update_ until all children has merged and merged children operation should come first to make sure. That's not straightforward and need investment.
1 parent 50064b6 commit 7a27383

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

python/langsmith/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Avoid calling into importlib on every call to __version__
2323

24-
__version__ = "0.4.27"
24+
__version__ = "0.4.28"
2525
version = __version__ # for backwards compatibility
2626

2727

python/langsmith/_internal/otel/_otel_exporter.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,10 @@ def export_batch(
196196
op, run_info, otel_context_map.get(op.id)
197197
)
198198
if span:
199-
# Only store spans that are still active (not already ended)
200-
if hasattr(span, "is_recording") and span.is_recording():
201-
self._span_info[op.id] = {
202-
"span": span,
203-
"created_at": time.time(),
204-
}
205-
logger.debug(
206-
f"Created active span, total: {len(self._span_info)}"
207-
)
208-
else:
209-
# Span ended in _create_span_for_run (had end_time)
210-
logger.debug("completed span (not tracked - already ended)")
199+
self._span_info[op.id] = {
200+
"span": span,
201+
"created_at": time.time(),
202+
}
211203
else:
212204
self._update_span_for_run(op, run_info)
213205
except Exception as e:

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "langsmith"
7-
version = "0.4.27"
7+
version = "0.4.28"
88
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
99
authors = [
1010
{name = "LangChain", email = "[email protected]"},

0 commit comments

Comments
 (0)