Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lambda-layer/README.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 14 additions & 6 deletions lambda-layer/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"]
14 changes: 0 additions & 14 deletions lambda-layer/src/otel-instrument
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,13 @@ 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

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";

Expand Down
Loading