Skip to content

fix(sdk): add max_spans limit to InMemorySpanExporter#5296

Merged
xrmx merged 7 commits into
open-telemetry:mainfrom
shayannab:fix/in-memory-span-exporter-max-spans
Jul 10, 2026
Merged

fix(sdk): add max_spans limit to InMemorySpanExporter#5296
xrmx merged 7 commits into
open-telemetry:mainfrom
shayannab:fix/in-memory-span-exporter-max-spans

Conversation

@shayannab

Copy link
Copy Markdown
Contributor

Description

InMemorySpanExporter currently stores all spans in an unbounded list,
which can cause memory issues in long-running test environments or
production debug scenarios.

This PR adds an optional max_spans parameter to __init__. When set,
the internal storage uses collections.deque(maxlen=max_spans) which
automatically drops the oldest spans when the limit is reached. Default
is None (no limit), so existing behaviour is fully preserved.

Fixes #5281

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Ran the existing test suite plus two new tests via tox:
tox -e py312-test-opentelemetry-sdk -- tests/trace/export/test_in_memory_span_exporter.py

  • test_max_spans_limit — verifies oldest spans are dropped when limit is reached
  • test_max_spans_none_is_unlimited — verifies default behaviour is unchanged

@shayannab shayannab requested a review from a team as a code owner June 12, 2026 07:52
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 12, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: shayannab / name: shayannab (c11f724)

…SpanExporter

- Update InMemorySpanExporter type hint from typing.Optional[int] to int | None.
- Refactor test_max_spans_limit to test distinct spans and assert order.
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jul 5, 2026
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/trace/export/in_memory_span_exporter.py Outdated
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Jul 9, 2026
@github-actions github-actions Bot removed the Stale label Jul 10, 2026
@xrmx xrmx enabled auto-merge July 10, 2026 07:52
@xrmx xrmx moved this from Approved PRs to Ready for merge in Python PR digest Jul 10, 2026
@xrmx xrmx added this pull request to the merge queue Jul 10, 2026
Merged via the queue into open-telemetry:main with commit 08322fd Jul 10, 2026
545 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for merge to Done in Python PR digest Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add max_spans limit to InMemorySpanExporter to prevent unbounded memory growth

3 participants