Skip to content

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

Open
shayannab wants to merge 1 commit into
open-telemetry:mainfrom
shayannab:fix/in-memory-span-exporter-max-spans
Open

fix(sdk): add max_spans limit to InMemorySpanExporter#5296
shayannab wants to merge 1 commit into
open-telemetry:mainfrom
shayannab:fix/in-memory-span-exporter-max-spans

Conversation

@shayannab

Copy link
Copy Markdown

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add max_spans limit to InMemorySpanExporter to prevent unbounded memory growth

1 participant