From 4c65d4564f3960857154641d200e5d601d8a2a43 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 11:31:44 -0400 Subject: [PATCH 01/12] chore(build): build dd-trace-py with release mode by default --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index ee4c7efd..f965977e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH +ENV DD_COMPILE_MODE="Release" + # Install datadog_lambda and dependencies from local COPY . . RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages From 796a370b0f0c7d3190bcec91ae6bd6c82380b0ef Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 11:59:55 -0400 Subject: [PATCH 02/12] does this make difference --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f965977e..b57fc29a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH -ENV DD_COMPILE_MODE="Release" +ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local COPY . . From 07df11ac23f48c66d638ddefef811032afbaa4b6 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 12:00:16 -0400 Subject: [PATCH 03/12] debug print --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b57fc29a..f74a24c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ RUN curl https://sh.rustup.rs -sSf | \ ENV PATH=/root/.cargo/bin:$PATH ENV DD_COMPILE_MODE=Release +RUN echo "DD_COMPILE_MODE=$DD_COMPILE_MODE" # Install datadog_lambda and dependencies from local COPY . . From 6f061439e3561ca88eb3d838e457f00ab7953ca9 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 13:05:16 -0400 Subject: [PATCH 04/12] try setting here --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f74a24c8..e326d1a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,12 +22,9 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH -ENV DD_COMPILE_MODE=Release -RUN echo "DD_COMPILE_MODE=$DD_COMPILE_MODE" - # Install datadog_lambda and dependencies from local COPY . . -RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages +RUN DD_COMPILE_MODE=Release pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages # Remove botocore (40MB) to reduce package size. aws-xray-sdk # installs it, while it's already provided by the Lambda Runtime. From 1cfcdd823c671aecce5e4ef43fb054a63d04c8b7 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 13:26:15 -0400 Subject: [PATCH 05/12] Revert "debug print" This reverts commit 07df11ac23f48c66d638ddefef811032afbaa4b6. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index e326d1a7..1ead2b32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,8 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH +ENV DD_COMPILE_MODE=Release + # Install datadog_lambda and dependencies from local COPY . . RUN DD_COMPILE_MODE=Release pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages From aa1cbe7c1a9941ef0a0f02a73dd3f75bdb3b0811 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 13:26:34 -0400 Subject: [PATCH 06/12] Revert "try setting here" This reverts commit 6f061439e3561ca88eb3d838e457f00ab7953ca9. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1ead2b32..b57fc29a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local COPY . . -RUN DD_COMPILE_MODE=Release pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages +RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages # Remove botocore (40MB) to reduce package size. aws-xray-sdk # installs it, while it's already provided by the Lambda Runtime. From 7ba9028caf8f123e3e64d39fc29f5d5c37a1cd5f Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 13:29:09 -0400 Subject: [PATCH 07/12] comment --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index b57fc29a..91a1043b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,10 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH +# Compile mode is explicitly set here to strip the debug symbols from the +# native extensions in dd-trace-py. Otherwise, they will have debug symbols +# by default when built from sources. PyPI packages are stripped off of debug +# symbols. This is mainly to reduce the layer size at the cost of debuggability ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local From 376eb90d98b43eaa8728b94c8ce9bb334a88e395 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 13:47:36 -0400 Subject: [PATCH 08/12] debug print --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 91a1043b..f7e5f53c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local COPY . . -RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages +RUN pip install -v --no-cache-dir . -t ./python/lib/$runtime/site-packages # Remove botocore (40MB) to reduce package size. aws-xray-sdk # installs it, while it's already provided by the Lambda Runtime. From 0fda51a23f7e8294fac07335920085d7c7b6e205 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 14:03:38 -0400 Subject: [PATCH 09/12] aggressively strip debug symbols --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index f7e5f53c..8eb94193 100644 --- a/Dockerfile +++ b/Dockerfile @@ -78,5 +78,8 @@ RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.h -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.hpp -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.pyx -delete +# Strip debug symbols using strip -g for all .so files in ddtrace +RUN find ./python/lib/$runtime/site-packages/ddtrace -name "*.so" -exec strip -g {} \; + FROM scratch COPY --from=builder /build/python / From 18c4f75e8c8bf760b45f0da068433c9a0257af53 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 14:04:11 -0400 Subject: [PATCH 10/12] remove debug print --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8eb94193..a3cc5e3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local COPY . . -RUN pip install -v --no-cache-dir . -t ./python/lib/$runtime/site-packages +RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages # Remove botocore (40MB) to reduce package size. aws-xray-sdk # installs it, while it's already provided by the Lambda Runtime. From 6e20afbcf1d4fc31ab420529e4cb28389695c214 Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 14:23:13 -0400 Subject: [PATCH 11/12] update comments --- Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3cc5e3a..61cf2e40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,10 +22,10 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH -# Compile mode is explicitly set here to strip the debug symbols from the -# native extensions in dd-trace-py. Otherwise, they will have debug symbols -# by default when built from sources. PyPI packages are stripped off of debug -# symbols. This is mainly to reduce the layer size at the cost of debuggability +# Compile mode is explicitly set here to not build native extensions with +# debug symbols. Otherwise, they will have debug symbols by default when built +# from sources. PyPI packages are stripped off of debug symbols, using strip -g. +# This is mainly to reduce the layer size at the cost of debuggability. ENV DD_COMPILE_MODE=Release # Install datadog_lambda and dependencies from local @@ -78,7 +78,10 @@ RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.h -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.hpp -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.pyx -delete -# Strip debug symbols using strip -g for all .so files in ddtrace +# Strip debug symbols using strip -g for all .so files in ddtrace. This is to +# reduce the size when ddtrace is built from sources. The release wheels are +# already stripped of debug symbols. We should revisit this when serverless +# benchmark uses pre-built wheels instead of building from sources. RUN find ./python/lib/$runtime/site-packages/ddtrace -name "*.so" -exec strip -g {} \; FROM scratch From dd0316f8d2156f7474c06b4902ce87621f5f15cc Mon Sep 17 00:00:00 2001 From: Taegyun Kim Date: Wed, 20 Aug 2025 14:32:58 -0400 Subject: [PATCH 12/12] can this work too? --- Dockerfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61cf2e40..36b236f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,12 +22,6 @@ RUN curl https://sh.rustup.rs -sSf | \ sh -s -- --default-toolchain stable -y ENV PATH=/root/.cargo/bin:$PATH -# Compile mode is explicitly set here to not build native extensions with -# debug symbols. Otherwise, they will have debug symbols by default when built -# from sources. PyPI packages are stripped off of debug symbols, using strip -g. -# This is mainly to reduce the layer size at the cost of debuggability. -ENV DD_COMPILE_MODE=Release - # Install datadog_lambda and dependencies from local COPY . . RUN pip install --no-cache-dir . -t ./python/lib/$runtime/site-packages