From 429b26d3836db26b390a47992ffc89d4a300eddb Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 06:57:20 -0700 Subject: [PATCH 01/11] Revert "ci: revert PRs #762 and #775 (#776)" This reverts commit a3f0640029679ed0a28e51be0eaf1a7b0edd6fa1. --- scripts/build_layers.sh | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 7456a38b..eabba101 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -98,22 +98,41 @@ function make_path_absolute { echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")" } +function search_wheel { + # Args: [wheel base name] [index] + + WHEEL_BASENAME=$1 + INDEX=$2 + + SEARCH_PATTERN="${WHEEL_BASENAME}-[^\"]*${PY_TAG}[^\"]*${PLATFORM}[^\"]*\.whl" + INDEX_URL="${S3_BASE}/index-${INDEX}.html" + echo "Searching for wheel ${SEARCH_PATTERN}" + export WHEEL_FILE=$(curl -sSfL ${INDEX_URL} | grep -o "$SEARCH_PATTERN" | head -n 1) + if [ ! -z "${WHEEL_FILE}" ]; then + curl -sSfL "${S3_BASE}/${WHEEL_FILE}" -o "${WHEEL_FILE}" + echo "Using S3 wheel: ${WHEEL_FILE}" + replace_ddtrace_dep "${WHEEL_BASENAME} = { file = \"${WHEEL_FILE}\" }" + fi +} + function docker_build_zip { - # Args: [python version] [zip destination] + # Args: [python version] [zip destination] [wheel base name] [index] destination=$(make_path_absolute $2) arch=$3 + wheel_basename=$4 + index=$5 # Restore pyproject.toml to a clean state for each build iteration cp pyproject.toml.bak pyproject.toml # Replace ddtrace source if necessary if [ -n "$DD_TRACE_COMMIT" ]; then - replace_ddtrace_dep "ddtrace = { git = \"https://github.com/DataDog/dd-trace-py.git\", rev = \"$DD_TRACE_COMMIT\" }" + replace_ddtrace_dep "${wheel_basename} = { git = \"https://github.com/DataDog/dd-trace-py.git\", rev = \"$DD_TRACE_COMMIT\" }" elif [ -n "$DD_TRACE_COMMIT_BRANCH" ]; then - replace_ddtrace_dep "ddtrace = { git = \"https://github.com/DataDog/dd-trace-py.git\", branch = \"$DD_TRACE_COMMIT_BRANCH\" }" + replace_ddtrace_dep "${wheel_basename} = { git = \"https://github.com/DataDog/dd-trace-py.git\", branch = \"$DD_TRACE_COMMIT_BRANCH\" }" elif [ -n "$DD_TRACE_WHEEL" ]; then - replace_ddtrace_dep "ddtrace = { file = \"$DD_TRACE_WHEEL\" }" + replace_ddtrace_dep "${wheel_basename} = { file = \"$DD_TRACE_WHEEL\" }" elif [ -n "$UPSTREAM_PIPELINE_ID" ]; then S3_BASE="https://dd-trace-py-builds.s3.amazonaws.com/${UPSTREAM_PIPELINE_ID}" if [ "${arch}" = "amd64" ]; then @@ -122,15 +141,9 @@ function docker_build_zip { PLATFORM="manylinux2014_aarch64" fi PY_TAG="cp$(echo "$1" | tr -d '.')" - WHEEL_FILE=$(curl -sSfL "${S3_BASE}/index-manylinux2014.html" \ - | grep -o "ddtrace-[^\"]*${PY_TAG}[^\"]*${PLATFORM}[^\"]*\.whl" \ - | head -n 1) + search_wheel ${wheel_basename} ${index} if [ -z "${WHEEL_FILE}" ]; then echo "No S3 wheel found for ${PY_TAG} ${PLATFORM}, using default pyproject.toml version" - else - curl -sSfL "${S3_BASE}/${WHEEL_FILE}" -o "${WHEEL_FILE}" - echo "Using S3 wheel: ${WHEEL_FILE}" - replace_ddtrace_dep "ddtrace = { file = \"${WHEEL_FILE}\" }" fi fi @@ -149,6 +162,7 @@ function docker_build_zip { rm -rf $temp_dir echo "Done creating archive $destination" + rm pyproject.toml.bak } rm -rf $LAYER_DIR @@ -159,7 +173,10 @@ do for architecture in "${ARCHS[@]}" do echo "Building layer for Python ${python_version} arch=${architecture}" - docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} + docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace_serverless" "serverless" || true + if [ -f pyproject.toml.bak ]; then # true means the previous attempt failed + docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace" "manylinux2014" + fi done done From a95762ef30efb96a1caf6fce425e47b49e7b1e41 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 12:33:22 -0700 Subject: [PATCH 02/11] try a different way of checking success --- scripts/build_layers.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index eabba101..d145f28f 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -162,7 +162,6 @@ function docker_build_zip { rm -rf $temp_dir echo "Done creating archive $destination" - rm pyproject.toml.bak } rm -rf $LAYER_DIR @@ -174,7 +173,8 @@ do do echo "Building layer for Python ${python_version} arch=${architecture}" docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace_serverless" "serverless" || true - if [ -f pyproject.toml.bak ]; then # true means the previous attempt failed + if [ $? != 0 ]; then + echo "Attempting layer build again with package ddtrace" docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace" "manylinux2014" fi done From aab590eff11d4ad67c69d1c3d3d74ced28a29ad7 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 12:41:30 -0700 Subject: [PATCH 03/11] refactor to only do docker build once --- scripts/build_layers.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index d145f28f..9e64a87c 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -115,13 +115,12 @@ function search_wheel { fi } -function docker_build_zip { - # Args: [python version] [zip destination] [wheel base name] [index] +function find_and_spec_wheel { + # Args: [python version] [wheel base name] [index] - destination=$(make_path_absolute $2) - arch=$3 - wheel_basename=$4 - index=$5 + arch=$2 + wheel_basename=$3 + index=$4 # Restore pyproject.toml to a clean state for each build iteration cp pyproject.toml.bak pyproject.toml @@ -147,6 +146,13 @@ function docker_build_zip { fi fi +} + +function docker_build_zip { + # Args: [python version] [zip destination] + + destination=$(make_path_absolute $2) + arch=$3 # Install datadogpy in a docker container to avoid the mess from switching # between different python runtimes. temp_dir=$(mktemp -d) @@ -172,11 +178,12 @@ do for architecture in "${ARCHS[@]}" do echo "Building layer for Python ${python_version} arch=${architecture}" - docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace_serverless" "serverless" || true + find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless" if [ $? != 0 ]; then echo "Attempting layer build again with package ddtrace" - docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} "ddtrace" "manylinux2014" + find_and_spec_wheel ${python_version} ${architecture} "ddtrace" "manylinux2014" fi + docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} done done From 3c64f8b2a12c74c27ebe7502d11bba23cc3eebca Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 12:45:41 -0700 Subject: [PATCH 04/11] oh yeah --- scripts/build_layers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 9e64a87c..4aa985c5 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -143,6 +143,7 @@ function find_and_spec_wheel { search_wheel ${wheel_basename} ${index} if [ -z "${WHEEL_FILE}" ]; then echo "No S3 wheel found for ${PY_TAG} ${PLATFORM}, using default pyproject.toml version" + return 1 fi fi From ae5c082ab58d6533e0313f96c4a7123333be2ebf Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 12:58:12 -0700 Subject: [PATCH 05/11] catch error code --- scripts/build_layers.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 4aa985c5..3e2a54c4 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -146,7 +146,6 @@ function find_and_spec_wheel { return 1 fi fi - } function docker_build_zip { @@ -179,8 +178,8 @@ do for architecture in "${ARCHS[@]}" do echo "Building layer for Python ${python_version} arch=${architecture}" - find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless" - if [ $? != 0 ]; then + find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless"; FAILURE=$? + if [ $FAILURE != 0 ]; then echo "Attempting layer build again with package ddtrace" find_and_spec_wheel ${python_version} ${architecture} "ddtrace" "manylinux2014" fi From 803586b223439a51fd5b5785efdf7afd5f85728b Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:01:07 -0700 Subject: [PATCH 06/11] bite the proverbial bullet --- scripts/build_layers.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 3e2a54c4..ff7fc21a 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -178,8 +178,10 @@ do for architecture in "${ARCHS[@]}" do echo "Building layer for Python ${python_version} arch=${architecture}" - find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless"; FAILURE=$? - if [ $FAILURE != 0 ]; then + set +e + find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless" + set -e + if [ $? != 0 ]; then echo "Attempting layer build again with package ddtrace" find_and_spec_wheel ${python_version} ${architecture} "ddtrace" "manylinux2014" fi From 0c808bf958111d28530bea3e72edc8a9d4a52906 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:04:24 -0700 Subject: [PATCH 07/11] *shakes fist* ....bash!!! --- scripts/build_layers.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index ff7fc21a..81c2c077 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -180,8 +180,9 @@ do echo "Building layer for Python ${python_version} arch=${architecture}" set +e find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless" + FAILURE=$? set -e - if [ $? != 0 ]; then + if [ $FAILURE != 0 ]; then echo "Attempting layer build again with package ddtrace" find_and_spec_wheel ${python_version} ${architecture} "ddtrace" "manylinux2014" fi From 2d7d300640f5b70cfbc769d1c839db57c0f5afc3 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:08:43 -0700 Subject: [PATCH 08/11] more handling --- scripts/build_layers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 81c2c077..ce290ed8 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -181,11 +181,11 @@ do set +e find_and_spec_wheel ${python_version} ${architecture} "ddtrace_serverless" "serverless" FAILURE=$? - set -e if [ $FAILURE != 0 ]; then echo "Attempting layer build again with package ddtrace" find_and_spec_wheel ${python_version} ${architecture} "ddtrace" "manylinux2014" fi + set -e docker_build_zip ${python_version} $LAYER_DIR/${LAYER_FILES_PREFIX}-${architecture}-${python_version}.zip ${architecture} done done From e401b19067757e341786fea3f2eb8630d9db5391 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:24:41 -0700 Subject: [PATCH 09/11] debug output --- scripts/build_layers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index ce290ed8..aa0aa20e 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -91,6 +91,7 @@ trap cleanup EXIT # Helper: replace the multi-line ddtrace dependency in pyproject.toml. # Uses perl instead of sed -z for macOS/Linux portability. replace_ddtrace_dep() { + echo "Replacing dep with $1" perl -i -0777 -pe "s|ddtrace = \[[^\]]*\]|$1|gs" pyproject.toml } From 95a559ede6f608a8ba76e7aa9248b6db90f6c092 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:34:45 -0700 Subject: [PATCH 10/11] construct basename when given a wheel directly --- scripts/build_layers.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index aa0aa20e..08ffd0d7 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -132,6 +132,7 @@ function find_and_spec_wheel { elif [ -n "$DD_TRACE_COMMIT_BRANCH" ]; then replace_ddtrace_dep "${wheel_basename} = { git = \"https://github.com/DataDog/dd-trace-py.git\", branch = \"$DD_TRACE_COMMIT_BRANCH\" }" elif [ -n "$DD_TRACE_WHEEL" ]; then + wheel_basename=${DD_TRACE_WHEEL%%-*} replace_ddtrace_dep "${wheel_basename} = { file = \"$DD_TRACE_WHEEL\" }" elif [ -n "$UPSTREAM_PIPELINE_ID" ]; then S3_BASE="https://dd-trace-py-builds.s3.amazonaws.com/${UPSTREAM_PIPELINE_ID}" From ccb70d8e80f4e270b42cfb3cbee009216e5e4654 Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 2 Apr 2026 13:52:55 -0700 Subject: [PATCH 11/11] handle dotslash in basename --- scripts/build_layers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build_layers.sh b/scripts/build_layers.sh index 08ffd0d7..b3f73385 100755 --- a/scripts/build_layers.sh +++ b/scripts/build_layers.sh @@ -132,7 +132,7 @@ function find_and_spec_wheel { elif [ -n "$DD_TRACE_COMMIT_BRANCH" ]; then replace_ddtrace_dep "${wheel_basename} = { git = \"https://github.com/DataDog/dd-trace-py.git\", branch = \"$DD_TRACE_COMMIT_BRANCH\" }" elif [ -n "$DD_TRACE_WHEEL" ]; then - wheel_basename=${DD_TRACE_WHEEL%%-*} + wheel_basename=$(sed 's/^\.\///' <<< ${DD_TRACE_WHEEL%%-*}) replace_ddtrace_dep "${wheel_basename} = { file = \"$DD_TRACE_WHEEL\" }" elif [ -n "$UPSTREAM_PIPELINE_ID" ]; then S3_BASE="https://dd-trace-py-builds.s3.amazonaws.com/${UPSTREAM_PIPELINE_ID}"