@@ -1642,90 +1642,6 @@ def test_async_langchain_chain_outside_transaction(
16421642 loop .run_until_complete (getattr (runnable , call_function )(input_ ))
16431643
16441644
1645- @pytest .mark .parametrize (
1646- "create_function,call_function,call_function_args,call_function_kwargs,expected_events" ,
1647- (
1648- pytest .param (
1649- create_structured_output_runnable ,
1650- "ainvoke" ,
1651- ({"input" : "Sally is 13" },),
1652- {"config" : {"tags" : ["bar" ], "metadata" : {"id" : "123" }}},
1653- chat_completion_recorded_events_runnable_invoke ,
1654- id = "runnable_chain.ainvoke-with-args-and-kwargs" ,
1655- ),
1656- pytest .param (
1657- create_structured_output_chain ,
1658- "ainvoke" ,
1659- ({"input" : "Sally is 13" },),
1660- {"config" : {"tags" : ["bar" ], "metadata" : {"id" : "123" }}, "return_only_outputs" : True },
1661- chat_completion_recorded_events_invoke ,
1662- id = "chain.ainvoke-with-args-and-kwargs" ,
1663- ),
1664- ),
1665- )
1666- def test_multiple_async_langchain_chain (
1667- set_trace_info ,
1668- json_schema ,
1669- prompt ,
1670- chat_openai_client ,
1671- create_function ,
1672- call_function ,
1673- call_function_args ,
1674- call_function_kwargs ,
1675- expected_events ,
1676- loop ,
1677- ):
1678- call1 = events_with_context_attrs (expected_events .copy ())
1679- call1 [0 ][1 ]["request_id" ] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1680- call1 [1 ][1 ]["request_id" ] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1681- call1 [2 ][1 ]["request_id" ] = "b1883d9d-10d6-4b67-a911-f72849704e92"
1682- call2 = events_with_context_attrs (expected_events .copy ())
1683- call2 [0 ][1 ]["request_id" ] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1684- call2 [1 ][1 ]["request_id" ] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1685- call2 [2 ][1 ]["request_id" ] = "a58aa0c0-c854-4657-9e7b-4cce442f3b61"
1686-
1687- @reset_core_stats_engine ()
1688- @validate_custom_events (call1 + call2 )
1689- # 3 langchain events and 5 openai events.
1690- @validate_custom_event_count (count = 16 )
1691- @validate_transaction_metrics (
1692- name = "test_chain:test_multiple_async_langchain_chain.<locals>._test" ,
1693- scoped_metrics = [(f"Llm/chain/LangChain/{ call_function } " , 2 )],
1694- rollup_metrics = [(f"Llm/chain/LangChain/{ call_function } " , 2 )],
1695- custom_metrics = [(f"Supportability/Python/ML/LangChain/{ langchain .__version__ } " , 1 )],
1696- background_task = True ,
1697- )
1698- @background_task ()
1699- def _test ():
1700- with patch ("langchain_core.callbacks.manager.uuid" , autospec = True ) as mock_uuid :
1701- mock_uuid .uuid4 .side_effect = [
1702- uuid .UUID ("b1883d9d-10d6-4b67-a911-f72849704e92" ), # first call
1703- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b61" ),
1704- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b61" ), # second call
1705- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b63" ),
1706- uuid .UUID ("b1883d9d-10d6-4b67-a911-f72849704e93" ),
1707- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b64" ),
1708- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b65" ),
1709- uuid .UUID ("a58aa0c0-c854-4657-9e7b-4cce442f3b66" ),
1710- ]
1711- set_trace_info ()
1712- add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
1713- add_custom_attribute ("llm.foo" , "bar" )
1714- add_custom_attribute ("non_llm_attr" , "python-agent" )
1715-
1716- runnable = create_function (json_schema , chat_openai_client , prompt )
1717- with WithLlmCustomAttributes ({"context" : "attr" }):
1718- call1 = asyncio .ensure_future (
1719- getattr (runnable , call_function )(* call_function_args , ** call_function_kwargs ), loop = loop
1720- )
1721- call2 = asyncio .ensure_future (
1722- getattr (runnable , call_function )(* call_function_args , ** call_function_kwargs ), loop = loop
1723- )
1724- loop .run_until_complete (asyncio .gather (call1 , call2 ))
1725-
1726- _test ()
1727-
1728-
17291645@reset_core_stats_engine ()
17301646@validate_custom_events (recorded_events_retrieval_chain_response )
17311647@validate_custom_event_count (count = 17 )
0 commit comments