Skip to content

fix: prevent shared mutable defaults for span attributes and events - #909

Merged
CagriYonca merged 1 commit into
mainfrom
fix-events
Oct 2, 2026
Merged

CagriYonca merged 1 commit into
mainfrom
fix-events

Conversation

@CagriYonca

Copy link
Copy Markdown
Contributor

Summary

Fixes #896

This PR resolves an issue where InstanaSpan and ReadableSpan used mutable default arguments (events = [] and attributes = {}), causing all spans created without explicit events/attributes to share the same process-global list. This led to:

  • Unbounded memory growth (live Event objects retained indefinitely).
  • $O(N)$ CPU overhead on span serialization.
  • Cross-trace event/exception leakage in SDK spans.

Changes

  • Changed events and attributes default values to None in InstanaSpan.__init__ and ReadableSpan.__init__.
  • Updated ReadableSpan.__init__ to instantiate fresh lists/dicts via list(events) and dict(attributes).
  • Removed the test fixture workaround (self.span.events.clear()) that previously masked this behavior.
  • Added regression unit tests to verify that distinct spans maintain isolated events and attributes.

Testing

@pvital pvital left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

@CagriYonca
CagriYonca merged commit 9dd19ac into main Oct 2, 2026
17 of 20 checks passed
@CagriYonca
CagriYonca deleted the fix-events branch October 2, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Performance: InstanaSpan.__init__ shares one mutable default events list across every span - resulting in unbounded CPU / memory growth

2 participants