Repository navigation
Langsmith tracing - #179
Merged
Merged
Conversation
lpi-tn
reviewed
Jul 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR integrates LangSmith tracing across the LangChain-based chat flows to improve observability, by configuring tracing at app startup and propagating trace_context/tags/metadata through both agent and non-agent LLM calls.
Changes:
- Added LangSmith dependency + config/env plumbing and startup configuration.
- Propagated structured trace metadata through chat endpoints and chat/tutor services.
- Decorated LLM proxy completion methods for LangSmith compatibility and enriched agent/non-agent run config with tags/metadata.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/app/core/langsmith.py |
Adds configure_langsmith_tracing() to set tracing-related env vars on startup. |
src/app/core/lifespan.py |
Calls tracing configuration during app lifespan startup. |
src/app/core/config.py |
Adds LangSmith-related settings fields. |
src/app/shared/infra/tracing.py |
Introduces shared tracing constants/enums for consistent run naming. |
src/app/shared/infra/llm_proxy.py |
Adds @traceable decorators and threads trace_context through completion APIs (plus new stream wrapper). |
src/app/shared/infra/abst_chat.py |
Builds and passes non-agent/agent trace metadata and tags into LLM + agent execution config. |
src/app/api/api_v1/endpoints/chat.py |
Builds agent trace context and propagates it into agent chat execution. |
src/app/api/api_v1/endpoints/chat_utils.py |
Propagates trace context through streaming agent helpers. |
src/app/models/chat.py |
Adds a TraceContext TypedDict to standardize agent trace metadata shape. |
src/app/tutor/service/agents.py |
Adds per-agent tags/metadata via RunnableConfig for tutor LangChain runs. |
src/app/tutor/service/tutor.py |
Adds trace metadata/tags to tutor syllabus agents and plumbs trace_context. |
src/app/tutor/api/router.py |
Constructs and forwards trace context for tutor syllabus endpoints. |
pyproject.toml |
Adds langsmith dependency. |
poetry.lock |
Locks langsmith (and transitive deps) versions. |
.env.example |
Documents new LangSmith tracing environment variables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces LangSmith tracing for LangChain-based LLM calls, enabling improved observability and debugging of both agent and non-agent chat operations. The integration is configurable via environment variables, and trace context metadata is now propagated throughout the chat and LLM proxy layers. The most important changes are summarized below.
LangSmith/Tracing Integration:
langsmithas a dependency and new LangSmith-related environment variables to.env.exampleand the settings model (pyproject.toml,.env.example,src/app/core/config.py). [1] [2] [3]configure_langsmith_tracingto set up LangSmith tracing on app startup (src/app/core/langsmith.py,src/app/core/lifespan.py). [1] [2] [3]Trace Context Propagation:
trace_contextmetadata for agent and non-agent chat operations, including endpoint, session, thread, and query details (src/app/api/api_v1/endpoints/chat.py,src/app/api/api_v1/endpoints/chat_utils.py). [1] [2] [3] [4] [5] [6] [7] [8] [9]Non-Agent and Agent Chat Improvements:
_build_non_agent_trace_contexthelper and ensured all chat operations (e.g., formatting, language detection, rephrasing, chat messages) pass trace context to LLM calls (src/app/shared/infra/abst_chat.py). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]LLM Proxy Enhancements:
LLMProxyto accept and logtrace_contextin all completion methods, and decorated key methods with@traceablefor LangSmith compatibility (src/app/shared/infra/llm_proxy.py). [1] [2] [3]These changes collectively enable end-to-end tracing and improved debugging for both agent and non-agent LLM-powered chat features.