Galileo Instrumentation for LangChain Apps
Quickstart Setup
Start by adding the Galileo SDK to the travel planner’s environment and initializing Galileo tracing.
Activate Environment
Navigate to the app directory and create a new virtual environment:
cd ~/workshop/agentic-ai/base-app
python3 -m venv .venv
source .venv/bin/activateInstall Galileo SDK
The app already installs langchain, langchain-openai, langgraph, and flask via its
requirements.txt. Galileo’s LangChain callback ships with the galileo package, so
let’s add it here.
Open the ~/workshop/agentic-ai/base-app/requirements.txt file for editing
and add the following packages:
galileo
python-dotenvThen add all of the packages to the virtual environment:
pip install -r requirements.txtConfigure Galileo credentials
Your EC2 instance comes pre-configured with OPENAI_API_KEY and
OPENAI_BASE_URL environment variables, which will be used by the application.
To define additional environment variables, create a new file named
~/workshop/agentic-ai/base-app/.env and add your credentials:
GALILEO_API_KEY="your-galileo-api-key"
GALILEO_CONSOLE_URL="https://console.multitenant.galileocloud.io"
# If you comment out the next two uncommented lines, Galileo uses a project and log
# stream both named "default".
GALILEO_PROJECT="Workshop19Galileo"
GALILEO_LOG_STREAM="TravelPlanner-${INSTANCE}"Initialize Galileo in the app
Initialize Galileo near the top of ~/workshop/agentic-ai/base-app/main.py, right before import logging. Passing the environment variables through means the project and log stream come from your .env when set, and fall back to Galileo’s default/default when not:
import os
from dotenv import load_dotenv
from galileo import galileo_context
load_dotenv()
galileo_context.init(project=os.getenv("GALILEO_PROJECT"),
log_stream=os.getenv("GALILEO_LOG_STREAM"))If you comment out the GALILEO_PROJECT and GALILEO_LOG_STREAM variables in your .env, where will
your traces show up in Galileo?
