@@ -65,7 +65,7 @@ def test_filtered_parent_marks_exported_children_as_app_roots(memory_exporter):
6565 assert "filtered-parent" not in spans
6666 assert spans ["child-a" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
6767 assert spans ["child-b" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
68- assert processor ._app_root_traces == {}
68+ assert processor ._span_export_expectation_by_id == {}
6969
7070
7171def test_exported_parent_suppresses_exported_child_app_root (memory_exporter ):
@@ -82,7 +82,7 @@ def test_exported_parent_suppresses_exported_child_app_root(memory_exporter):
8282
8383 assert spans ["parent" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
8484 assert LangfuseOtelSpanAttributes .IS_APP_ROOT not in spans ["child" ].attributes
85- assert processor ._app_root_traces == {}
85+ assert processor ._span_export_expectation_by_id == {}
8686
8787
8888def test_grandparent_baggage_claim_suppresses_child_through_filtered_parent (
@@ -115,7 +115,7 @@ def test_grandparent_baggage_claim_suppresses_child_through_filtered_parent(
115115 spans ["grandparent" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
116116 )
117117 assert LangfuseOtelSpanAttributes .IS_APP_ROOT not in spans ["child" ].attributes
118- assert processor ._app_root_traces == {}
118+ assert processor ._span_export_expectation_by_id == {}
119119
120120
121121def test_same_trace_baggage_claim_suppresses_local_app_root (memory_exporter ):
@@ -139,7 +139,7 @@ def test_same_trace_baggage_claim_suppresses_local_app_root(memory_exporter):
139139 LangfuseOtelSpanAttributes .IS_APP_ROOT
140140 not in spans ["downstream-root" ].attributes
141141 )
142- assert processor ._app_root_traces == {}
142+ assert processor ._span_export_expectation_by_id == {}
143143
144144
145145def test_different_trace_baggage_claim_does_not_suppress_local_app_root (
@@ -165,7 +165,7 @@ def test_different_trace_baggage_claim_does_not_suppress_local_app_root(
165165 spans ["downstream-root" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ]
166166 is True
167167 )
168- assert processor ._app_root_traces == {}
168+ assert processor ._span_export_expectation_by_id == {}
169169
170170
171171def test_local_baggage_claim_suppresses_child_even_when_parent_is_filtered (
@@ -200,7 +200,7 @@ def should_export_span(span: ReadableSpan) -> bool:
200200
201201 assert "parent" not in spans
202202 assert LangfuseOtelSpanAttributes .IS_APP_ROOT not in spans ["child" ].attributes
203- assert processor ._app_root_traces == {}
203+ assert processor ._span_export_expectation_by_id == {}
204204
205205
206206def test_start_time_false_positive_can_leave_exported_child_without_app_root (
@@ -228,7 +228,7 @@ def should_export_span(span: ReadableSpan) -> bool:
228228
229229 assert "parent" not in spans
230230 assert LangfuseOtelSpanAttributes .IS_APP_ROOT not in spans ["child" ].attributes
231- assert processor ._app_root_traces == {}
231+ assert processor ._span_export_expectation_by_id == {}
232232
233233
234234def test_active_langfuse_scope_sets_baggage_after_root_start (
@@ -272,7 +272,7 @@ def test_blocked_instrumentation_scope_parent_marks_child_as_app_root(
272272
273273 assert "blocked-parent" not in spans
274274 assert spans ["child" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
275- assert processor ._app_root_traces == {}
275+ assert processor ._span_export_expectation_by_id == {}
276276
277277
278278def test_foreign_project_langfuse_parent_marks_child_as_app_root (memory_exporter ):
@@ -294,7 +294,7 @@ def test_foreign_project_langfuse_parent_marks_child_as_app_root(memory_exporter
294294
295295 assert "foreign-parent" not in spans
296296 assert spans ["child" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
297- assert processor ._app_root_traces == {}
297+ assert processor ._span_export_expectation_by_id == {}
298298
299299
300300def test_should_export_span_raising_does_not_mark_app_root (memory_exporter ):
@@ -315,7 +315,7 @@ def should_export_span(span: ReadableSpan) -> bool:
315315 spans = _get_spans_by_name (memory_exporter )
316316
317317 assert "root" not in spans
318- assert processor ._app_root_traces == {}
318+ assert processor ._span_export_expectation_by_id == {}
319319
320320
321321def test_mark_app_root_candidate_exception_is_swallowed (memory_exporter , monkeypatch ):
@@ -378,10 +378,12 @@ def worker(worker_id: int) -> None:
378378 LangfuseOtelSpanAttributes .IS_APP_ROOT not in span .attributes
379379 for span in child_spans
380380 )
381- assert processor ._app_root_traces == {}
381+ assert processor ._span_export_expectation_by_id == {}
382382
383383
384- def test_multiple_interleaved_traces_track_state_independently (memory_exporter ):
384+ def test_multiple_interleaved_traces_track_active_span_state_independently (
385+ memory_exporter ,
386+ ):
385387 tracer_provider , processor = _create_processor (memory_exporter )
386388 langfuse_tracer = _langfuse_tracer (tracer_provider )
387389
@@ -390,15 +392,17 @@ def test_multiple_interleaved_traces_track_state_independently(memory_exporter):
390392 trace_b_root = langfuse_tracer .start_span ("trace-b-root" )
391393 trace_b_ctx = trace_api .set_span_in_context (trace_b_root )
392394
393- assert len (processor ._app_root_traces ) == 2
395+ assert len (processor ._span_export_expectation_by_id ) == 2
394396
395397 trace_a_child = langfuse_tracer .start_span ("trace-a-child" , context = trace_a_ctx )
396398 trace_b_child = langfuse_tracer .start_span ("trace-b-child" , context = trace_b_ctx )
397399
400+ assert len (processor ._span_export_expectation_by_id ) == 4
401+
398402 trace_b_child .end ()
399403 trace_b_root .end ()
400404
401- assert len (processor ._app_root_traces ) == 1
405+ assert len (processor ._span_export_expectation_by_id ) == 2
402406
403407 trace_a_child .end ()
404408 trace_a_root .end ()
@@ -419,7 +423,28 @@ def test_multiple_interleaved_traces_track_state_independently(memory_exporter):
419423 assert (
420424 LangfuseOtelSpanAttributes .IS_APP_ROOT not in spans ["trace-b-child" ].attributes
421425 )
422- assert processor ._app_root_traces == {}
426+ assert processor ._span_export_expectation_by_id == {}
427+
428+
429+ def test_child_started_after_parent_end_is_marked_as_app_root (memory_exporter ):
430+ tracer_provider , processor = _create_processor (memory_exporter )
431+ langfuse_tracer = _langfuse_tracer (tracer_provider )
432+
433+ parent = langfuse_tracer .start_span ("parent" )
434+ parent_ctx = trace_api .set_span_in_context (parent )
435+
436+ parent .end ()
437+
438+ child = langfuse_tracer .start_span ("child" , context = parent_ctx )
439+ child .end ()
440+
441+ processor .force_flush ()
442+
443+ spans = _get_spans_by_name (memory_exporter )
444+
445+ assert spans ["parent" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
446+ assert spans ["child" ].attributes [LangfuseOtelSpanAttributes .IS_APP_ROOT ] is True
447+ assert processor ._span_export_expectation_by_id == {}
423448
424449
425450def test_set_langfuse_trace_id_in_baggage_sets_value ():
0 commit comments