Skip to content

Commit 476503d

Browse files
authored
Instrument the sample application using CWOperator. (#44)
This PR Instrument the sample application using CWOperator by setting up following: 1. annotation: instrumentation.opentelemetry.io/inject-python: "true" 2. run the server with `--noreload` 3. Add `DJANGO_SETTINGS_MODULE` env variable. 4. Add `PYTHONPATH` env variable, this is required as CWOperator instrumentation when application is mount in a specific directory instead of root. 5. Add `OTEL_TRACES_SAMPLER`, this will be removed when Xray remote sampler is ready. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 9275ff9 commit 476503d

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

sample-applications/vehicle-dealership-sample-app/docker-compose.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ services:
2828
context: .
2929
dockerfile: VehicleInventoryApp/Dockerfile
3030
container_name: vehicle-inventory-backend
31-
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001"
31+
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001 --noreload"
3232
restart: always
3333
volumes:
3434
- ./VehicleInventoryApp/.:/vehicle-inventory-app
35+
environment:
36+
DJANGO_SETTINGS_MODULE: "VehicleInventoryApp.settings"
37+
OTEL_TRACES_SAMPLER: "always_on"
3538
ports:
3639
- "8001:8001"
3740
depends_on:
@@ -44,11 +47,14 @@ services:
4447
context: .
4548
dockerfile: ImageServiceApp/Dockerfile
4649
container_name: image-service-backend
47-
command: sh -c "python3 manage.py runserver 0.0.0.0:8000"
50+
command: sh -c "python3 manage.py runserver 0.0.0.0:8000 --noreload"
4851
restart: always
4952
volumes:
5053
- ./ImageServiceApp/.:/image-service-app
5154
- $HOME/.aws/credentials:/home/app/.aws/credentials:ro
55+
environment:
56+
DJANGO_SETTINGS_MODULE: "ImageServiceApp.settings"
57+
OTEL_TRACES_SAMPLER: "always_on"
5258
ports:
5359
- "8000:8000"
5460
depends_on:

sample-applications/vehicle-dealership-sample-app/eks/backend-deployment.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
annotations:
2323
kompose.cmd: kompose convert -f docker-compose.yaml
2424
kompose.version: 1.31.2 (HEAD)
25+
instrumentation.opentelemetry.io/inject-python: "true"
2526
creationTimestamp: null
2627
labels:
2728
io.kompose.network/vehicleinventoryapp-default: "true"
@@ -31,7 +32,7 @@ spec:
3132
- args:
3233
- sh
3334
- -c
34-
- python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001
35+
- python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001 --noreload
3536
image: ${REPOSITORY_PREFIX}/pythonsampleapp/vehicle-inventory-service:latest
3637
name: vehicle-inventory-backend
3738
env:
@@ -41,6 +42,13 @@ spec:
4142
value: ${POSTGRES_PASSWORD}
4243
- name: POSTGRES_USER
4344
value: djangouser
45+
- name: PYTHONPATH
46+
value: "/vehicle-inventory-app"
47+
- name: DJANGO_SETTINGS_MODULE
48+
value: "VehicleInventoryApp.settings"
49+
# TODO: Remove OTEL_TRACES_SAMPLER when XRay trace sampler is ready
50+
- name: OTEL_TRACES_SAMPLER
51+
value: "always_on"
4452
imagePullPolicy: Always
4553
ports:
4654
- containerPort: 8001

sample-applications/vehicle-dealership-sample-app/eks/image-backend-deployment.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
annotations:
2323
kompose.cmd: Kompose convert -f docker-compose.yaml
2424
kompose.version: 1.31.2 (HEAD)
25+
instrumentation.opentelemetry.io/inject-python: "true"
2526
creationTimestamp: null
2627
labels:
2728
io.kompose.network/imageserviceapp-default: "true"
@@ -31,7 +32,7 @@ spec:
3132
- args:
3233
- sh
3334
- -c
34-
- python3 manage.py runserver 0.0.0.0:8000
35+
- python3 manage.py runserver 0.0.0.0:8000 --noreload
3536
image: ${REPOSITORY_PREFIX}/pythonsampleapp/image-service:latest
3637
name: image-service-backend
3738
imagePullPolicy: Always
@@ -49,5 +50,12 @@ spec:
4950
value: ${POSTGRES_PASSWORD}
5051
- name: POSTGRES_USER
5152
value: djangouser
53+
- name: PYTHONPATH
54+
value: "/image-service-app"
55+
- name: DJANGO_SETTINGS_MODULE
56+
value: "ImageServiceApp.settings"
57+
# TODO: Remove OTEL_TRACES_SAMPLER when XRay trace sampler is ready
58+
- name: OTEL_TRACES_SAMPLER
59+
value: "always_on"
5260
restartPolicy: Always
5361
status: {}

0 commit comments

Comments
 (0)