Skip to content

feat: AWS OpenTelemetry Support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ AzureOpenAI-compatible RESTful APIs for Amazon Bedrock.
This is a fork project from [Bedrock Access Gateway](https://github.com/aws-samples/bedrock-access-gateway), with the dedicated support for **AzureOpenAI** client instead of **OpenAI** client.

**Enhanced Features:**

- [x] AzureOpenAI client
- [x] Deployment on Amazon EKS
- [x] [JSON mode](https://learn.microsoft.com/sv-se/azure/ai-services/openai/how-to/json-mode?tabs=python) response format
- [x] [AWS Distro for OpenTelemetry](https://aws-otel.github.io/) support, helps on debugging and observability.

## Setup
### Happy path for testing
Expand Down Expand Up @@ -42,7 +44,7 @@ make build

Make sure to update the image of the k8s deployment under `deployment/k8s/manifest.yaml`, and run `make deploy` to deploy again.

> [!INFO]
> [!TIP]
> Feel free to change the region within the `scripts/push-to-ecr.sh` if you want to change the target ECR repo name and region.

### Verification
Expand Down Expand Up @@ -330,4 +332,4 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform

## License

This library is licensed under the MIT-0 License. See the LICENSE file.
This library is licensed under the MIT-0 License. See the LICENSE file.
37 changes: 33 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
version: '3'
# version: '3'
services:
gateway:
build:
context: ./src
dockerfile: Dockerfile
dockerfile: Dockerfile_otel
ports:
- 8000:80
volumes:
- ./src/:/app/
- ~/.aws:/root/.aws # If not provide AWS credentials from .env, just load your local AWS credentails
command: ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "80", "--reload"]
# command: ["opentelemetry-instrument","uvicorn","api.app:app","--port","8000","--host","0.0.0.0", "--reload"] # reload is not working with Otel instrumented app
command: ["opentelemetry-instrument","uvicorn","api.app:app","--port","8000","--host","0.0.0.0"]
env_file:
- .env
environment:
- DEBUG=true
- AWS_REGION=us-east-1
- AWS_PROFILE=account-b-us
- AWS_PROFILE=bedrock
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
depends_on:
- otel-collector
networks:
- app-network
otel-collector:
image: public.ecr.aws/aws-observability/aws-otel-collector:latest
command: ["--config=/etc/otel-collector-config.yaml"]
volumes:
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
- ~/.aws:/home/aoc/.aws
ports:
- "4317:4317" # OTLP gRPC receiver
- "4318:4318" # OTLP HTTP receiver
- "8888:8888" # Prometheus metrics exposed by the collector
- "8889:8889" # Prometheus exporter metrics
- "13133:13133" # Health check extension
environment:
- AWS_REGION=us-west-2
- AWS_PROFILE=default
- AWS_SDK_LOAD_CONFIG=1
- AWS_CONFIG_FILE=/home/aoc/.aws/config
- AWS_SHARED_CREDENTIALS_FILE=/home/aoc/.aws/credentials
networks:
- app-network
networks:
app-network:
driver: bridge
27 changes: 27 additions & 0 deletions otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

processors:
batch:

exporters:
awsxray:
region: "us-west-2"
logging:
verbosity: detailed

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [awsxray]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [logging]
13 changes: 13 additions & 0 deletions src/Dockerfile_otel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.12-slim

WORKDIR /app

COPY ./requirements-otel.txt /app/requirements-otel.txt

RUN pip install --no-cache-dir --upgrade -r /app/requirements-otel.txt

COPY ./api /app/api

RUN opentelemetry-bootstrap --action=install

CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "8000"]
14 changes: 14 additions & 0 deletions src/requirements-otel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fastapi==0.111.0
pydantic==2.7.1
uvicorn==0.29.0
mangum==0.17.0
tiktoken==0.6.0
requests==2.32.3
numpy==1.26.4
boto3==1.35.17
botocore==1.35.17
opentelemetry-api==1.27.0
opentelemetry-sdk==1.27.0
opentelemetry-sdk-extension-aws==2.0.2
opentelemetry-propagator-aws-xray==1.0.2
opentelemetry-distro[otlp]
Loading