diff --git a/lambda-layer/README.md b/lambda-layer/README.md new file mode 100644 index 000000000..dbdba611c --- /dev/null +++ b/lambda-layer/README.md @@ -0,0 +1,49 @@ +# AWS Lambda Application Signals Support + +This package provides support for **Application Signals** in AWS Lambda environment. + +## Features + +- Supports Application Signals, including traces and metrics, for AWS Lambda Python Runtimes. +- Automates the deployment process, including the creation of the Application Python Lambda Layer and a sample Lambda function. + +## Prerequisites + +Before you begin, make sure you have installed and configured the following tools: + +- [Docker](https://www.docker.com/get-started) +- [Terraform](https://www.terraform.io/downloads) +- [AWS CLI](https://aws.amazon.com/cli/) (to configure AWS credentials) + +### Configure AWS Credentials + +Ensure that your AWS credentials are properly configured in your local environment. You can use the following command with the AWS CLI: + +```bash +aws configure +``` +This will prompt you to enter your `AWS Access Key ID`, `AWS Secret Access Key`, `Default region name`, and `Default output format`. + +## Installation and Deployment + +### 1. Clone the Repository + +First, clone this repository to your local machine: + +```bash +git clone https://github.com/yourusername/your-repo.git +``` + +### 2. Run the Build Script + +Navigate to the `lambda-layer` folder and run the `build.sh` script. This will create the Application Python Lambda Layer and a Lambda sample app in your AWS account: + +```bash +cd lambda-layer +./build.sh +``` + +## Lambda Sample App + +Once the script has successfully run, you will see the deployed Lambda sample app in your AWS account. You can trigger the +Lambda function and view the traces and metrics through the AWS CloudWatch Console. diff --git a/lambda-layer/src/Dockerfile b/lambda-layer/src/Dockerfile index c403ec403..3b832d06d 100644 --- a/lambda-layer/src/Dockerfile +++ b/lambda-layer/src/Dockerfile @@ -1,6 +1,4 @@ -ARG runtime=python3.12 - -FROM public.ecr.aws/sam/build-${runtime} +FROM public.ecr.aws/sam/build-python3.12 AS python312 ADD . /workspace @@ -14,10 +12,20 @@ RUN mkdir -p /build && \ python3 -m pip install aws-opentelemetry-distro/ -t /build/python && \ mv otel_wrapper.py /build/python && \ mv otel-instrument /build && \ + python3 -m compileall /build/python && \ chmod 755 /build/otel-instrument && \ - rm -rf /build/python/boto* && \ - rm -rf /build/python/urllib3* && \ - cd /build && \ + rm -rf /build/python/urllib3* + + +FROM public.ecr.aws/sam/build-python3.11 AS python311 + +WORKDIR /workspace + +COPY --from=python312 /build /build + +RUN python3 -m compileall /build/python + +RUN cd /build && \ zip -r aws-opentelemetry-python-layer.zip otel-instrument python CMD ["cp", "/build/aws-opentelemetry-python-layer.zip", "/out/aws-opentelemetry-python-layer.zip"] diff --git a/lambda-layer/src/otel-instrument b/lambda-layer/src/otel-instrument index 16518ea1f..402d95d8d 100755 --- a/lambda-layer/src/otel-instrument +++ b/lambda-layer/src/otel-instrument @@ -84,15 +84,6 @@ export PYTHONPATH="$LAMBDA_LAYER_PKGS_DIR:$PYTHONPATH"; export PYTHONPATH="$LAMBDA_RUNTIME_DIR:$PYTHONPATH"; -# Configure OpenTelemetry Python with environment variables - -# - We leave `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` to its default. This is -# `http://localhost:4318/v1/traces` because we are using the HTTP exporter - -# - If OTEL_EXPORTER_OTLP_PROTOCOL is not set by user, the default exporting protocol is http/protobuf. -if [ -z "${OTEL_EXPORTER_OTLP_PROTOCOL}" ]; then - export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf -fi # - Set the service name @@ -100,11 +91,6 @@ if [ -z "${OTEL_SERVICE_NAME}" ]; then export OTEL_SERVICE_NAME=$AWS_LAMBDA_FUNCTION_NAME; fi -# - Set the propagators - -if [[ -z "$OTEL_PROPAGATORS" ]]; then - export OTEL_PROPAGATORS="tracecontext,baggage,xray" -fi export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME,aws.log.group.names=$AWS_LAMBDA_LOG_GROUP_NAME";