feat(packages): symlinked .runfile pkgs should not be usercode (#13474) [backport 2.21] #14192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This came up again so I'll backport to 2.21 - https://datadoghq.atlassian.net/browse/DEBUG-4257
While dogfooding, we noticed that code origins was still sending third-party code for bazel, e.g. this path:
We have code specifically to handle the
*.runfiles
path, but we pass the string to a Path and call the resolve which removes the*.runfiles
segment.To fix this, we update the path resolution logic in
ddtrace/internal/packages.py
to improve handling of symlinks and add a new test to ensure correct behavior when symlinks are involved.ddtrace/internal/packages.py
: Updated_root_module
to usepath
instead ofpath.resolve()
to ensure symlinks are searched properly. Similarly, updatedfilename_to_package
to usepath
for consistent path handling. [1] [2]tests/internal/test_packages.py
: Addedtest_third_party_packages_symlinks
to verify that symlinks, particularly those with.runfiles
in their paths, are correctly excluded from being identified as user code. This ensures the logic remains robust in environments with symlinked directories.Refs: DEBUG-3926, DEBUG-4257
(cherry picked from commit 197dbe2)
Checklist
Reviewer Checklist