From 4ef48808734375ffb2969f3840ecf42b07679a8e Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Mon, 30 Mar 2026 11:57:52 -0400 Subject: [PATCH 1/3] chore: remove ddtrace patch.py files from layer --- Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d9eb756..64cd7d21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,10 +62,9 @@ RUN rm -rf \ # https://docs.python.org/3.11/using/cmdline.html#cmdoption-O # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNODEBUGRANGES RUN PYTHONNODEBUGRANGES=1 python -OO -m compileall -b ./python/lib/$runtime/site-packages -# remove all .py files except ddtrace/contrib/*/patch.py which are necessary -# for ddtrace.patch to discover instrumationation packages. -RUN find ./python/lib/$runtime/site-packages -name \*.py | grep -v ddtrace/contrib | xargs rm -rf -RUN find ./python/lib/$runtime/site-packages/ddtrace/contrib -name \*.py | grep -v patch.py | xargs rm -rf +# remove all .py files +# DEV: previously we kept patch.py files, but this is no longer necessary +RUN find ./python/lib/$runtime/site-packages -name \*.py | xargs rm -rf RUN find ./python/lib/$runtime/site-packages -name __pycache__ -type d -exec rm -r {} \+ # When building ddtrace from branch, remove extra source files. These are From c650ec9fa3be0fc9cf9c9ec26df6bf499c1d913a Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Mon, 30 Mar 2026 14:28:06 -0400 Subject: [PATCH 2/3] version gate the patch.py file removing --- Dockerfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 64cd7d21..e5939f8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,8 +63,15 @@ RUN rm -rf \ # https://docs.python.org/3/using/cmdline.html#envvar-PYTHONNODEBUGRANGES RUN PYTHONNODEBUGRANGES=1 python -OO -m compileall -b ./python/lib/$runtime/site-packages # remove all .py files -# DEV: previously we kept patch.py files, but this is no longer necessary -RUN find ./python/lib/$runtime/site-packages -name \*.py | xargs rm -rf +# DEV: ddtrace>=4.7.0rc4 checks for .pyc files in addition to .py files for instrumentation +# discovery (DataDog/dd-trace-py#17196), so we can safely remove all .py files. +# For older versions, we need to keep patch.py files for instrumentation discovery. +RUN if python -c "from packaging.version import Version; import ddtrace; exit(0 if Version(ddtrace.__version__) >= Version('4.7.0rc4') else 1)"; then \ + find ./python/lib/$runtime/site-packages -name \*.py | xargs rm -rf; \ + else \ + find ./python/lib/$runtime/site-packages -name \*.py | grep -v ddtrace/contrib | xargs rm -rf && \ + find ./python/lib/$runtime/site-packages/ddtrace/contrib -name \*.py | grep -v patch.py | xargs rm -rf; \ + fi RUN find ./python/lib/$runtime/site-packages -name __pycache__ -type d -exec rm -r {} \+ # When building ddtrace from branch, remove extra source files. These are From 686a392e143dd845bf48f2818077768a75ee58b3 Mon Sep 17 00:00:00 2001 From: Brett Langdon Date: Mon, 30 Mar 2026 16:07:00 -0400 Subject: [PATCH 3/3] Apply suggestion from @brettlangdon --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e5939f8c..12e1f7ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,7 +66,7 @@ RUN PYTHONNODEBUGRANGES=1 python -OO -m compileall -b ./python/lib/$runtime/site # DEV: ddtrace>=4.7.0rc4 checks for .pyc files in addition to .py files for instrumentation # discovery (DataDog/dd-trace-py#17196), so we can safely remove all .py files. # For older versions, we need to keep patch.py files for instrumentation discovery. -RUN if python -c "from packaging.version import Version; import ddtrace; exit(0 if Version(ddtrace.__version__) >= Version('4.7.0rc4') else 1)"; then \ +RUN if python -c "from packaging.version import Version; import ddtrace; exit(0 if Version(ddtrace.__version__) >= Version('4.7.0rc3') else 1)"; then \ find ./python/lib/$runtime/site-packages -name \*.py | xargs rm -rf; \ else \ find ./python/lib/$runtime/site-packages -name \*.py | grep -v ddtrace/contrib | xargs rm -rf && \