Skip to content

Add Optional Ephemeral Scope Handling #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rahultejwani
Copy link
Collaborator

This PR adds optional ephemeral scope handling for high cardinality use cases. This is the first part of a series of changes to improve memory efficiency in high-cardinality metrics scenarios.

…Cases

This change adds mechanisms to avoid caching subscopes when dealing with high
cardinality metrics, which prevents memory leaks and improves performance.

Implementation:
- Added a `NoCacheSubscopes` option to ScopeOptions for explicit opt-in
- Added adaptive behavior that automatically switches to non-caching mode when
  the number of subscopes exceeds 5000 (HighCardinalityThreshold)
- Ephemeral scopes are not stored in the registry and will be garbage collected
  when no longer referenced
- Fixed reporter methods to avoid deadlocks by moving WaitGroup.Done() calls
  outside of mutex locks
- Added tests for both explicit and adaptive ephemeral scope behavior

Benefits:
- Memory usage plateaus instead of growing unbounded for high-cardinality cases
- Reduces lock contention on the scope registry
- No breaking changes as this is an opt-in feature
- Provides both explicit control and automatic protection

Use case: When tags are unique per event (e.g., request IDs or session IDs),
this change prevents memory exhaustion while allowing for comprehensive metrics.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants