Skip to content

Commit 596f674

Browse files
committed
update sample app
1 parent 19c187a commit 596f674

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

.github/workflows/python-sample-app-s3-deploy.yml

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
name: Sample App Deployment - Python S3
55
on:
66
workflow_dispatch: # be able to run the workflow on demand
7+
push:
8+
branches:
9+
- python-genesis-app-metrics-fix
710

811
permissions:
912
id-token: write
@@ -46,24 +49,40 @@ jobs:
4649
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ secrets.E2E_TEST_ROLE_ARN }}
4750
aws-region: ${{ matrix.aws-region }}
4851

49-
- name: Build Sample App Zip
50-
working-directory: sample-apps/python
51-
run: zip -r python-sample-app.zip .
52+
# - name: Build Sample App Zip
53+
# working-directory: sample-apps/python
54+
# run: zip -r python-sample-app.zip .
5255

53-
- name: Upload to S3
54-
working-directory: sample-apps/python
55-
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./python-sample-app.zip --key python-sample-app.zip
56+
# - name: Upload to S3
57+
# working-directory: sample-apps/python
58+
# run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./python-sample-app.zip --key python-sample-app.zip
5659

57-
- name: Build Lambda Sample App
58-
uses: actions/checkout@v4
59-
with:
60-
repository: 'aws-observability/aws-otel-python-instrumentation'
61-
- name: Build sample lambda function
62-
shell: bash
63-
run: ./package-lambda-function.sh
64-
working-directory: lambda-layer/sample-apps
65-
66-
- name: Upload to Lambda Sample App to S3
67-
working-directory: lambda-layer/sample-apps
68-
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./build/function.zip --key pyfunction.zip
60+
# - name: Build Lambda Sample App
61+
# uses: actions/checkout@v4
62+
# with:
63+
# repository: 'aws-observability/aws-otel-python-instrumentation'
64+
# - name: Build sample lambda function
65+
# shell: bash
66+
# run: ./package-lambda-function.sh
67+
# working-directory: lambda-layer/sample-apps
68+
69+
# - name: Upload to Lambda Sample App to S3
70+
# working-directory: lambda-layer/sample-apps
71+
# run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./build/function.zip --key pyfunction.zip
72+
73+
# - name: Build Sample App Zip
74+
# working-directory: sample-apps/python
75+
# run: zip -r python-sample-app.zip .
76+
77+
# - name: Upload to S3
78+
# working-directory: sample-apps/python
79+
# run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./python-sample-app.zip --key python-sample-app.zip
80+
81+
- name: Build Gen AI Sample App Zip
82+
working-directory: sample-apps/python-gen-ai
83+
run: zip -r python-gen-ai-sample-app.zip .
84+
85+
- name: Upload Gen AI Sample App to S3
86+
working-directory: sample-apps/python-gen-ai
87+
run: aws s3api put-object --bucket ${{ secrets.APP_SIGNALS_E2E_EC2_JAR }}-prod-${{ matrix.aws-region }} --body ./python-gen-ai-sample-app.zip --key python-gen-ai-sample-app.zip
6988

sample-apps/python/genai_service/server.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from langchain_aws import ChatBedrock
77
from langchain.prompts import ChatPromptTemplate
88
from langchain.chains import LLMChain
9-
from opentelemetry import trace
9+
from opentelemetry import trace, metrics
1010
from opentelemetry.sdk.trace import TracerProvider
1111
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
1212
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
1313
from openinference.instrumentation.langchain import LangChainInstrumentor
14+
import random
1415

1516
# Load environment variables
1617
load_dotenv()
@@ -92,7 +93,15 @@ async def chat(request: ChatRequest):
9293
"""
9394
Chat endpoint that processes a single user message through AWS Bedrock
9495
"""
96+
9597
try:
98+
# Emit OTel Metrics
99+
meter = metrics.get_meter("genesis-meter", "1.0.0")
100+
request_duration = meter.create_histogram(
101+
name="Genesis_TestMetrics", description="Genesis request duration", unit="s"
102+
)
103+
request_duration.record(0.1 + (0.5 * random.random()), {"method": "GET", "status": "200"})
104+
96105
# Process the input through the chain
97106
result = await chain.ainvoke({"input": request.message})
98107
return ChatResponse(response=result["text"])

0 commit comments

Comments
 (0)