Skip to content
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

Fix: Adjust flush timing for nested generations using outermost_lock_context #183

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Feb 10, 2025

Fixes: #176

Overview:
Fix the issue where spans in nested generations are flushed prematurely, causing foreign key constraint failures due to missing parent spans.

Changes:

  • Modified the flush logic so that only the outermost generation performs a flush, while inner generations do not trigger a flush.
  • Renamed and updated the context manager from manual_flush_context() to outermost_lock_context(). When enabled for the outermost generation (enable_lock=True), outermost_lock_context() acquires the BatchSpanProcessor's condition lock (via "with processor.condition:") to synchronize flush operations. This ensures that flush occurs only once at the end of the outermost generation.
  • Updated the generation() decorator to use outermost_lock_context(is_outermost) appropriately, ensuring that flush is executed only for the outermost generation.

Effect:
This change ensures that all spans are sent only after the entire nested generation has completed, preserving the parent-child relationships and avoiding foreign key constraint issues.

@koxudaxi koxudaxi changed the title Fix flush buffered spans Fix: Adjust span flush timing for nested generations Feb 10, 2025
lilypad/generations.py Outdated Show resolved Hide resolved
@koxudaxi koxudaxi marked this pull request as draft February 11, 2025 00:10
@koxudaxi koxudaxi changed the title Fix: Adjust span flush timing for nested generations Fix: Adjust flush timing for nested generations using outermost_lock_context Feb 11, 2025
@koxudaxi koxudaxi marked this pull request as ready for review February 11, 2025 01:55
@koxudaxi koxudaxi requested a review from brenkao February 11, 2025 01:58
@koxudaxi koxudaxi merged commit d9d8c98 into main Feb 12, 2025
8 checks passed
@koxudaxi koxudaxi deleted the fix-flush-buffered-spans branch February 12, 2025 00:51
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.

Saving spans with nested generations fails.
2 participants