diff --git a/README.md b/README.md index ab37cde1..fd85db80 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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. \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 084087df..729ba96f 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 \ No newline at end of file + - 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 diff --git a/otel-collector-config.yaml b/otel-collector-config.yaml new file mode 100644 index 00000000..7510cf14 --- /dev/null +++ b/otel-collector-config.yaml @@ -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] diff --git a/src/Dockerfile_otel b/src/Dockerfile_otel new file mode 100644 index 00000000..7b2a413e --- /dev/null +++ b/src/Dockerfile_otel @@ -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"] \ No newline at end of file diff --git a/src/requirements-otel.txt b/src/requirements-otel.txt new file mode 100644 index 00000000..8123dbba --- /dev/null +++ b/src/requirements-otel.txt @@ -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]