Skip to content

Commit 73d7884

Browse files
authored
Merge branch 'main' into dependabot/pip/contract-tests/images/applications/django/django-5.0.9
2 parents 3247831 + 042edf1 commit 73d7884

21 files changed

+541
-47
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Push aws-opentelemetry-python-distro Layer
2+
description: |
3+
This action assumes that the repo was checked out. Builds and push Lambda Layer and sample app to S3 bucket for
4+
the further end to end tests.
5+
6+
inputs:
7+
aws-region:
8+
required: false
9+
description: "AWS Region, required only if push_image is true"
10+
snapshot-ecr-role:
11+
required: false
12+
description: "IAM Role used for pushing to snapshot ecr, required only if push_image is true"
13+
python_version:
14+
required: true
15+
description: "The python version used in actions"
16+
layer_directory:
17+
required: true
18+
description: 'The role use to publish lambda layer'
19+
staging_s3_bucket:
20+
required: true
21+
description: 'S3 bucket holds SDK artifact tarball'
22+
os:
23+
required: true
24+
description: "The os"
25+
26+
27+
runs:
28+
using: "composite"
29+
steps:
30+
- name: Build sample lambda function
31+
shell: bash
32+
working-directory: ${{ inputs.layer_directory }}/sample-apps
33+
run: ./package-lambda-function.sh
34+
- name: Build layers
35+
shell: bash
36+
working-directory: ${{ inputs.layer_directory }}/src
37+
run: |
38+
./build-lambda-layer.sh
39+
pip install tox
40+
tox
41+
- name: Upload Layer to S3
42+
shell: bash
43+
run: |
44+
aws s3 cp ./build/aws-opentelemetry-python-layer.zip s3://${{ inputs.staging_s3_bucket }}/layer-${{ github.run_id }}.zip
45+
working-directory: ${{ inputs.layer_directory }}/src
46+
- name: Upload Sample App to S3
47+
shell: bash
48+
run: |
49+
aws s3 cp ./build/function.zip s3://${{ inputs.staging_s3_bucket }}/function-${{ github.run_id }}.zip
50+
working-directory: ${{ inputs.layer_directory }}/sample-apps

.github/workflows/application-signals-e2e-test.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
python-version: '3.12'
101101
cpu-architecture: 'x86_64'
102102
staging-wheel-name: ${{ inputs.staging-wheel-name }}
103-
103+
104104
#
105105
# DOCKER DISTRIBUTION LANGUAGE VERSION COVERAGE
106106
# DEFAULT SETTING: {Python Version}, EKS, AMD64, AL2
@@ -174,7 +174,7 @@ jobs:
174174
caller-workflow-name: 'main-build'
175175
python-version: '3.9'
176176
staging-wheel-name: ${{ inputs.staging-wheel-name }}
177-
177+
178178
#
179179
# DOCKER DISTRIBUTION PLATFORM COVERAGE
180180
# DEFAULT SETTING: Python 3.10, {Platform}, AMD64, AL2
@@ -215,5 +215,12 @@ jobs:
215215
cpu-architecture: 'arm64'
216216
staging-wheel-name: ${{ inputs.staging-wheel-name }}
217217

218-
219-
218+
#
219+
# Lambda layer integration tests
220+
lambda:
221+
uses: aws-observability/aws-application-signals-test-framework/.github/workflows/python-lambda-test.yml@main
222+
secrets: inherit
223+
with:
224+
aws-region: us-east-1
225+
python-version: '3.12'
226+
caller-workflow-name: 'main-build'

.github/workflows/daily_scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ jobs:
8282
id: high_scan
8383
uses: ./.github/actions/image_scan
8484
with:
85-
image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.5.0"
85+
image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.6.0"
8686
severity: 'CRITICAL,HIGH'
8787

8888
- name: Perform low image scan
8989
if: always()
9090
id: low_scan
9191
uses: ./.github/actions/image_scan
9292
with:
93-
image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.5.0"
93+
image-ref: "public.ecr.aws/aws-observability/adot-autoinstrumentation-python:v0.6.0"
9494
severity: 'MEDIUM,LOW,UNKNOWN'
9595

9696
- name: Configure AWS Credentials for emitting metrics

.github/workflows/main_build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- main
77
- "release/v*"
8+
- ci-workflow
89
workflow_dispatch: # be able to run the workflow on demand
910
env:
1011
AWS_DEFAULT_REGION: us-east-1
@@ -71,6 +72,16 @@ jobs:
7172
cd ./dist
7273
cp aws_opentelemetry_distro-${{ steps.python_output.outputs.ADOT_PYTHON_VERSION}}-py3-none-any.whl $staging_wheel
7374
75+
- name: Build and Publish Lambda Staging Layer
76+
uses: ./.github/actions/lambda_artifacts_build
77+
with:
78+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
79+
snapshot-ecr-role: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
80+
python_version: "3.12"
81+
layer_directory: lambda-layer
82+
staging_s3_bucket: ${{ env.STAGING_S3_BUCKET }}
83+
os: ubuntu-latest
84+
7485
- name: Upload wheel to S3
7586
run: |
7687
aws s3 cp dist/${{ steps.staging_wheel_output.outputs.STAGING_WHEEL}} s3://${{ env.STAGING_S3_BUCKET }}

.github/workflows/release_lambda.yml

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ on:
1010

1111
env:
1212
COMMERCIAL_REGIONS: us-east-1, us-east-2, us-west-1, us-west-2, ap-south-1, ap-northeast-3, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-northeast-1, ca-central-1, eu-central-1, eu-west-1, eu-west-2, eu-west-3, eu-north-1, sa-east-1
13-
# LAYER_NAME: AWSOpenTelemetryDistroPython
14-
LAYER_NAME: AWSOpenTelemetryDistroPythonBeta
13+
LAYER_NAME: AWSOpenTelemetryDistroPython
1514

1615
permissions:
1716
id-token: write
@@ -56,7 +55,6 @@ jobs:
5655
needs: build-layer
5756
strategy:
5857
matrix:
59-
# aws_region: ${{ fromJson(github.event.inputs.aws_region) }}
6058
aws_region: ${{ fromJson(needs.build-layer.outputs.aws_regions_json) }}
6159
steps:
6260
- name: role arn
@@ -112,7 +110,6 @@ jobs:
112110
mkdir ${{ env.LAYER_NAME }}
113111
echo $layerARN > ${{ env.LAYER_NAME }}/${{ matrix.aws_region }}
114112
cat ${{ env.LAYER_NAME }}/${{ matrix.aws_region }}
115-
pwd
116113
- name: public layer
117114
run: |
118115
layerVersion=$(
@@ -193,21 +190,39 @@ jobs:
193190
run: |
194191
git config user.name "github-actions[bot]"
195192
git config user.email "github-actions[bot]@users.noreply.github.com"
196-
git checkout -b "release-lambda-${{ github.run_id }}"
197193
mv layer.tf lambda-layer/terraform/lambda/
198194
git add lambda-layer/terraform/lambda/layer.tf
199195
git commit -m "Update Lambda layer ARNs for releasing" || echo "No changes to commit"
200-
git push --set-upstream origin "release-lambda-${{ github.run_id }}"
201-
- name: Create Pull Request
196+
git push
197+
create-release:
198+
runs-on: ubuntu-latest
199+
needs: generate-release-note
200+
steps:
201+
- name: Checkout Repo @ SHA - ${{ github.sha }}
202+
uses: actions/checkout@v4
203+
- name: Get latest commit SHA
204+
run: |
205+
echo "COMMIT_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
206+
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
207+
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
208+
- name: Create Tag
209+
run: |
210+
git config user.name "github-actions[bot]"
211+
git config user.email "github-actions[bot]@users.noreply.github.com"
212+
TAG_NAME="lambda-${SHORT_SHA}"
213+
git tag -a "$TAG_NAME" -m "Release Lambda layer based on commit $TAG_NAME"
214+
git push origin "$TAG_NAME"
215+
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV
216+
env:
217+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
- name: Create Release
219+
id: create_release
220+
uses: actions/create-release@v1
202221
env:
203222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
204-
uses: peter-evans/create-pull-request@v5
205223
with:
206-
token: ${{ secrets.GITHUB_TOKEN }}
207-
commit-message: "Update Lambda layer ARNs for releasing"
208-
title: "Update Layer layer ARNs for releasing"
209-
body: |
210-
This PR updates the layer.tf file for the AWS region `${{ matrix.aws_region }}`.
211-
branch: release-lambda-${{ github.run_id }}
212-
base: main
213-
224+
tag_name: ${{ env.TAG_NAME }}
225+
release_name: "Release AWSOpenTelemetryDistroPython Lambda Layer"
226+
body_path: lambda-layer/terraform/lambda/layer.tf
227+
draft: true
228+
prerelease: false

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_attribute_keys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
AWS_BEDROCK_KNOWLEDGE_BASE_ID: str = "aws.bedrock.knowledge_base.id"
2424
AWS_BEDROCK_AGENT_ID: str = "aws.bedrock.agent.id"
2525
AWS_BEDROCK_GUARDRAIL_ID: str = "aws.bedrock.guardrail.id"
26+
AWS_BEDROCK_GUARDRAIL_ARN: str = "aws.bedrock.guardrail.arn"
2627
AWS_SECRETSMANAGER_SECRET_ARN: str = "aws.secretsmanager.secret.arn"
2728
AWS_SNS_TOPIC_ARN: str = "aws.sns.topic.arn"
2829
AWS_STEPFUNCTIONS_STATEMACHINE_ARN: str = "aws.stepfunctions.state_machine.arn"

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_metric_attribute_generator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from amazon.opentelemetry.distro._aws_attribute_keys import (
99
AWS_BEDROCK_AGENT_ID,
1010
AWS_BEDROCK_DATA_SOURCE_ID,
11+
AWS_BEDROCK_GUARDRAIL_ARN,
1112
AWS_BEDROCK_GUARDRAIL_ID,
1213
AWS_BEDROCK_KNOWLEDGE_BASE_ID,
1314
AWS_CLOUDFORMATION_PRIMARY_IDENTIFIER,
1415
AWS_KINESIS_STREAM_NAME,
15-
AWS_LAMBDA_FUNCTION_NAME,
1616
AWS_LAMBDA_RESOURCEMAPPING_ID,
1717
AWS_LOCAL_OPERATION,
1818
AWS_LOCAL_SERVICE,
@@ -423,6 +423,7 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
423423
elif is_key_present(span, AWS_BEDROCK_GUARDRAIL_ID):
424424
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::Guardrail"
425425
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_GUARDRAIL_ID))
426+
cloudformation_primary_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_GUARDRAIL_ARN))
426427
elif is_key_present(span, AWS_BEDROCK_KNOWLEDGE_BASE_ID):
427428
remote_resource_type = _NORMALIZED_BEDROCK_SERVICE_NAME + "::KnowledgeBase"
428429
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_BEDROCK_KNOWLEDGE_BASE_ID))
@@ -456,9 +457,6 @@ def _set_remote_type_and_identifier(span: ReadableSpan, attributes: BoundedAttri
456457
elif is_key_present(span, AWS_LAMBDA_RESOURCEMAPPING_ID):
457458
remote_resource_type = _NORMALIZED_LAMBDA_SERVICE_NAME + "::EventSourceMapping"
458459
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_LAMBDA_RESOURCEMAPPING_ID))
459-
elif is_key_present(span, AWS_LAMBDA_FUNCTION_NAME):
460-
remote_resource_type = _NORMALIZED_LAMBDA_SERVICE_NAME + "::Function"
461-
remote_resource_identifier = _escape_delimiters(span.attributes.get(AWS_LAMBDA_FUNCTION_NAME))
462460
elif is_db_span(span):
463461
remote_resource_type = _DB_CONNECTION_STRING_TYPE
464462
remote_resource_identifier = _get_db_connection(span)

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_aws_span_processing_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_ingress_operation(__, span: ReadableSpan) -> str:
5252
"""
5353
operation: str = span.name
5454
if _AWS_LAMBDA_FUNCTION_NAME in os.environ:
55-
operation = os.environ.get(_AWS_LAMBDA_FUNCTION_NAME) + "/Handler"
55+
operation = os.environ.get(_AWS_LAMBDA_FUNCTION_NAME) + "/FunctionHandler"
5656
elif should_use_internal_operation(span):
5757
operation = INTERNAL_OPERATION
5858
elif not _is_valid_operation(span, operation):

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/attribute_propagating_span_processor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from amazon.opentelemetry.distro._aws_span_processing_util import is_aws_sdk_span, is_local_root
99
from opentelemetry.context import Context
1010
from opentelemetry.sdk.trace import ReadableSpan, Span, SpanProcessor
11+
from opentelemetry.semconv.trace import SpanAttributes
1112
from opentelemetry.trace import SpanKind
1213
from opentelemetry.trace.propagation import get_current_span
1314

@@ -62,6 +63,12 @@ def on_start(self, span: Span, parent_context: Optional[Context] = None) -> None
6263
if _is_consumer_kind(span) and _is_consumer_kind(parent_span):
6364
span.set_attribute(AWS_CONSUMER_PARENT_SPAN_KIND, parent_span.kind.name)
6465

66+
# Propagate span attribute cloud.resource_id for extracting lambda alias for dependency metrics.
67+
parent_resource_id = parent_span.attributes.get(SpanAttributes.CLOUD_RESOURCE_ID)
68+
current_resource_id = span.attributes.get(SpanAttributes.CLOUD_RESOURCE_ID)
69+
if current_resource_id is None and parent_resource_id is not None:
70+
span.set_attribute(SpanAttributes.CLOUD_RESOURCE_ID, parent_resource_id)
71+
6572
propagation_data: str = None
6673
if is_local_root(span):
6774
if not _is_server_kind(span):

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_span_metrics_processor.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
from typing import Dict, Optional
3+
from typing import Callable, Dict, Optional
44

55
from typing_extensions import override
66

@@ -45,19 +45,29 @@ class AwsSpanMetricsProcessor(SpanProcessor):
4545
_generator: MetricAttributeGenerator
4646
_resource: Resource
4747

48+
_force_flush_function: Callable
49+
50+
# no op function to act as a default function in case forceFlushFunction was
51+
# not supplied to the the constructor.
52+
# pylint: disable=no-self-use
53+
def _no_op_function(self, timeout_millis: float = None) -> bool:
54+
return True
55+
4856
def __init__(
4957
self,
5058
error_histogram: Histogram,
5159
fault_histogram: Histogram,
5260
latency_histogram: Histogram,
5361
generator: MetricAttributeGenerator,
5462
resource: Resource,
63+
force_flush_function: Callable = _no_op_function,
5564
):
5665
self._error_histogram = error_histogram
5766
self._fault_histogram = fault_histogram
5867
self._latency_histogram = latency_histogram
5968
self._generator = generator
6069
self._resource = resource
70+
self._force_flush_function = force_flush_function
6171

6272
# pylint: disable=no-self-use
6373
@override
@@ -78,8 +88,8 @@ def shutdown(self) -> None:
7888

7989
# pylint: disable=no-self-use
8090
@override
81-
def force_flush(self, timeout_millis: int = None) -> bool:
82-
return True
91+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
92+
return self._force_flush_function(timeout_millis)
8393

8494
def _record_metrics(self, span: ReadableSpan, attributes: BoundedAttributes) -> None:
8595
# Only record metrics if non-empty attributes are returned.

0 commit comments

Comments
 (0)