dd-trace-py
dd-trace-py copied to clipboard
fix(profiling): make explicitly marked main packages "my code"
If a user runs their code as a "main module" which they installed like a
library (python -m my_program args...), and expicilty specifies that
it's the main package via DD_MAIN_PACKAGE, we should consider code from
that module "my code". Right now we don't, though, because we mark that
code as a "library" in the profiling code provenance info. Check
whether the user specified a main package and make sure it gets marked
as "my code" by leaving the kind blank.
Checklist
- [ ] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the library release note guidelines
- The change includes or references documentation updates if necessary
- Backport labels are set (if applicable)
Reviewer Checklist
- [ ] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking API changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the release branch maintenance policy
CODEOWNERS have been resolved as:
releasenotes/notes/profiling-main-package-my-code-f650101b736c412e.yaml @DataDog/apm-python
ddtrace/internal/datadog/profiling/code_provenance.py @DataDog/profiling-python
tests/profiling_v2/test_code_provenance.py @DataDog/profiling-python
Bootstrap import analysis
Comparison of import times between this PR and base.
Summary
The average import time from this PR is: 281 ± 2 ms.
The average import time from base is: 283 ± 3 ms.
The import time difference between this PR and base is: -2.1 ± 0.1 ms.
Import time breakdown
The following import paths have shrunk:
ddtrace.auto
2.001 ms
(0.71%)
ddtrace.bootstrap.sitecustomize
1.324 ms
(0.47%)
ddtrace.bootstrap.preload
1.324 ms
(0.47%)
ddtrace.internal.remoteconfig.client
0.649 ms
(0.23%)
ddtrace
0.677 ms
(0.24%)
ddtrace.internal._unpatched
0.029 ms
(0.01%)
json
0.029 ms
(0.01%)
json.decoder
0.029 ms
(0.01%)
re
0.029 ms
(0.01%)
enum
0.029 ms
(0.01%)
types
0.029 ms
(0.01%)
Benchmarks
Benchmark execution time: 2025-07-16 01:36:05
Comparing candidate commit f7e7c6759d123d4b57100d204c5edda536046275 in PR branch push-xtxtmqtxtxny with baseline commit c3a0a8a55e35fbe49b74d6025c3012cc2fe5e137 in branch main.
Found 0 performance improvements and 3 performance regressions! Performance is the same for 545 metrics, 2 unstable metrics.
scenario:iastaspectsospath-ospathsplit_aspect
- 🟥
execution_time[+845.095ns; +1064.862ns] or [+17.435%; +21.969%]
scenario:iastaspectsospath-ospathsplitdrive_aspect
- 🟥
execution_time[+500.948ns; +561.721ns] or [+13.637%; +15.291%]
scenario:iastaspectsospath-ospathsplitext_aspect
- 🟥
execution_time[+740.869ns; +853.184ns] or [+16.259%; +18.724%]