I’m new to LangChain and having issues with Langsmith tracking in my Colab notebook. The code runs fine but no logs appear in Langsmith dashboard.
from langchain_core.documents import Document
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.prompts import ChatPromptTemplate
from langchain_community.vectorstores.faiss import FAISS
from langchain_openai import AzureOpenAIEmbeddings
from langchain.chains import create_retrieval_chain
from langsmith import Client
from langchain_core.messages import HumanMessage, AIMessage
from langchain_core.prompts import MessagesPlaceholder
import logging
def load_web_content(page_url):
logging.getLogger("langchain_text_splitters.base").setLevel(logging.ERROR)
web_loader = WebBaseLoader(page_url)
documents = web_loader.load()
text_splitter = RecursiveCharacterTextSplitter(
chunk_size=500,
chunk_overlap=50
)
split_documents = text_splitter.split_documents(documents)
return split_documents
def setup_vector_store(documents):
embedding_model = AzureOpenAIEmbeddings(
model="text-embedding-3-large",
azure_endpoint="https://myendpoint.openai.azure.com/openai/deployments/embedding-model/embeddings?api-version=2023-05-15",
openai_api_key="your-key-here",
openai_api_version="2023-05-15"
)
vector_db = FAISS.from_documents(documents, embedding_model)
return vector_db
def build_qa_chain(vector_db):
system_prompt = ChatPromptTemplate.from_messages([
("system", "Please answer the question using this context: {context}"),
MessagesPlaceholder(variable_name="chat_history"),
("human", "{input}")
])
document_chain = create_stuff_documents_chain(
llm=language_model,
prompt=system_prompt
)
doc_retriever = vector_db.as_retriever(search_kwargs={"k": 3})
final_chain = create_retrieval_chain(doc_retriever, document_chain)
return final_chain
def handle_conversation(qa_chain, user_question, history):
result = qa_chain.invoke({
"input": user_question,
"chat_history": history
})
return result["answer"]
conversation_history = []
if __name__ == "__main__":
web_docs = load_web_content("https://docs.smith.langchain.com/evaluation/concepts")
vector_store = setup_vector_store(web_docs)
qa_system = build_qa_chain(vector_store)
while True:
question = input("Ask: ")
if question.lower() == "quit":
break
answer = handle_conversation(qa_system, question, conversation_history)
conversation_history.append(HumanMessage(content=question))
conversation_history.append(AIMessage(content=answer))
print("Response:", answer)
Everything works but no tracking shows up in Langsmith. Any ideas what might be missing? I’ve tried different approaches but still no luck with the logging.
Had the exact same problem when I started using Langsmith in Colab. Everyone’s mentioning environment variables, which is key, but here’s what really got me: Colab doesn’t always pick up env vars if you set them mid-session, especially after kernel restarts or running cells out of order. Set them right at the start of your notebook and restart the runtime. Also check you’re looking at the right project in Langsmith. Traces default to a “default” project unless you set LANGCHAIN_PROJECT. I wasted hours staring at my empty custom project while everything was going to default. Your chain looks fine, but make sure your Azure OpenAI setup actually works first. If auth fails, the whole chain can fail silently and you won’t see traces. Test just the language model by itself first.
I’ve hit this wall tons of times setting up pipeline monitoring. Sure, everyone’s talking about environment variables, but there’s a bigger problem.
Your setup’s a mess to debug. Azure OpenAI, FAISS, web scraping, plus LangSmith tracking? That’s way too many pieces in Colab.
Skip the environment variable dance completely. I route everything through Latenode for ML monitoring. Same RAG pipeline, but with logging and monitoring that actually works.
Ditch LangSmith in Colab. Build your document processing and QA chain in Latenode instead. Clean Azure OpenAI connections, native vector storage, proper execution logs - no extra setup needed.
Bonus: trigger it from anywhere, not just Colab. We moved our experimental chains there and never went back. Way cleaner than debugging env vars in notebooks.
The first response covered environment variables, but there’s more.
I hit this exact issue last year setting up tracing for our team’s notebooks. Beyond the env vars, you need to initialize the LangSmith client correctly.
Add this after your imports:
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "your-langsmith-api-key"
os.environ["LANGCHAIN_PROJECT"] = "your-project-name" # optional but helpful
You’re importing Client from langsmith but never using it. Drop that import - you don’t need it for basic tracing.
One thing that tripped me up - your LangSmith API key is different from your OpenAI key. They’re separate services.
Also, your language_model variable is undefined. That’ll throw an error before you even reach the tracing part.
Your code has a bigger problem than just environment variables. The language_model variable isn’t defined anywhere - that’s why create_stuff_documents_chain crashes. LangSmith can’t trace what doesn’t exist.
You need to actually initialize your Azure OpenAI model:
LangSmith needs actual model calls to trace. No model = no telemetry data. I’ve seen this tons of times - people get caught up setting up tracing but forget to instantiate the actual LLM.
Also, test your Azure connection separately first. If auth fails, everything breaks silently and you’ll just stare at empty dashboards even with perfect environment variables.
colab’s runtime is prob eating your traces. try adding import langsmith, then run langsmith.utils.tracing_is_enabled() to check if tracing actually started. sometimes colab blocks connections to langsmith servers even if your env vars are correct.
Debugging LangSmith tracing in Colab always comes down to the fundamentals. People covered the missing language_model variable and env vars, but here’s what usually breaks first in production.
I’ve debugged this exact setup dozens of times. Your Azure OpenAI endpoint looks wrong - you’re mixing the embeddings URL format with the chat completions setup. That URL should just be your base endpoint like https://myendpoint.openai.azure.com.
Also, that while loop at the bottom? It won’t work in Colab notebooks. Input() blocks execution weird in Jupyter environments. Test with hardcoded questions first:
test_questions = ["What is evaluation?", "How does tracing work?"]
for question in test_questions:
answer = handle_conversation(qa_system, question, conversation_history)
print(f"Q: {question}")
print(f"A: {answer}\n")
Your retrieval chain setup might be swallowing errors. Wrap your invoke calls in try/except blocks to catch authentication failures that kill tracing silently.
This video walks through proper LangSmith setup from scratch. Super helpful for getting the basics right:
Once you fix the model instantiation and test with simple hardcoded questions, traces should start appearing. The environment variables everyone mentioned are correct, but they’re useless if your chain crashes before making any LLM calls.
You’re missing the LangSmith env variables. Set LANGCHAIN_TRACING_V2=true and LANGCHAIN_API_KEY in Colab before running your code. Also, where’s language_model defined in your script?