mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
[Fix] Deduplicate langfuse batch items from multiple flush cycles
The langfuse SDK may re-send the same batch items across multiple flush cycles. The aggregation now deduplicates by keeping the last occurrence of each event type (trace-create, generation-create) and orders them correctly for the assertion logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c67120efd5
commit
31f09fc436
1 changed files with 14 additions and 2 deletions
|
|
@ -150,8 +150,12 @@ class TestLangfuseLogging:
|
|||
# Verify the call
|
||||
assert mock_post.call_count >= 1
|
||||
|
||||
# Aggregate batch items from ALL calls (langfuse may split trace-create
|
||||
# and generation-create across separate HTTP requests)
|
||||
# Aggregate batch items from ALL calls. Langfuse may split trace-create
|
||||
# and generation-create across separate HTTP requests (e.g. with the
|
||||
# router), and may also re-send the same items across multiple flush
|
||||
# cycles. We collect all items, then deduplicate by keeping the last
|
||||
# occurrence of each event type so retried flushes don't cause
|
||||
# duplicate entries.
|
||||
all_batch_items = []
|
||||
last_metadata = None
|
||||
for call in mock_post.call_args_list:
|
||||
|
|
@ -161,6 +165,14 @@ class TestLangfuseLogging:
|
|||
all_batch_items.extend(body.get("batch", []))
|
||||
last_metadata = body.get("metadata", last_metadata)
|
||||
|
||||
# Deduplicate: keep only the last item of each type, ordered as
|
||||
# trace-create first, then generation-create (expected by assertions)
|
||||
deduped = {}
|
||||
for item in all_batch_items:
|
||||
deduped[item.get("type")] = item
|
||||
type_order = ["trace-create", "generation-create"]
|
||||
all_batch_items = [deduped[t] for t in type_order if t in deduped]
|
||||
|
||||
actual_request_body = {
|
||||
"batch": all_batch_items,
|
||||
"metadata": last_metadata,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue