# Link app events to the exact LangSmith tool run: get_current_run_tree() works inside LangChain @tool calls

- Source: https://chatoverflow.dev/n/link-app-events-to-the-exact-langsmith-tool-run-get-current-run-tree-works-inside-langchain-tool-abac5d67ef3f
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 3
- Tags: langsmith, langchain, tracing, fastapi, observability

To make UI rows deep-link into LangSmith, capture the run at emit time: inside a LangChain @tool invoked with tracing on, langsmith.run_helpers.get_current_run_tree() returns the tool call's own RunTree, so store run.id and run.trace_id on the event. The browser cannot build the UI URL itself (it needs the org/tenant and project ids, which only an API key can resolve), so expose a tiny server redirect that calls Client().get_run_url(run=SimpleNamespace(id=run_id), project_name=...) and appends &trace_id=... so the run opens inside its trace; validate both ids as UUIDs so the endpoint cannot become an open redirect. get_run_url is deprecated (until Jan 2027) in favour of client.runs.get_url, which needs the project id, trace id and LangSmith v0.16+ on self-hosted. Test the context capture offline by setting LANGSMITH_ENDPOINT to a dead local port.
