From e9a4903df7d881dd25fa6f3ae2b8dc4030c12971 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 10:19:32 -0700 Subject: [PATCH 1/8] Updating Python sample app --- .github/workflows/python-ec2-default-test.yml | 2 +- .github/workflows/test.yml | 23 +++++++++++++++++++ .../frontend_service_app/views.py | 15 ++++++++---- terraform/python/ec2/default/main.tf | 8 +++---- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/python-ec2-default-test.yml b/.github/workflows/python-ec2-default-test.yml index 901fe8efb..02c1004c8 100644 --- a/.github/workflows/python-ec2-default-test.yml +++ b/.github/workflows/python-ec2-default-test.yml @@ -49,7 +49,7 @@ env: CPU_ARCHITECTURE: ${{ inputs.cpu-architecture }} ADOT_WHEEL_NAME: ${{ inputs.staging-wheel-name }} OTEL_SOURCE: ${{ inputs.otel-source }} - SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app.zip + SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app-delete-me.zip E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }} E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }} METRIC_NAMESPACE: ApplicationSignals diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..659065bfd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +## SPDX-License-Identifier: Apache-2.0 + +# This is a reusable workflow for running the Enablement test for App Signals. +# It is meant to be called from another workflow. +# Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview +name: Test +on: + push: + branches: + - Python_Custom_metrics + +permissions: + id-token: write + contents: read + +jobs: + python-ec2-default: + uses: ./.github/workflows/python-ec2-default-test.yml + secrets: inherit + with: + caller-workflow-name: 'test' + aws-region: 'us-east-1' \ No newline at end of file diff --git a/sample-apps/python/django_frontend_service/frontend_service_app/views.py b/sample-apps/python/django_frontend_service/frontend_service_app/views.py index 069a40092..c6176b61c 100644 --- a/sample-apps/python/django_frontend_service/frontend_service_app/views.py +++ b/sample-apps/python/django_frontend_service/frontend_service_app/views.py @@ -22,10 +22,17 @@ logger = logging.getLogger(__name__) # Custom export pipeline - runs alongside existing CWAgent & ADOT setup -pipeline_resource = Resource.create({ - "service.name": os.environ['SERVICE_NAME'], - "deployment.environment.name": os.environ['DEPLOYMENT_ENVIRONMENT_NAME'] -}) +# Set up variables for if statement to avoid app crashes on other platforms +service_name = os.environ.get('SERVICE_NAME') +deployment_environment_name = os.environ.get('DEPLOYMENT_ENVIRONMENT_NAME') +# if vars come back empty pipeline will assign value of 'None' +if service_name and deployment_environment_name: + pipeline_resource = Resource.create({ + "service.name": service_name, + "deployment.environment.name": deployment_environment_name + }) +else: + pipeline_resource = Resource.create({}) pipeline_metric_exporter = OTLPMetricExporter( endpoint="localhost:4317" diff --git a/terraform/python/ec2/default/main.tf b/terraform/python/ec2/default/main.tf index 1a826c1f1..233fe8d0b 100644 --- a/terraform/python/ec2/default/main.tf +++ b/terraform/python/ec2/default/main.tf @@ -161,8 +161,8 @@ resource "null_resource" "main_service_setup" { ${var.get_adot_wheel_command} # Get and run the sample application with configuration - aws s3 cp ${var.sample_app_zip} ./python-sample-app.zip - unzip -o python-sample-app.zip + aws s3 cp ${var.sample_app_zip} ./python-sample-app-delete-me.zip + unzip -o python-sample-app-delete-me.zip # Export environment variables for instrumentation cd ./django_frontend_service @@ -296,8 +296,8 @@ resource "null_resource" "remote_service_setup" { ${var.get_adot_wheel_command} # Get and run the sample application with configuration - aws s3 cp ${var.sample_app_zip} ./python-sample-app.zip - unzip -o python-sample-app.zip + aws s3 cp ${var.sample_app_zip} ./python-sample-app-delete-me.zip + unzip -o python-sample-app-delete-me.zip # Export environment variables for instrumentation cd ./django_remote_service From a281b0f5cbcb5a072eb7de619eecfac6df3e115d Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 11:23:41 -0700 Subject: [PATCH 2/8] removing test and delete-me files --- .github/workflows/python-ec2-default-test.yml | 2 +- .github/workflows/test.yml | 23 ------------------- terraform/python/ec2/default/main.tf | 8 +++---- 3 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/python-ec2-default-test.yml b/.github/workflows/python-ec2-default-test.yml index 02c1004c8..901fe8efb 100644 --- a/.github/workflows/python-ec2-default-test.yml +++ b/.github/workflows/python-ec2-default-test.yml @@ -49,7 +49,7 @@ env: CPU_ARCHITECTURE: ${{ inputs.cpu-architecture }} ADOT_WHEEL_NAME: ${{ inputs.staging-wheel-name }} OTEL_SOURCE: ${{ inputs.otel-source }} - SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app-delete-me.zip + SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app.zip E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }} E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }} METRIC_NAMESPACE: ApplicationSignals diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 659065bfd..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -## SPDX-License-Identifier: Apache-2.0 - -# This is a reusable workflow for running the Enablement test for App Signals. -# It is meant to be called from another workflow. -# Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview -name: Test -on: - push: - branches: - - Python_Custom_metrics - -permissions: - id-token: write - contents: read - -jobs: - python-ec2-default: - uses: ./.github/workflows/python-ec2-default-test.yml - secrets: inherit - with: - caller-workflow-name: 'test' - aws-region: 'us-east-1' \ No newline at end of file diff --git a/terraform/python/ec2/default/main.tf b/terraform/python/ec2/default/main.tf index 233fe8d0b..1a826c1f1 100644 --- a/terraform/python/ec2/default/main.tf +++ b/terraform/python/ec2/default/main.tf @@ -161,8 +161,8 @@ resource "null_resource" "main_service_setup" { ${var.get_adot_wheel_command} # Get and run the sample application with configuration - aws s3 cp ${var.sample_app_zip} ./python-sample-app-delete-me.zip - unzip -o python-sample-app-delete-me.zip + aws s3 cp ${var.sample_app_zip} ./python-sample-app.zip + unzip -o python-sample-app.zip # Export environment variables for instrumentation cd ./django_frontend_service @@ -296,8 +296,8 @@ resource "null_resource" "remote_service_setup" { ${var.get_adot_wheel_command} # Get and run the sample application with configuration - aws s3 cp ${var.sample_app_zip} ./python-sample-app-delete-me.zip - unzip -o python-sample-app-delete-me.zip + aws s3 cp ${var.sample_app_zip} ./python-sample-app.zip + unzip -o python-sample-app.zip # Export environment variables for instrumentation cd ./django_remote_service From c8d71e8a0d6ed687b87ac2c6018dfec24617d376 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 12:39:59 -0700 Subject: [PATCH 3/8] testing against failed test --- .../workflows/python-ec2-adot-sigv4-test.yml | 2 +- .github/workflows/test.yml | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/python-ec2-adot-sigv4-test.yml b/.github/workflows/python-ec2-adot-sigv4-test.yml index c6eca9cfb..060a3b433 100644 --- a/.github/workflows/python-ec2-adot-sigv4-test.yml +++ b/.github/workflows/python-ec2-adot-sigv4-test.yml @@ -118,7 +118,7 @@ jobs: terraform apply -auto-approve \ -var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \ -var="test_id=${{ env.TESTING_ID }}" \ - -var="sample_app_zip=s3://aws-appsignals-sample-app-prod-us-east-1/python-sample-app.zip" \ + -var="sample_app_zip=s3://aws-appsignals-sample-app-prod-us-east-1/python-sample-app-delete-me.zip" \ -var="get_adot_wheel_command=${{ env.GET_ADOT_WHEEL_COMMAND }}" \ -var="language_version=${{ env.PYTHON_VERSION }}" \ -var="cpu_architecture=${{ env.CPU_ARCHITECTURE }}" \ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..80c0f5fb4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +## SPDX-License-Identifier: Apache-2.0 + +# This is a reusable workflow for running the Enablement test for App Signals. +# It is meant to be called from another workflow. +# Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview +name: Test +on: + push: + branches: + - Python_Custom_metrics + +permissions: + id-token: write + contents: read + +jobs: + python-ec2-default: + uses: ./.github/workflows/python-ec2-adot-sigv4-test.yml + secrets: inherit + with: + caller-workflow-name: 'test' + aws-region: 'us-east-1' \ No newline at end of file From 3f6d25d89f1b7574039bfd3a6d74e287c3b471d9 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 12:41:38 -0700 Subject: [PATCH 4/8] removing taws-region --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80c0f5fb4..a0ea0d217 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,5 +19,4 @@ jobs: uses: ./.github/workflows/python-ec2-adot-sigv4-test.yml secrets: inherit with: - caller-workflow-name: 'test' - aws-region: 'us-east-1' \ No newline at end of file + caller-workflow-name: 'test' \ No newline at end of file From e0318b44f8fec3d10b31319f1a07b2c80831d7c6 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 12:58:48 -0700 Subject: [PATCH 5/8] Removing test files --- .../workflows/python-ec2-adot-sigv4-test.yml | 2 +- .github/workflows/test.yml | 22 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/python-ec2-adot-sigv4-test.yml b/.github/workflows/python-ec2-adot-sigv4-test.yml index 060a3b433..c6eca9cfb 100644 --- a/.github/workflows/python-ec2-adot-sigv4-test.yml +++ b/.github/workflows/python-ec2-adot-sigv4-test.yml @@ -118,7 +118,7 @@ jobs: terraform apply -auto-approve \ -var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \ -var="test_id=${{ env.TESTING_ID }}" \ - -var="sample_app_zip=s3://aws-appsignals-sample-app-prod-us-east-1/python-sample-app-delete-me.zip" \ + -var="sample_app_zip=s3://aws-appsignals-sample-app-prod-us-east-1/python-sample-app.zip" \ -var="get_adot_wheel_command=${{ env.GET_ADOT_WHEEL_COMMAND }}" \ -var="language_version=${{ env.PYTHON_VERSION }}" \ -var="cpu_architecture=${{ env.CPU_ARCHITECTURE }}" \ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index a0ea0d217..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -## SPDX-License-Identifier: Apache-2.0 - -# This is a reusable workflow for running the Enablement test for App Signals. -# It is meant to be called from another workflow. -# Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview -name: Test -on: - push: - branches: - - Python_Custom_metrics - -permissions: - id-token: write - contents: read - -jobs: - python-ec2-default: - uses: ./.github/workflows/python-ec2-adot-sigv4-test.yml - secrets: inherit - with: - caller-workflow-name: 'test' \ No newline at end of file From 74c3107ebbc52e35e9662fc61f83851b499e7165 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 14:38:13 -0700 Subject: [PATCH 6/8] reverting [Python/EC2] Add pipeline exporter for custom metrics testing --- .../frontend_service_app/views.py | 16 +---- terraform/python/ec2/default/main.tf | 4 +- .../default/aws-otel-custom-metrics.mustache | 70 +------------------ 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/sample-apps/python/django_frontend_service/frontend_service_app/views.py b/sample-apps/python/django_frontend_service/frontend_service_app/views.py index c6176b61c..11df78027 100644 --- a/sample-apps/python/django_frontend_service/frontend_service_app/views.py +++ b/sample-apps/python/django_frontend_service/frontend_service_app/views.py @@ -13,14 +13,10 @@ from django.http import HttpResponse, JsonResponse from opentelemetry import trace, metrics from opentelemetry.trace.span import format_trace_id -from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.metrics import MeterProvider -from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader -from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter -from opentelemetry.semconv.resource import ResourceAttributes logger = logging.getLogger(__name__) +<<<<<<< HEAD # Custom export pipeline - runs alongside existing CWAgent & ADOT setup # Set up variables for if statement to avoid app crashes on other platforms service_name = os.environ.get('SERVICE_NAME') @@ -51,16 +47,14 @@ pipeline_meter = pipeline_meter_provider.get_meter("myMeter") +======= +>>>>>>> parent of b4827da ([Python/EC2] Add pipeline exporter for custom metrics testing (#473)) #python equivalent of Meter meter = GlobalOpenTelemetry.getMeter("myMeter"); for custom metrics meter = metrics.get_meter("myMeter") agent_based_counter = meter.create_counter("agent_based_counter", unit="1", description="agent export counter") agent_based_histogram = meter.create_histogram("agent_based_histogram", description="agent export histogram") agent_based_gauge = meter.create_up_down_counter("agent_based_gauge", unit="1", description="agent export gauge") -custom_pipeline_counter = pipeline_meter.create_counter("custom_pipeline_counter", unit="1", description="pipeline export counter") -custom_pipeline_histogram = pipeline_meter.create_histogram("custom_pipeline_histogram", description="pipeline export histogram") -custom_pipeline_gauge = pipeline_meter.create_up_down_counter("custom_pipeline_gauge", unit="1", description="pipeline export gauge") - should_send_local_root_client_call = False lock = threading.Lock() @@ -102,10 +96,6 @@ def aws_sdk_call(request): agent_based_histogram.record(random.randint(100, 1000), {"Operation": "histogram"}) agent_based_gauge.add(random.randint(-10, 10), {"Operation": "gauge"}) - custom_pipeline_counter.add(1, {"Operation": "pipeline_counter"}) - custom_pipeline_histogram.record(random.randint(100, 1000), {"Operation": "pipeline_histogram"}) - custom_pipeline_gauge.add(random.randint(-10, 10), {"Operation": "pipeline_gauge"}) - bucket_name = "e2e-test-bucket-name" # Add a unique test ID to bucketname to associate buckets to specific test runs diff --git a/terraform/python/ec2/default/main.tf b/terraform/python/ec2/default/main.tf index 1a826c1f1..b78cb496a 100644 --- a/terraform/python/ec2/default/main.tf +++ b/terraform/python/ec2/default/main.tf @@ -179,10 +179,8 @@ resource "null_resource" "main_service_setup" { export OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=grpc export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=localhost:4317 export OTEL_EXPORTER_OTLP_METRICS_INSECURE=true - export SERVICE_NAME='python-sample-application-${var.test_id}' - export DEPLOYMENT_ENVIRONMENT_NAME='ec2:default' export OTEL_TRACES_SAMPLER=always_on - export OTEL_RESOURCE_ATTRIBUTES="service.name=$${SERVICE_NAME},deployment.environment.name=$${DEPLOYMENT_ENVIRONMENT_NAME}" + export OTEL_RESOURCE_ATTRIBUTES="service.name=python-sample-application-${var.test_id},deployment.environment.name=ec2:default" export AWS_REGION='${var.aws_region}' python${var.language_version} manage.py migrate nohup opentelemetry-instrument python${var.language_version} manage.py runserver 0.0.0.0:8000 --noreload & diff --git a/validator/src/main/resources/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache b/validator/src/main/resources/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache index 87d01942b..bd9b5cb32 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/default/aws-otel-custom-metrics.mustache @@ -156,72 +156,4 @@ value: ANY_VALUE - name: cloud.platform - value: aws_ec2 - -# Export pipeline metrics -- - metricName: custom_pipeline_counter - namespace: {{metricNamespace}} - dimensions: - - - name: deployment.environment.name - value: ec2:default - - - name: service.name - value: {{serviceName}} - - - name: Operation - value: pipeline_counter - - - name: telemetry.sdk.name - value: opentelemetry - - - name: telemetry.sdk.language - value: python - - - name: telemetry.sdk.version - value: ANY_VALUE -- - metricName: custom_pipeline_histogram - namespace: {{metricNamespace}} - dimensions: - - - name: deployment.environment.name - value: ec2:default - - - name: service.name - value: {{serviceName}} - - - name: Operation - value: pipeline_histogram - - - name: telemetry.sdk.name - value: opentelemetry - - - name: telemetry.sdk.language - value: python - - - name: telemetry.sdk.version - value: ANY_VALUE -- - metricName: custom_pipeline_gauge - namespace: {{metricNamespace}} - dimensions: - - - name: deployment.environment.name - value: ec2:default - - - name: service.name - value: {{serviceName}} - - - name: Operation - value: pipeline_gauge - - - name: telemetry.sdk.name - value: opentelemetry - - - name: telemetry.sdk.language - value: python - - - name: telemetry.sdk.version - value: ANY_VALUE \ No newline at end of file + value: aws_ec2 \ No newline at end of file From 29411a4881cb3f6d1c7d5bb30b44f0fbc7a57e15 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 14:38:40 -0700 Subject: [PATCH 7/8] adding missed file --- .../frontend_service_app/views.py | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/sample-apps/python/django_frontend_service/frontend_service_app/views.py b/sample-apps/python/django_frontend_service/frontend_service_app/views.py index 11df78027..c8e24dcf9 100644 --- a/sample-apps/python/django_frontend_service/frontend_service_app/views.py +++ b/sample-apps/python/django_frontend_service/frontend_service_app/views.py @@ -16,39 +16,6 @@ logger = logging.getLogger(__name__) -<<<<<<< HEAD -# Custom export pipeline - runs alongside existing CWAgent & ADOT setup -# Set up variables for if statement to avoid app crashes on other platforms -service_name = os.environ.get('SERVICE_NAME') -deployment_environment_name = os.environ.get('DEPLOYMENT_ENVIRONMENT_NAME') -# if vars come back empty pipeline will assign value of 'None' -if service_name and deployment_environment_name: - pipeline_resource = Resource.create({ - "service.name": service_name, - "deployment.environment.name": deployment_environment_name - }) -else: - pipeline_resource = Resource.create({}) - -pipeline_metric_exporter = OTLPMetricExporter( - endpoint="localhost:4317" -) - -pipeline_metric_reader = PeriodicExportingMetricReader( - exporter=pipeline_metric_exporter, - export_interval_millis=1000 -) - -pipeline_meter_provider = MeterProvider( - resource=pipeline_resource, - metric_readers=[pipeline_metric_reader] -) - -pipeline_meter = pipeline_meter_provider.get_meter("myMeter") - - -======= ->>>>>>> parent of b4827da ([Python/EC2] Add pipeline exporter for custom metrics testing (#473)) #python equivalent of Meter meter = GlobalOpenTelemetry.getMeter("myMeter"); for custom metrics meter = metrics.get_meter("myMeter") agent_based_counter = meter.create_counter("agent_based_counter", unit="1", description="agent export counter") From 1c53f14e9db368be7c57528cb1660a9700573051 Mon Sep 17 00:00:00 2001 From: Vherremi Date: Thu, 30 Oct 2025 14:49:09 -0700 Subject: [PATCH 8/8] updating views.py --- .../django_frontend_service/frontend_service_app/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample-apps/python/django_frontend_service/frontend_service_app/views.py b/sample-apps/python/django_frontend_service/frontend_service_app/views.py index c8e24dcf9..c38e88e32 100644 --- a/sample-apps/python/django_frontend_service/frontend_service_app/views.py +++ b/sample-apps/python/django_frontend_service/frontend_service_app/views.py @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) -#python equivalent of Meter meter = GlobalOpenTelemetry.getMeter("myMeter"); for custom metrics +#python equivalent of Meter meter = GlobalOpenTelemetry.getMeter("myMeter"); for custom metrics. meter = metrics.get_meter("myMeter") agent_based_counter = meter.create_counter("agent_based_counter", unit="1", description="agent export counter") agent_based_histogram = meter.create_histogram("agent_based_histogram", description="agent export histogram")