Skip to content

Commit edeb890

Browse files
committed
With streamlit
1 parent c32596d commit edeb890

File tree

17 files changed

+4717
-335
lines changed

17 files changed

+4717
-335
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TODO: Use `uv sync --script` once available https://github.com/astral-sh/uv/pull/11361
2+
3+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS build
4+
RUN apt update && apt install -y git curl
5+
WORKDIR /build
6+
ARG GIT_REF
7+
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"
8+
# Creates the virtualenv
9+
RUN curl -LO "${SCRIPT_URL}" && curl -LO "${SCRIPT_URL}.lock"
10+
RUN uv venv venv && uv export --script run_streamlit.py | uv pip sync -p venv -
11+
12+
FROM python:3.13-slim
13+
WORKDIR /build
14+
COPY --from=build /build/ .
15+
ENV PATH="/build/venv/bin:$PATH"
16+
ENTRYPOINT ["python", "run_streamlit.py"]
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
This sample contains part of the LangGraph chatbot demo taken from
2-
https://python.langchain.com/docs/tutorials/chatbot, running with OTel instrumentation. It
3-
sends traces and logs to the OTel collector which sends them to GCP. Docker compose wraps
4-
everything to make it easy to run.
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.
57

68
## Running the example
79

8-
I recommend running in Cloud Shell, it's super simple. You will see GenAI spans in trace
9-
explorer right away. Make sure the Vertex and Trace APIs are enabled in the project.
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.
1013

11-
### Cloud Shell or GCE
14+
### Without cloning
1215

1316
```sh
14-
git clone --branch=vertex-langgraph https://github.com/aabmass/opentelemetry-python-contrib.git
15-
cd opentelemetry-python-contrib/instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo
16-
docker compose up --build --abort-on-container-exit
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
1718
```
1819

19-
### Locally with Application Default Credentials
20+
### With cloned repo
2021

2122
```sh
2223
git clone --branch=vertex-langgraph https://github.com/aabmass/opentelemetry-python-contrib.git
2324
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
2429

25-
# Export the credentials to `GOOGLE_APPLICATION_CREDENTIALS` environment variable so it is
26-
# available inside the docker containers
27-
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/application_default_credentials.json
28-
# Lets collector read mounted config
29-
export USERID="$(id -u)"
30-
# Specify the project ID
31-
export GOOGLE_CLOUD_PROJECT=<your project id>
32-
docker compose up --build --abort-on-container-exit
30+
```sh
31+
uv run streamlit run src/langgraph_chatbot_demo/langchain_history.py
3332
```
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

instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/docker-compose.yaml

Lines changed: 0 additions & 43 deletions
This file was deleted.

instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/otel-collector-config.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.

instrumentation-genai/opentelemetry-instrumentation-vertexai/examples/langgraph-chatbot-demo/pyproject.toml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.9"
77
dependencies = [
8+
"duckduckgo-search>=7.3.0",
9+
"langchain-community>=0.3.16",
810
"langchain-core>=0.3.31",
911
"langchain-google-vertexai>=2.0.7",
1012
"langgraph>0.2.27",
1113
"opentelemetry-distro>=0.50b0",
14+
"opentelemetry-exporter-gcp-logging>=1.9.0a0",
15+
"opentelemetry-exporter-gcp-trace>=1.8.0",
1216
"opentelemetry-exporter-otlp-proto-grpc>=1.29.0",
17+
"opentelemetry-instrumentation-aiohttp-client>=0.50b0",
18+
"opentelemetry-instrumentation-httpx>=0.50b0",
19+
"opentelemetry-instrumentation-requests>=0.50b0",
20+
"opentelemetry-instrumentation-sqlite3>=0.51b0",
21+
"opentelemetry-instrumentation-urllib>=0.50b0",
22+
"opentelemetry-instrumentation-urllib3>=0.50b0",
1323
"opentelemetry-instrumentation-vertexai",
24+
"streamlit>=1.41.1",
1425
]
1526

1627
[tool.uv.sources]
17-
opentelemetry-instrumentation-vertexai = { git = "https://github.com/aabmass/opentelemetry-python-contrib.git", subdirectory = "instrumentation-genai/opentelemetry-instrumentation-vertexai", branch = "vertex-langgraph" }
28+
opentelemetry-instrumentation-vertexai = { path = "../../" }
1829

1930
[dependency-groups]
20-
dev = [
21-
"ruff>=0.9.2",
22-
]
31+
dev = ["ipython>=8.18.1", "ruff>=0.9.2"]
32+
33+
[project.entry-points.opentelemetry_traces_exporter]
34+
otlp_google_auth = "langgraph_chatbot_demo._otlp_google_auth:OTLPSpanExporterGoogleAuth"
35+
36+
[build-system]
37+
requires = ["hatchling"]
38+
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)