Skip to content

Commit

Permalink
chatbot-rag-app: implements bedrock tracing with langtrace (#374)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt authored Jan 20, 2025
1 parent fbfe731 commit 050847c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 49 deletions.
2 changes: 2 additions & 0 deletions example-apps/chatbot-rag-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
*/node_modules
1 change: 0 additions & 1 deletion example-apps/chatbot-rag-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM node:22-alpine AS build-step
WORKDIR /app
ENV PATH=/node_modules/.bin:$PATH
COPY frontend ./frontend
RUN rm -rf /app/frontend/node_modules
RUN cd frontend && yarn install
RUN cd frontend && REACT_APP_API_HOST=/api yarn build

Expand Down
9 changes: 8 additions & 1 deletion example-apps/chatbot-rag-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ dotenv run -- python api/app.py
If you set `OTEL_SDK_DISABLED=false` in your `.env` file, the app will send
logs, metrics and traces to an OpenTelemetry compatible endpoint.

This happens automatically, when using docker. If running with python directly,
prefix `python` with `opentelemetry-instrument` to enable OpenTelemetry.

```bash
dotenv run -- opentelemetry-instrument python api/app.py
```

[env.example](env.example) defaults to use Elastic APM server, started by
[docker-compose-elastic.yml](../../docker). If you start your Elastic stack
this way, you can access Kibana like this, authenticating with the username
Expand All @@ -147,7 +154,7 @@ To update package versions, recreate [requirements.txt](requirements.txt) and
reinstall like this. Once checked in, any commands above will use updates.

```bash
rm -rf .venv
rm -rf .venv requirements.txt
python3 -m venv .venv
source .venv/bin/activate
# Install dev requirements for pip-compile and edot-bootstrap
Expand Down
4 changes: 4 additions & 0 deletions example-apps/chatbot-rag-app/api/llm_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def init_azure_chat(temperature):


def init_bedrock(temperature):
# Bedrock is not yet in EDOT. Use the Langtrace Python SDK instead
from langtrace_python_sdk.instrumentation import AWSBedrockInstrumentation

AWSBedrockInstrumentation().instrument()
return ChatBedrock(
model_id=os.getenv("CHAT_MODEL"),
streaming=True,
Expand Down
94 changes: 47 additions & 47 deletions example-apps/chatbot-rag-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.13
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile
Expand All @@ -14,17 +14,17 @@ aiosignal==1.3.2
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.7.0
anyio==4.8.0
# via
# httpx
# openai
attrs==24.3.0
# via aiohttp
blinker==1.9.0
# via flask
boto3==1.35.84
boto3==1.36.2
# via langchain-aws
botocore==1.35.84
botocore==1.36.2
# via
# boto3
# s3transfer
Expand All @@ -37,11 +37,11 @@ certifi==2024.12.14
# httpx
# requests
# sentry-sdk
charset-normalizer==3.4.0
charset-normalizer==3.4.1
# via requests
click==8.1.7
click==8.1.8
# via flask
cohere==5.13.3
cohere==5.13.8
# via langchain-cohere
colorama==0.4.6
# via langtrace-python-sdk
Expand All @@ -57,15 +57,15 @@ distro==1.9.0
# via openai
docstring-parser==0.16
# via google-cloud-aiplatform
elastic-opentelemetry==0.6.0
elastic-opentelemetry==0.6.1
# via -r requirements.in
elastic-transport==8.15.1
elastic-transport==8.17.0
# via elasticsearch
elasticsearch[vectorstore-mmr]==8.17.0
# via
# -r requirements.in
# langchain-elasticsearch
fastavro==1.9.7
fastavro==1.10.0
# via cohere
filelock==3.16.1
# via
Expand All @@ -81,7 +81,7 @@ frozenlist==1.5.0
# via
# aiohttp
# aiosignal
fsspec==2024.10.0
fsspec==2024.12.0
# via
# huggingface-hub
# langtrace-python-sdk
Expand All @@ -100,7 +100,7 @@ google-auth==2.37.0
# google-cloud-core
# google-cloud-resource-manager
# google-cloud-storage
google-cloud-aiplatform==1.75.0
google-cloud-aiplatform==1.77.0
# via langchain-google-vertexai
google-cloud-bigquery==3.27.0
# via google-cloud-aiplatform
Expand Down Expand Up @@ -129,22 +129,22 @@ googleapis-common-protos[grpc]==1.66.0
# grpcio-status
# opentelemetry-exporter-otlp-proto-grpc
# opentelemetry-exporter-otlp-proto-http
grpc-google-iam-v1==0.13.1
grpc-google-iam-v1==0.14.0
# via google-cloud-resource-manager
grpcio==1.68.1
grpcio==1.69.0
# via
# google-api-core
# googleapis-common-protos
# grpc-google-iam-v1
# grpcio-status
# opentelemetry-exporter-otlp-proto-grpc
grpcio-status==1.68.1
grpcio-status==1.69.0
# via google-api-core
h11==0.14.0
# via httpcore
httpcore==1.0.7
# via httpx
httpx==0.27.2
httpx==0.28.1
# via
# cohere
# langchain-google-vertexai
Expand All @@ -157,7 +157,7 @@ httpx-sse==0.4.0
# langchain-community
# langchain-google-vertexai
# langchain-mistralai
huggingface-hub==0.27.0
huggingface-hub==0.27.1
# via
# tokenizers
# transformers
Expand All @@ -171,7 +171,7 @@ importlib-metadata==8.5.0
# via opentelemetry-api
itsdangerous==2.2.0
# via flask
jinja2==3.1.4
jinja2==3.1.5
# via flask
jiter==0.8.2
# via openai
Expand All @@ -183,17 +183,17 @@ jsonpatch==1.33
# via langchain-core
jsonpointer==3.0.0
# via jsonpatch
langchain==0.3.13
langchain==0.3.14
# via
# -r requirements.in
# langchain-community
langchain-aws==0.2.10
langchain-aws==0.2.11
# via -r requirements.in
langchain-cohere==0.3.3
langchain-cohere==0.3.4
# via -r requirements.in
langchain-community==0.3.12
langchain-community==0.3.14
# via langchain-experimental
langchain-core==0.3.27
langchain-core==0.3.30
# via
# langchain
# langchain-aws
Expand All @@ -205,48 +205,47 @@ langchain-core==0.3.27
# langchain-mistralai
# langchain-openai
# langchain-text-splitters
langchain-elasticsearch==0.3.0
langchain-elasticsearch==0.3.2
# via -r requirements.in
langchain-experimental==0.3.3
langchain-experimental==0.3.4
# via langchain-cohere
langchain-google-vertexai==2.0.9
langchain-google-vertexai==2.0.11
# via -r requirements.in
langchain-mistralai==0.2.4
# via -r requirements.in
langchain-openai==0.2.13
langchain-openai==0.3.1
# via -r requirements.in
langchain-text-splitters==0.3.4
langchain-text-splitters==0.3.5
# via langchain
langsmith==0.2.4
langsmith==0.2.11
# via
# langchain
# langchain-community
# langchain-core
langtrace-python-sdk==3.3.16
langtrace-python-sdk==3.3.26
# via -r requirements.in
markupsafe==3.0.2
# via
# jinja2
# werkzeug
marshmallow==3.23.2
marshmallow==3.25.1
# via dataclasses-json
multidict==6.1.0
# via
# aiohttp
# yarl
mypy-extensions==1.0.0
# via typing-inspect
numpy==1.26.4
numpy==2.2.2
# via
# cohere
# elasticsearch
# langchain
# langchain-aws
# langchain-community
# pandas
# shapely
# transformers
openai==1.58.1
openai==1.59.9
# via langchain-openai
opentelemetry-api==1.29.0
# via
Expand Down Expand Up @@ -291,7 +290,7 @@ opentelemetry-proto==1.29.0
# opentelemetry-exporter-otlp-proto-http
opentelemetry-resource-detector-azure==0.1.5
# via elastic-opentelemetry
opentelemetry-resourcedetector-gcp==1.7.0a0
opentelemetry-resourcedetector-gcp==1.8.0a0
# via elastic-opentelemetry
opentelemetry-sdk==1.29.0
# via
Expand All @@ -302,15 +301,15 @@ opentelemetry-sdk==1.29.0
# opentelemetry-resource-detector-azure
# opentelemetry-resourcedetector-gcp
# opentelemetry-sdk-extension-aws
opentelemetry-sdk-extension-aws==2.0.2
opentelemetry-sdk-extension-aws==2.1.0
# via elastic-opentelemetry
opentelemetry-semantic-conventions==0.50b0
# via
# elastic-opentelemetry
# opentelemetry-instrumentation
# opentelemetry-instrumentation-sqlalchemy
# opentelemetry-sdk
orjson==3.10.12
orjson==3.10.15
# via langsmith
packaging==24.2
# via
Expand All @@ -336,7 +335,7 @@ proto-plus==1.25.0
# google-api-core
# google-cloud-aiplatform
# google-cloud-resource-manager
protobuf==5.29.2
protobuf==5.29.3
# via
# google-api-core
# google-cloud-aiplatform
Expand Down Expand Up @@ -372,7 +371,7 @@ pydantic-core==2.23.4
# via
# cohere
# pydantic
pydantic-settings==2.7.0
pydantic-settings==2.7.1
# via langchain-community
python-dateutil==2.9.0.post0
# via
Expand Down Expand Up @@ -413,11 +412,11 @@ requests-toolbelt==1.0.0
# via langsmith
rsa==4.9
# via google-auth
s3transfer==0.10.4
s3transfer==0.11.1
# via boto3
safetensors==0.4.5
safetensors==0.5.2
# via transformers
sentry-sdk==2.19.2
sentry-sdk==2.20.0
# via langtrace-python-sdk
shapely==2.0.6
# via google-cloud-aiplatform
Expand All @@ -428,9 +427,8 @@ six==1.17.0
sniffio==1.3.1
# via
# anyio
# httpx
# openai
sqlalchemy==2.0.36
sqlalchemy==2.0.37
# via
# langchain
# langchain-community
Expand Down Expand Up @@ -459,13 +457,15 @@ tqdm==4.67.1
# transformers
trace-attributes==7.1.0
# via langtrace-python-sdk
transformers==4.47.1
transformers==4.48.0
# via langtrace-python-sdk
types-requests==2.32.0.20241016
# via cohere
typing-extensions==4.12.2
# via
# anyio
# cohere
# google-cloud-aiplatform
# huggingface-hub
# langchain-core
# openai
Expand All @@ -481,7 +481,7 @@ tzdata==2024.2
# via pandas
ujson==5.10.0
# via langtrace-python-sdk
urllib3==2.2.3
urllib3==2.3.0
# via
# botocore
# elastic-transport
Expand All @@ -490,7 +490,7 @@ urllib3==2.2.3
# types-requests
werkzeug==3.1.3
# via flask
wrapt==1.17.0
wrapt==1.17.2
# via
# deprecated
# opentelemetry-instrumentation
Expand Down

0 comments on commit 050847c

Please sign in to comment.