Skip to content

Commit 2c9c260

Browse files
authored
Build layer during CI/CD workflows + some minor refactoring (aws-observability#989)
*Description of changes:* - Running the lambda layer build script during PR to ensure that layer builds successfully. - During the main build, ensure that we can build the lambda layer and also upload it to the staging bucket for further E2E testing. The E2E test will be added in the subsequent PR. *Testing:* Triggered the main_build workflow in my fork: https://github.com/srprash/aws-otel-java-instrumentation/actions/runs/12679487319/job/35339366348 - Observed that the layer zip file was successfully uploaded to the run: https://github.com/srprash/aws-otel-java-instrumentation/actions/runs/12679487319/job/35339366348#step:5:22 - Upload to S3 fails since I don't have the right credentials in my fork. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9d54809 commit 2c9c260

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

.github/workflows/main-build.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,38 @@ jobs:
226226
with:
227227
arguments: contractTests -PlocalDocker=true
228228

229+
application-signals-lambda-layer-build:
230+
runs-on: ubuntu-latest
231+
steps:
232+
- uses: actions/checkout@v4
233+
with:
234+
fetch-depth: 0
235+
- uses: actions/setup-java@v4
236+
with:
237+
java-version: 17
238+
distribution: 'temurin'
239+
- name: Build Application Signals Lambda Layer
240+
working-directory: lambda-layer
241+
run: |
242+
./build-layer.sh
243+
- name: Upload layer zip to GitHub Actions
244+
uses: actions/upload-artifact@v3
245+
with:
246+
name: aws-opentelemetry-java-layer.zip
247+
path: lambda-layer/build/distributions/aws-opentelemetry-java-layer.zip
248+
- name: Configure AWS Credentials
249+
uses: aws-actions/configure-aws-credentials@v4
250+
with:
251+
role-to-assume: arn:aws:iam::${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}:role/${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}
252+
aws-region: us-east-1
253+
- name: Upload layer zip to S3
254+
working-directory: lambda-layer
255+
run: |
256+
aws s3 cp ./build/distributions/aws-opentelemetry-java-layer.zip s3://adot-main-build-staging-jar/adot-java-lambda-layer-${{ github.run_id }}.zip
257+
258+
229259
application-signals-e2e-test:
230-
needs: [build]
260+
needs: [build, application-signals-lambda-layer-build]
231261
uses: ./.github/workflows/application-signals-e2e-test.yml
232262
secrets: inherit
233263
with:
@@ -247,3 +277,4 @@ jobs:
247277
region: us-east-1
248278
secrets:
249279
roleArn: ${{ secrets.METRICS_ROLE_ARN }}
280+

.github/workflows/pr-build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,18 @@ jobs:
156156
arguments: build --stacktrace -PenableCoverage=true
157157
- uses: codecov/codecov-action@v3
158158

159+
build-lambda:
160+
runs-on: ubuntu-latest
161+
steps:
162+
- name: Checkout Repo @ SHA - ${{ github.sha }}
163+
uses: actions/checkout@v4
164+
165+
- name: Setup Java
166+
uses: actions/setup-java@v4
167+
with:
168+
java-version: 17
169+
distribution: temurin
170+
171+
- name: Build layer
172+
working-directory: lambda-layer
173+
run: ./build-layer.sh

lambda-layer/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
build
66

77
# Ignore Terraform state files
8-
.terraform
8+
.terraform/
99
*.tfstate
1010
*.tfstate.backup
1111
*.lock.hcl

lambda-layer/build-layer.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -e
23

34
SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
45

@@ -27,8 +28,6 @@ patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-instrumentation.p
2728
# This patch is for Lambda related context propagation
2829
patch -p1 < "$SOURCEDIR"/patches/opentelemetry-java-instrumentation.patch
2930

30-
git add -A
31-
git commit -m "Create patch version"
3231
./gradlew publishToMavenLocal
3332
popd
3433
rm -rf opentelemetry-java-instrumentation
@@ -46,8 +45,12 @@ popd
4645
echo "Info: Building ADOT Lambda Java SDK Layer Code"
4746
./gradlew build -PotelVersion=${version}
4847

49-
5048
## Copy ADOT Java Agent downloaded using Gradle task and bundle it with the Lambda handler script
5149
echo "Info: Creating the layer artifact"
52-
cp "$SOURCEDIR"/build/javaagent/aws-opentelemetry-agent*.jar ./opentelemetry-javaagent.jar
53-
zip -qr opentelemetry-javaagent-layer.zip opentelemetry-javaagent.jar otel-instrument
50+
mkdir -p "$SOURCEDIR"/build/distributions/
51+
cp "$SOURCEDIR"/build/javaagent/aws-opentelemetry-agent*.jar "$SOURCEDIR"/build/distributions/aws-opentelemetry-javaagent.jar
52+
zip -r ./build/distributions/aws-opentelemetry-java-layer.zip "$SOURCEDIR"/build/distributions/aws-opentelemetry-javaagent.jar otel-instrument
53+
54+
## Cleanup
55+
# revert the patch applied since it is only needed while building the layer.
56+
git restore ../dependencyManagement/build.gradle.kts

lambda-layer/otel-instrument

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export OTEL_PROPAGATORS="${OTEL_PROPAGATORS:-xray,tracecontext,b3,b3multi}"
66

77
export OTEL_SERVICE_NAME=${OTEL_SERVICE_NAME:-${AWS_LAMBDA_FUNCTION_NAME}}
88

9-
export JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}"
9+
export JAVA_TOOL_OPTIONS="-javaagent:/opt/aws-opentelemetry-javaagent.jar ${JAVA_TOOL_OPTIONS}"
1010

1111
if [[ $OTEL_RESOURCE_ATTRIBUTES != *"service.name="* ]]; then
1212
export OTEL_RESOURCE_ATTRIBUTES="service.name=${AWS_LAMBDA_FUNCTION_NAME},${OTEL_RESOURCE_ATTRIBUTES}"

0 commit comments

Comments
 (0)