Skip to content

Commit 5ea8459

Browse files
authored
Updating Lambda Patch v1.33.6 + Fast Startup capability (#986)
### Description of changes: - Fast Startup feature was added as opt-in in the upstream some time ago: open-telemetry/opentelemetry-lambda#1180 (includes perf improvement results) - Did some of my own testing on a Java17 Lambda function with 3GB of memory and noticed cold start time improvement from 8.7 seconds to 4.2 seconds. - Since the ADOT 1.x version has been updated to lated 1.33.6 version of upstream, we need to update the lambda layer related patches to this version as well. - Tested by manually building the layer and instrumenting a sample lambda function. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent dc6ba37 commit 5ea8459

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

lambda-layer/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33

44
# Ignore Gradle build output directory
55
build
6+
7+
# Ignore Terraform state files
8+
.terraform
9+
*.tfstate
10+
*.tfstate.backup
11+
*.lock.hcl

lambda-layer/build-layer.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
44

55

66
## Get OTel version
7+
echo "Info: Getting OTEL Version"
78
file="$SOURCEDIR/../.github/patches/versions"
89
version=$(awk -F'=v' '/OTEL_JAVA_INSTRUMENTATION_VERSION/ {print $2}' "$file")
910
echo "Found OTEL Version: ${version}"
@@ -15,16 +16,17 @@ fi
1516

1617

1718
## Clone and Patch the OpenTelemetry Java Instrumentation Repository
19+
echo "Info: Cloning and Patching OpenTelemetry Java Instrumentation Repository"
1820
git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.git
1921
pushd opentelemetry-java-instrumentation
2022
git checkout v${version} -b tag-v${version}
2123

22-
# This patch is for Lambda related context propagation
23-
patch -p1 < "$SOURCEDIR"/patches/opentelemetry-java-instrumentation.patch
24-
2524
# There is another patch in the .github/patches directory for other changes. We should apply them too for consistency.
2625
patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-instrumentation.patch
2726

27+
# This patch is for Lambda related context propagation
28+
patch -p1 < "$SOURCEDIR"/patches/opentelemetry-java-instrumentation.patch
29+
2830
git add -A
2931
git commit -m "Create patch version"
3032
./gradlew publishToMavenLocal
@@ -33,16 +35,19 @@ rm -rf opentelemetry-java-instrumentation
3335

3436

3537
## Build the ADOT Java from current source
38+
echo "Info: Building ADOT Java from current source"
3639
pushd "$SOURCEDIR"/..
3740
patch -p1 < "${SOURCEDIR}"/patches/aws-otel-java-instrumentation.patch
3841
CI=false ./gradlew publishToMavenLocal -Prelease.version=${version}-adot-lambda1
3942
popd
4043

4144

4245
## Build ADOT Lambda Java SDK Layer Code
43-
./gradlew build
46+
echo "Info: Building ADOT Lambda Java SDK Layer Code"
47+
./gradlew build -PotelVersion=${version}
4448

4549

4650
## Copy ADOT Java Agent downloaded using Gradle task and bundle it with the Lambda handler script
51+
echo "Info: Creating the layer artifact"
4752
cp "$SOURCEDIR"/build/javaagent/aws-opentelemetry-agent*.jar ./opentelemetry-javaagent.jar
4853
zip -qr opentelemetry-javaagent-layer.zip opentelemetry-javaagent.jar otel-instrument

lambda-layer/build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ val javaagentDependency by configurations.creating {
2727
extendsFrom()
2828
}
2929

30+
val otelVersion: String by project
31+
3032
dependencies {
31-
compileOnly(platform("io.opentelemetry:opentelemetry-bom:1.32.1"))
32-
compileOnly(platform("io.opentelemetry:opentelemetry-bom-alpha:1.32.1-alpha"))
33+
compileOnly(platform("io.opentelemetry:opentelemetry-bom:$otelVersion"))
34+
compileOnly(platform("io.opentelemetry:opentelemetry-bom-alpha:$otelVersion-alpha"))
3335
// Already included in wrapper so compileOnly
3436
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
3537
compileOnly("io.opentelemetry:opentelemetry-sdk-extension-aws")
36-
javaagentDependency("software.amazon.opentelemetry:aws-opentelemetry-agent:1.32.1-adot-lambda1")
38+
javaagentDependency("software.amazon.opentelemetry:aws-opentelemetry-agent:$otelVersion-adot-lambda1")
3739
}
3840

3941
tasks.register<Copy>("download") {

lambda-layer/otel-instrument

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,25 @@ else
3535
export OTEL_RESOURCE_ATTRIBUTES="$LAMBDA_RESOURCE_ATTRIBUTES,$OTEL_RESOURCE_ATTRIBUTES";
3636
fi
3737

38-
exec "$@"
38+
ARGS=("$@")
39+
EXTRA_ARGS=()
40+
41+
if [ "${OTEL_JAVA_AGENT_FAST_STARTUP_ENABLED}" == "true" ]; then
42+
echo "[OTEL] Enabling fast startup mode ..."
43+
# Disable bytecode verification
44+
EXTRA_ARGS+=("-Xverify:none")
45+
# Be sure that tiered compilation is enabled
46+
EXTRA_ARGS+=("-XX:+TieredCompilation")
47+
# Stop tiered compilation at level 1
48+
EXTRA_ARGS+=("-XX:TieredStopAtLevel=1")
49+
for i in "${!ARGS[@]}"; do
50+
# If tiered compilation is disabled, ignore it as we enable it at level 1 for fast startup
51+
if [[ ${ARGS[i]} = "-XX:-TieredCompilation" ]]; then
52+
unset 'ARGS[i]'
53+
fi
54+
done
55+
fi
56+
57+
ARGS=("${ARGS[0]}" "${EXTRA_ARGS[@]}" "${ARGS[@]:1}")
58+
59+
exec "${ARGS[@]}"

lambda-layer/patches/aws-otel-java-instrumentation.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ index 9493189..6090207 100644
66
val TEST_SNAPSHOTS = rootProject.findProperty("testUpstreamSnapshots") == "true"
77

88
// This is the version of the upstream instrumentation BOM
9-
-val otelVersion = "1.32.1-adot2"
10-
+val otelVersion = "1.32.1-adot-lambda1"
11-
val otelSnapshotVersion = "1.33.0"
9+
-val otelVersion = "1.33.6-adot1"
10+
+val otelVersion = "1.33.6-adot-lambda1"
11+
val otelSnapshotVersion = "1.33.6"
1212
val otelAlphaVersion = if (!TEST_SNAPSHOTS) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT"
1313
val otelJavaAgentVersion = if (!TEST_SNAPSHOTS) otelVersion else "$otelSnapshotVersion-SNAPSHOT"

lambda-layer/patches/opentelemetry-java-instrumentation.patch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,10 @@ index cc1414c0bf..db8a59b046 100644
636636
--- a/version.gradle.kts
637637
+++ b/version.gradle.kts
638638
@@ -1,5 +1,5 @@
639-
-val stableVersion = "1.32.1"
640-
-val alphaVersion = "1.32.1-alpha"
641-
+val stableVersion = "1.32.1-adot-lambda1"
642-
+val alphaVersion = "1.32.1-adot-lambda1-alpha"
639+
-val stableVersion = "1.33.6-adot1"
640+
-val alphaVersion = "1.33.6-adot1-alpha"
641+
+val stableVersion = "1.33.6-adot-lambda1"
642+
+val alphaVersion = "1.33.6-adot-lambda1-alpha"
643643

644644
allprojects {
645645
if (findProperty("otel.stable") != "true") {

0 commit comments

Comments
 (0)