Skip to content

Commit

Permalink
Add Instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhlogin committed Jan 25, 2024
1 parent 3c822a8 commit fac6ce2
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def build(self) -> AwsSpanMetricsProcessor:
error_histogram: Histogram = meter.create_histogram(_ERROR)
fault_histogram: Histogram = meter.create_histogram(_FAULT)
latency_histogram: Histogram = meter.create_histogram(_LATENCY, unit=_LATENCY_UNITS)
error_histogram.name = _ERROR
fault_histogram.name = _FAULT
latency_histogram.name = _LATENCY

return AwsSpanMetricsProcessor(
error_histogram, fault_histogram, latency_histogram, self._generator, self._resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ WORKDIR /image-service-app

# Install dependencies
COPY ImageServiceApp/requirements.txt /image-service-app/
RUN pip install -r requirements.txt
COPY ImageServiceApp/aws_opentelemetry_distro-0.0.1-py3-none-any.whl /image-service-app/
COPY ImageServiceApp/opentelemetry_sdk_extension_aws-2.0.1-py3-none-any.whl /image-service-app/

RUN pip install -r requirements.txt && pip install aws_opentelemetry_distro-0.0.1-py3-none-any.whl && pip install opentelemetry_sdk_extension_aws-2.0.1-py3-none-any.whl

# Copy the project code into the container
COPY ImageServiceApp/. /image-service-app/
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
Django~=5.0
requests~=2.31.0
boto3~=1.34.14
python-dotenv~=1.0.0
python-dotenv~=1.0.0
chardet~=5.2.0
opentelemetry-distro==0.43b0
# We don't use the distro[otlp] option which automatically includes exporters since gRPC is not appropriate for
# injected auto-instrumentation, where it has a strict dependency on the OS / Python version the artifact is built for.
opentelemetry-exporter-otlp-proto-http==1.22.0

opentelemetry-propagator-b3==1.22.0
opentelemetry-propagator-jaeger==1.22.0
opentelemetry-propagator-aws-xray==1.0.1

opentelemetry-instrumentation==0.43b0
opentelemetry-propagator-ot-trace==0.43b0

# Copied in from https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation
opentelemetry-instrumentation-aws-lambda==0.43b0
opentelemetry-instrumentation-aio-pika==0.43b0
opentelemetry-instrumentation-aiohttp-client==0.43b0
opentelemetry-instrumentation-aiopg==0.43b0
opentelemetry-instrumentation-asgi==0.43b0
opentelemetry-instrumentation-asyncpg==0.43b0
opentelemetry-instrumentation-boto==0.43b0
opentelemetry-instrumentation-boto3sqs==0.43b0
opentelemetry-instrumentation-botocore==0.43b0
opentelemetry-instrumentation-celery==0.43b0
opentelemetry-instrumentation-confluent-kafka==0.43b0
opentelemetry-instrumentation-dbapi==0.43b0
opentelemetry-instrumentation-django==0.43b0
opentelemetry-instrumentation-elasticsearch==0.43b0
opentelemetry-instrumentation-falcon==0.43b0
opentelemetry-instrumentation-fastapi==0.43b0
opentelemetry-instrumentation-flask==0.43b0
opentelemetry-instrumentation-grpc==0.43b0
opentelemetry-instrumentation-httpx==0.43b0
opentelemetry-instrumentation-jinja2==0.43b0
opentelemetry-instrumentation-kafka-python==0.43b0
opentelemetry-instrumentation-logging==0.43b0
opentelemetry-instrumentation-mysql==0.43b0
opentelemetry-instrumentation-mysqlclient==0.43b0
opentelemetry-instrumentation-pika==0.43b0
opentelemetry-instrumentation-psycopg2==0.43b0
opentelemetry-instrumentation-pymemcache==0.43b0
opentelemetry-instrumentation-pymongo==0.43b0
opentelemetry-instrumentation-pymysql==0.43b0
opentelemetry-instrumentation-pyramid==0.43b0
opentelemetry-instrumentation-redis==0.43b0
opentelemetry-instrumentation-remoulade==0.43b0
opentelemetry-instrumentation-requests==0.43b0
opentelemetry-instrumentation-sklearn==0.43b0
opentelemetry-instrumentation-sqlalchemy==0.43b0
opentelemetry-instrumentation-sqlite3==0.43b0
opentelemetry-instrumentation-starlette==0.43b0
opentelemetry-instrumentation-system-metrics==0.43b0
opentelemetry-instrumentation-tornado==0.43b0
opentelemetry-instrumentation-tortoiseorm==0.43b0
opentelemetry-instrumentation-urllib==0.43b0
opentelemetry-instrumentation-urllib3==0.43b0
opentelemetry-instrumentation-wsgi==0.43b0
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ WORKDIR /vehicle-inventory-app

# Install dependencies
COPY VehicleInventoryApp/requirements.txt /vehicle-inventory-app/
RUN pip install -r requirements.txt
COPY VehicleInventoryApp/aws_opentelemetry_distro-0.0.1-py3-none-any.whl /vehicle-inventory-app/
COPY VehicleInventoryApp/opentelemetry_sdk_extension_aws-2.0.1-py3-none-any.whl /vehicle-inventory-app/

RUN pip install -r requirements.txt && pip install aws_opentelemetry_distro-0.0.1-py3-none-any.whl && pip install opentelemetry_sdk_extension_aws-2.0.1-py3-none-any.whl

# Copy the project code into the container
COPY VehicleInventoryApp/. /vehicle-inventory-app/
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
Django~=5.0
requests~=2.31.0
mysqlclient~=2.2.1
python-dotenv~=1.0.0
python-dotenv~=1.0.0
opentelemetry-distro==0.43b0
# We don't use the distro[otlp] option which automatically includes exporters since gRPC is not appropriate for
# injected auto-instrumentation, where it has a strict dependency on the OS / Python version the artifact is built for.
opentelemetry-exporter-otlp-proto-http==1.22.0

opentelemetry-propagator-b3==1.22.0
opentelemetry-propagator-jaeger==1.22.0
opentelemetry-propagator-aws-xray==1.0.1

opentelemetry-instrumentation==0.43b0
opentelemetry-propagator-ot-trace==0.43b0

# Copied in from https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation
opentelemetry-instrumentation-aws-lambda==0.43b0
opentelemetry-instrumentation-aio-pika==0.43b0
opentelemetry-instrumentation-aiohttp-client==0.43b0
opentelemetry-instrumentation-aiopg==0.43b0
opentelemetry-instrumentation-asgi==0.43b0
opentelemetry-instrumentation-asyncpg==0.43b0
opentelemetry-instrumentation-boto==0.43b0
opentelemetry-instrumentation-boto3sqs==0.43b0
opentelemetry-instrumentation-botocore==0.43b0
opentelemetry-instrumentation-celery==0.43b0
opentelemetry-instrumentation-confluent-kafka==0.43b0
opentelemetry-instrumentation-dbapi==0.43b0
opentelemetry-instrumentation-django==0.43b0
opentelemetry-instrumentation-elasticsearch==0.43b0
opentelemetry-instrumentation-falcon==0.43b0
opentelemetry-instrumentation-fastapi==0.43b0
opentelemetry-instrumentation-flask==0.43b0
opentelemetry-instrumentation-grpc==0.43b0
opentelemetry-instrumentation-httpx==0.43b0
opentelemetry-instrumentation-jinja2==0.43b0
opentelemetry-instrumentation-kafka-python==0.43b0
opentelemetry-instrumentation-logging==0.43b0
opentelemetry-instrumentation-mysql==0.43b0
opentelemetry-instrumentation-mysqlclient==0.43b0
opentelemetry-instrumentation-pika==0.43b0
opentelemetry-instrumentation-psycopg2==0.43b0
opentelemetry-instrumentation-pymemcache==0.43b0
opentelemetry-instrumentation-pymongo==0.43b0
opentelemetry-instrumentation-pymysql==0.43b0
opentelemetry-instrumentation-pyramid==0.43b0
opentelemetry-instrumentation-redis==0.43b0
opentelemetry-instrumentation-remoulade==0.43b0
opentelemetry-instrumentation-requests==0.43b0
opentelemetry-instrumentation-sklearn==0.43b0
opentelemetry-instrumentation-sqlalchemy==0.43b0
opentelemetry-instrumentation-sqlite3==0.43b0
opentelemetry-instrumentation-starlette==0.43b0
opentelemetry-instrumentation-system-metrics==0.43b0
opentelemetry-instrumentation-tornado==0.43b0
opentelemetry-instrumentation-tortoiseorm==0.43b0
opentelemetry-instrumentation-urllib==0.43b0
opentelemetry-instrumentation-urllib3==0.43b0
opentelemetry-instrumentation-wsgi==0.43b0
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ services:
context: .
dockerfile: VehicleInventoryApp/Dockerfile
container_name: vehicle-inventory-backend
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001"
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && opentelemetry-instrument python3 manage.py runserver 0.0.0.0:8001 --noreload"
restart: always
volumes:
- ./VehicleInventoryApp/.:/vehicle-inventory-app
environment:
OTEL_SERVICE_NAME: "VehicleInventoryApp"
OTEL_METRICS_EXPORTER: "none"
OTEL_SMP_ENABLED: "true"
OTEL_PYTHON_DISTRO: "aws_distro"
OTEL_PYTHON_CONFIGURATOR: "aws_configurator"
DJANGO_SETTINGS_MODULE: "VehicleInventoryApp.settings"
OTEL_AWS_SMP_EXPORTER_ENDPOINT: "http://cloudwatch-agent.amazon-cloudwatch:4315"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://cloudwatch-agent.amazon-cloudwatch:4315"
OTEL_TRACES_SAMPLER: "always_on"
ports:
- "8001:8001"
depends_on:
Expand All @@ -44,11 +54,21 @@ services:
context: .
dockerfile: ImageServiceApp/Dockerfile
container_name: image-service-backend
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8000"
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && opentelemetry-instrument python3 manage.py runserver 0.0.0.0:8000 --noreload"
restart: always
volumes:
- ./ImageServiceApp/.:/image-service-app
- $HOME/.aws/credentials:/home/app/.aws/credentials:ro
environment:
OTEL_SERVICE_NAME: "ImageServiceApp"
OTEL_METRICS_EXPORTER: "none"
OTEL_SMP_ENABLED: "true"
OTEL_PYTHON_DISTRO: "aws_distro"
OTEL_PYTHON_CONFIGURATOR: "aws_configurator"
DJANGO_SETTINGS_MODULE: "ImageServiceApp.settings"
OTEL_AWS_SMP_EXPORTER_ENDPOINT: "http://cloudwatch-agent.amazon-cloudwatch:4315"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://cloudwatch-agent.amazon-cloudwatch:4315"
OTEL_TRACES_SAMPLER: "always_on"
ports:
- "8000:8000"
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
- args:
- sh
- -c
- python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python3 manage.py runserver 0.0.0.0:8001
- python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && opentelemetry-instrument python3 manage.py runserver 0.0.0.0:8001 --noreload
image: ${REPOSITORY_PREFIX}/pythonsampleapp/vehicle-inventory-service:latest
name: vehicle-inventory-backend
env:
Expand All @@ -43,6 +43,24 @@ spec:
value: ${MYSQL_PASSWORD}
- name: MYSQL_USER
value: djangouser
- name: OTEL_SERVICE_NAME
value: "VehicleInventoryApp"
- name: OTEL_SMP_ENABLED
value: "true"
- name: OTEL_PYTHON_DISTRO
value: "aws_distro"
- name: OTEL_PYTHON_CONFIGURATOR
value: "aws_configurator"
- name: DJANGO_SETTINGS_MODULE
value: "VehicleInventoryApp.settings"
- name: OTEL_AWS_SMP_EXPORTER_ENDPOINT
value: "http://cloudwatch-agent.amazon-cloudwatch:4315"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://cloudwatch-agent.amazon-cloudwatch:4315"
- name: OTEL_METRICS_EXPORTER
value: "none"
- name: OTEL_TRACES_SAMPLER
value: "always_on"
imagePullPolicy: Always
ports:
- containerPort: 8001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
storage: 1Gi
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
- args:
- sh
- -c
- python3 manage.py migrate --noinput; python3 manage.py collectstatic --noinput; python3 manage.py runserver 0.0.0.0:8000
- python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && opentelemetry-instrument python3 manage.py runserver 0.0.0.0:8000 --noreload
image: ${REPOSITORY_PREFIX}/pythonsampleapp/image-service:latest
name: image-service-backend
imagePullPolicy: Always
Expand All @@ -43,5 +43,23 @@ spec:
env:
- name: S3_BUCKET
value: ${S3_BUCKET}
- name: OTEL_SERVICE_NAME
value: "ImageServiceApp"
- name: OTEL_PYTHON_DISTRO
value: "aws_distro"
- name: OTEL_PYTHON_CONFIGURATOR
value: "aws_configurator"
- name: DJANGO_SETTINGS_MODULE
value: "ImageServiceApp.settings"
- name: OTEL_AWS_SMP_EXPORTER_ENDPOINT
value: "http://cloudwatch-agent.amazon-cloudwatch:4315"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://cloudwatch-agent.amazon-cloudwatch:4315"
- name: OTEL_SMP_ENABLED
value: "true"
- name: OTEL_METRICS_EXPORTER
value: "none"
- name: OTEL_TRACES_SAMPLER
value: "always_on"
restartPolicy: Always
status: {}

0 comments on commit fac6ce2

Please sign in to comment.