Skip to content

Commit 485c2ee

Browse files
committed
Streamlit + LangGraph agent telemetry example
1 parent 96a9d0f commit 485c2ee

File tree

17 files changed

+7186
-0
lines changed

17 files changed

+7186
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.venv
2+
docker-compose.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS build
2+
RUN apt update && apt install -y git curl
3+
WORKDIR /build
4+
ARG GIT_REF
5+
ENV SCRIPT_URL="https://raw.githubusercontent.com/aabmass/opentelemetry-python-contrib/${GIT_REF?must be set to a git commit}/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/run_streamlit.py"
6+
# Creates the virtualenv
7+
RUN curl -LO "${SCRIPT_URL}" && curl -LO "${SCRIPT_URL}.lock"
8+
RUN VIRTUAL_ENV=./venv uv sync --active --frozen --script run_streamlit.py
9+
10+
FROM python:3.13-slim
11+
WORKDIR /build
12+
COPY --from=build /build/ .
13+
ENV PATH="/build/venv/bin:$PATH"
14+
ENTRYPOINT ["python", "run_streamlit.py"]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
This sample contains a Streamlit + LangGraph chatbot demo. It sends traces and logs to the GCP
2+
with the OTLP exporter and opentelemetry-exporter-gcp-logging exporters.
3+
4+
The `run_streamlit.py` script allows you to easily run the sample with auto instrumentation
5+
enabled and sending telemetry to GCP. It just sets some environment variables and runs with
6+
`opentelemetry-instrument.
7+
8+
## Running the example
9+
10+
First, make sure you have `uv` installed: https://docs.astral.sh/uv/getting-started/installation/.
11+
12+
Optionally, set a project with `export GOOGLE_CLOUD_PROJECT=...`. The app respects ADC.
13+
14+
### Without cloning
15+
16+
```sh
17+
uv run --upgrade https://raw.githubusercontent.com/aabmass/opentelemetry-python-contrib/refs/heads/vertex-langgraph/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/run_streamlit.py
18+
```
19+
20+
### With cloned repo
21+
22+
```sh
23+
git clone --branch=vertex-langgraph https://github.com/aabmass/opentelemetry-python-contrib.git
24+
cd opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo
25+
uv run run_streamlit_local.py
26+
```
27+
28+
### Without auto instrumentation
29+
30+
```sh
31+
uv run streamlit run src/langgraph_chatbot_demo/langchain_history.py
32+
```
33+
34+
## Deploy
35+
36+
Build the docker image
37+
38+
```sh
39+
PROJECT=<...>
40+
TAG=0.x.y
41+
42+
# Update GIT_REF to a commit SHA to force rebuilding if the branch is updated
43+
docker build \
44+
--build-arg GIT_REF=vertex-langgraph \
45+
-t us-central1-docker.pkg.dev/${PROJECT}/oci/langgraph-chatbot-demo:${TAG} \
46+
https://raw.githubusercontent.com/aabmass/opentelemetry-python-contrib/refs/heads/vertex-langgraph/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/Dockerfile
47+
```
48+
49+
### App Engine
50+
51+
Use the included app.yaml
52+
53+
```sh
54+
gcloud app deploy --image-url=us-central1-docker.pkg.dev/${PROJECT}/oci/langgraph-chatbot-demo:${TAG} app.yaml
55+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
runtime: custom
2+
env: flex
3+
env_variables:
4+
STREAMLIT_SERVER_PORT: "8080"
5+
PYTHONUNBUFFERED: "1"
6+
7+
network:
8+
session_affinity: true
9+
10+
resources:
11+
memory_gb: 2
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[project]
2+
name = "langgraph-chatbot-demo"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.9"
7+
dependencies = [
8+
"duckduckgo-search>=7.3.0",
9+
"google-cloud-storage[tracing]>=2.19.0",
10+
"langchain-community>=0.3.16",
11+
"langchain-core>=0.3.31",
12+
"langchain-google-vertexai>=2.0.7",
13+
"langgraph>0.2.27",
14+
"opentelemetry-distro>=0.50b0",
15+
"opentelemetry-exporter-gcp-logging>=1.9.0a0",
16+
"opentelemetry-exporter-gcp-trace>=1.8.0",
17+
"opentelemetry-exporter-otlp-proto-grpc>=1.29.0",
18+
"opentelemetry-instrumentation-aiohttp-client>=0.50b0",
19+
"opentelemetry-instrumentation-httpx>=0.50b0",
20+
"opentelemetry-instrumentation-requests>=0.50b0",
21+
"opentelemetry-instrumentation-sqlite3>=0.51b0",
22+
"opentelemetry-instrumentation-urllib>=0.50b0",
23+
"opentelemetry-instrumentation-urllib3>=0.50b0",
24+
"opentelemetry-instrumentation-vertexai>=2.0b0",
25+
"streamlit>=1.41.1",
26+
]
27+
28+
[tool.uv.sources]
29+
opentelemetry-instrumentation-vertexai = { path = "../../" }
30+
31+
[dependency-groups]
32+
dev = ["ipython>=8.18.1", "ruff>=0.9.2"]
33+
34+
[project.entry-points.opentelemetry_traces_exporter]
35+
otlp_google_auth = "langgraph_chatbot_demo._otlp_google_auth:OTLPSpanExporterGoogleAuth"
36+
37+
[build-system]
38+
requires = ["hatchling"]
39+
build-backend = "hatchling.build"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# /// script
2+
# requires-python = ">=3.13"
3+
# dependencies = [
4+
# "langgraph-chatbot-demo",
5+
# ]
6+
#
7+
# [tool.uv.sources]
8+
# langgraph-chatbot-demo = { git = "https://github.com/aabmass/opentelemetry-python-contrib.git", subdirectory = "instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo", branch = "vertex-langgraph" }
9+
#
10+
# ///
11+
12+
from langgraph_chatbot_demo.run_streamlit import run_streamlit
13+
14+
run_streamlit()

0 commit comments

Comments
 (0)