Skip to content

fix(layer): detect ddtrace_serverless version so contrib .py files are removed - #901

Merged
astuyve merged 2 commits into
mainfrom
dilly/layer-serverless-wheel-version
Dec 4, 2026
Merged

astuyve merged 2 commits into
mainfrom
dilly/layer-serverless-wheel-version

Conversation

@astuyve

@astuyve astuyve commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Reads the ddtrace version from either ddtrace-*.dist-info or ddtrace_serverless-*.dist-info in the .py cleanup step of the layer Dockerfile.

Motivation

The downstream pipeline that dd-trace-py triggers (UPSTREAM_PIPELINE_ID) installs the ddtrace_serverless wheel (built with DD_SERVERLESS_BUILD=1). Its metadata is in ddtrace_serverless-<ver>.dist-info, so the grep … ddtrace-*.dist-info/METADATA step returned nothing. Version('') then raised InvalidVersion, and the else branch kept every ddtrace/contrib/**/patch.py. Those are 106 files, about 720 kB, shipped next to their .pyc files. From the build log:

from packaging.version import Version; exit(0 if Version('') >= Version('4.7.0rc3') else 1)
packaging.version.InvalidVersion: Invalid version: ''

This is a large part of why check-layer-size fails on dd-trace-py main builds. Layers built from the PyPI ddtrace wheel were not affected.

Results (Python 3.15, amd64, dd-trace-py main pipeline 157654945, ddtrace_serverless 4.18.0rc1)

unzipped zipped
main 25,466 kB 10,113 kB
this PR 24,746 kB (−720 kB) 9,891 kB

Testing Guidelines

  • Built the layer locally with UPSTREAM_PIPELINE_ID=157654945 PYTHON_VERSION=3.15 ARCH=amd64 ./scripts/build_layers.sh and ran check_layer_size.sh (numbers above). The build log now prints Detected ddtrace version: 4.18.0rc1, and the layer has no .py files left.
  • Smoke-tested the layer in public.ecr.aws/sam/build-python3.15:1: patched botocore, urllib3, httplib, sqlite3, logging, aiohttp, flask and subprocess, then invoked datadog_lambda.handler on an API Gateway event. It produced aws.lambda, aws.lambda.load, aws.lambda.import and sqlite.query spans, the same as main. Integration discovery from .pyc works for ddtrace ≥ 4.7.0rc3 (chore(tracer): contrib checking for patch.py and patch.pyc dd-trace-py#17196).

Additional Notes

Not addressed here: ddtrace.__version__ reports 0.0.0 with the serverless wheel, because importlib can't find a ddtrace distribution. This only affects CI builds from upstream wheels.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

🤖 Generated with Claude Code

…e removed

Wheels from dd-trace-py CI built with DD_SERVERLESS_BUILD=1 install as the
ddtrace_serverless distribution. The .py cleanup step only read
ddtrace-*.dist-info/METADATA, so the version came back empty, the packaging
check raised InvalidVersion, and the fallback branch kept every
ddtrace/contrib/**/patch.py (~720 kB) in the layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The metadata lookup handles either wheel distribution when the other metadata path is absent, while preserving the existing version-gated cleanup behavior.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 7893b5c

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b771615 | Docs | Give us feedback!

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@astuyve
astuyve merged commit 529e354 into main Dec 4, 2026
120 checks passed
@astuyve
astuyve deleted the dilly/layer-serverless-wheel-version branch December 4, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants