@@ -62,7 +62,10 @@ def test_llm_calls(logger_memory_logger):
6262 spans = memory_logger .pop ()
6363 assert len (spans ) == 3
6464
65+ # ``root_span_id`` is the root span's own span_id (the parent reference for
66+ # its children); ``trace_root_id`` is the trace shared by every span.
6567 root_span_id = spans [0 ]["span_id" ]
68+ trace_root_id = spans [0 ]["root_span_id" ]
6669
6770 assert_matches_object (
6871 spans ,
@@ -81,7 +84,7 @@ def test_llm_calls(logger_memory_logger):
8184 },
8285 "metadata" : {"tags" : []},
8386 "span_id" : root_span_id ,
84- "root_span_id" : root_span_id ,
87+ "root_span_id" : trace_root_id ,
8588 },
8689 {
8790 "span_attributes" : {"name" : "ChatPromptTemplate" },
@@ -97,7 +100,7 @@ def test_llm_calls(logger_memory_logger):
97100 ]
98101 },
99102 "metadata" : {"tags" : ["seq:step:1" ]},
100- "root_span_id" : root_span_id ,
103+ "root_span_id" : trace_root_id ,
101104 "span_parents" : [root_span_id ],
102105 },
103106 {
@@ -144,7 +147,7 @@ def test_llm_calls(logger_memory_logger):
144147 "tags" : ["seq:step:2" ],
145148 "model" : "gpt-4o-mini-2024-07-18" ,
146149 },
147- "root_span_id" : root_span_id ,
150+ "root_span_id" : trace_root_id ,
148151 "span_parents" : [root_span_id ],
149152 },
150153 ],
@@ -171,6 +174,7 @@ def test_chain_with_memory(logger_memory_logger):
171174 assert len (spans ) == 3
172175
173176 root_span_id = spans [0 ]["span_id" ]
177+ trace_root_id = spans [0 ]["root_span_id" ]
174178
175179 assert_matches_object (
176180 spans ,
@@ -189,7 +193,7 @@ def test_chain_with_memory(logger_memory_logger):
189193 },
190194 "metadata" : {"tags" : ["test" ]},
191195 "span_id" : root_span_id ,
192- "root_span_id" : root_span_id ,
196+ "root_span_id" : trace_root_id ,
193197 },
194198 {
195199 "span_attributes" : {"name" : "ChatPromptTemplate" },
@@ -205,7 +209,7 @@ def test_chain_with_memory(logger_memory_logger):
205209 ]
206210 },
207211 "metadata" : {"tags" : ["seq:step:1" , "test" ]},
208- "root_span_id" : root_span_id ,
212+ "root_span_id" : trace_root_id ,
209213 "span_parents" : [root_span_id ],
210214 },
211215 {
@@ -252,7 +256,7 @@ def test_chain_with_memory(logger_memory_logger):
252256 "tags" : ["seq:step:2" , "test" ],
253257 "model" : "gpt-4o-mini-2024-07-18" ,
254258 },
255- "root_span_id" : root_span_id ,
259+ "root_span_id" : trace_root_id ,
256260 "span_parents" : [root_span_id ],
257261 },
258262 ],
@@ -301,13 +305,14 @@ def calculator(input: CalculatorInput) -> str:
301305
302306 spans = memory_logger .pop ()
303307 root_span_id = spans [0 ]["span_id" ]
308+ trace_root_id = spans [0 ]["root_span_id" ]
304309
305310 assert_matches_object (
306311 spans ,
307312 [
308313 {
309314 "span_id" : root_span_id ,
310- "root_span_id" : root_span_id ,
315+ "root_span_id" : trace_root_id ,
311316 "span_attributes" : {
312317 "name" : "ChatOpenAI" ,
313318 "type" : "llm" ,
@@ -640,13 +645,13 @@ def test_chain_null_values(logger_memory_logger):
640645 flush ()
641646
642647 spans = memory_logger .pop ()
643- root_span_id = spans [0 ]["span_id " ]
648+ trace_root_id = spans [0 ]["root_span_id " ]
644649
645650 assert_matches_object (
646651 spans ,
647652 [
648653 {
649- "root_span_id" : root_span_id ,
654+ "root_span_id" : trace_root_id ,
650655 "span_attributes" : {
651656 "name" : "TestChain" ,
652657 "type" : "task" ,
@@ -721,7 +726,10 @@ def task_fn(input, hooks):
721726
722727 # Find the root eval span
723728 root_eval_span = [s for s in spans if s .get ("span_attributes" , {}).get ("name" ) == "test-consecutive-eval" ][0 ]
729+ # ``root_eval_span_id`` is the eval root's own span_id (the parent reference
730+ # for its children); ``trace_root_id`` is the trace shared by every span.
724731 root_eval_span_id = root_eval_span ["span_id" ]
732+ trace_root_id = root_eval_span ["root_span_id" ]
725733
726734 # Find the eval dataset record spans (direct children of root eval span)
727735 eval_record_spans = [
@@ -751,7 +759,7 @@ def task_fn(input, hooks):
751759 [
752760 {
753761 "span_id" : root_eval_span_id ,
754- "root_span_id" : root_eval_span_id ,
762+ "root_span_id" : trace_root_id ,
755763 "span_attributes" : {
756764 "name" : "test-consecutive-eval" ,
757765 "type" : "eval" ,
@@ -765,7 +773,7 @@ def task_fn(input, hooks):
765773 [eval_record_1 ],
766774 [
767775 {
768- "root_span_id" : root_eval_span_id ,
776+ "root_span_id" : trace_root_id ,
769777 "span_parents" : [root_eval_span_id ],
770778 "span_attributes" : {
771779 "name" : "eval" ,
@@ -781,7 +789,7 @@ def task_fn(input, hooks):
781789 [eval_record_2 ],
782790 [
783791 {
784- "root_span_id" : root_eval_span_id ,
792+ "root_span_id" : trace_root_id ,
785793 "span_parents" : [root_eval_span_id ],
786794 "span_attributes" : {
787795 "name" : "eval" ,
@@ -797,7 +805,7 @@ def task_fn(input, hooks):
797805 [task_1_span ],
798806 [
799807 {
800- "root_span_id" : root_eval_span_id ,
808+ "root_span_id" : trace_root_id ,
801809 "span_parents" : [eval_record_1 ["span_id" ]],
802810 "span_attributes" : {
803811 "name" : "task" ,
@@ -813,7 +821,7 @@ def task_fn(input, hooks):
813821 [task_2_span ],
814822 [
815823 {
816- "root_span_id" : root_eval_span_id ,
824+ "root_span_id" : trace_root_id ,
817825 "span_parents" : [eval_record_2 ["span_id" ]],
818826 "span_attributes" : {
819827 "name" : "task" ,
0 commit comments