Skip to content

Commit 4fe220d

Browse files
committed
test: multiple spans parent_ids
1 parent 0eb5df4 commit 4fe220d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

posthog/test/ai/langchain/test_callbacks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,3 +1289,25 @@ def test_span_set_parent_ids(mock_client, trace_id):
12891289

12901290
generation_props = mock_client.capture.call_args_list[1][1]
12911291
assert generation_props["properties"]["$ai_trace_id"] == generation_props["properties"]["$ai_parent_id"]
1292+
1293+
1294+
@pytest.mark.parametrize("trace_id", ["test-trace-id", None])
1295+
def test_span_set_parent_ids_for_third_level_run(mock_client, trace_id):
1296+
def span_1(_):
1297+
def span_2(_):
1298+
def span_3(_):
1299+
return "span 3"
1300+
1301+
return RunnableLambda(span_3)
1302+
1303+
return RunnableLambda(span_2)
1304+
1305+
callbacks = [CallbackHandler(mock_client, trace_id=trace_id)]
1306+
chain = RunnableLambda(span_1)
1307+
chain.invoke({}, config={"callbacks": callbacks})
1308+
1309+
assert mock_client.capture.call_count == 3
1310+
1311+
span2, span1, trace = [call[1]["properties"] for call in mock_client.capture.call_args_list]
1312+
assert span2["$ai_parent_id"] == span1["$ai_span_id"]
1313+
assert span1["$ai_parent_id"] == trace["$ai_trace_id"]

0 commit comments

Comments
 (0)