55import sys
66import uuid
77
8- import langsmith as ls
98from langsmith import traceable
109from temporalio .client import Client
1110from temporalio .contrib .langsmith import LangSmithPlugin
1413
1514from langsmith_tracing .chatbot .workflows import ChatbotWorkflow
1615
16+ PROJECT_NAME = "langsmith-chatbot"
17+
1718
1819async def main ():
1920 add_temporal_runs = "--add-temporal-runs" in sys .argv
@@ -22,7 +23,7 @@ async def main():
2223 config .setdefault ("target_host" , "localhost:7233" )
2324
2425 plugin = LangSmithPlugin (
25- project_name = "langsmith-chatbot" ,
26+ project_name = PROJECT_NAME ,
2627 add_temporal_runs = add_temporal_runs ,
2728 )
2829
@@ -34,11 +35,13 @@ async def main():
3435
3536 wf_id = f"langsmith-chatbot-{ uuid .uuid4 ().hex [:8 ]} "
3637
37- # Client-side trace wraps the full interactive session. Each turn
38- # (signal + query poll) nests under this root span in LangSmith.
3938 @traceable (
4039 name = f"Chatbot Session { wf_id [- 8 :]} " ,
4140 run_type = "chain" ,
41+ # CRITICAL: Client-side @traceable runs outside the LangSmithPlugin's scope.
42+ # Make sure client-side traces use the same project_name as what is given to
43+ # # the plugin.
44+ project_name = PROJECT_NAME ,
4245 tags = ["client-side" , "chatbot" ],
4346 )
4447 async def run_session ():
@@ -83,10 +86,7 @@ async def send_and_wait(msg: str):
8386 else :
8487 print ("(timed out waiting for response)" )
8588
86- try :
87- await run_session ()
88- finally :
89- ls .flush ()
89+ await run_session ()
9090
9191
9292if __name__ == "__main__" :
0 commit comments