Skip to content

fix(profiling): make explicitly marked main packages "my code" #13649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Jun 11, 2025

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

Copy link
Contributor

github-actions bot commented Jun 11, 2025

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

Copy link
Contributor

github-actions bot commented Jun 11, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 287 ± 3 ms.

The average import time from base is: 283 ± 7 ms.

The import time difference between this PR and base is: 4.5 ± 0.2 ms.

Import time breakdown

The following import paths have grown:

ddtrace.auto 0.914 ms (0.32%)
ddtrace.bootstrap.sitecustomize 0.484 ms (0.17%)
ddtrace.appsec._common_module_patches 0.260 ms (0.09%)
ddtrace.appsec._asm_request_context 0.260 ms (0.09%)
ddtrace.appsec._utils 0.260 ms (0.09%)
ddtrace.bootstrap.preload 0.224 ms (0.08%)
ddtrace.internal.products 0.151 ms (0.05%)
importlib.metadata 0.151 ms (0.05%)
zipfile 0.151 ms (0.05%)
zipfile._path 0.151 ms (0.05%)
ddtrace.internal.flare.flare 0.039 ms (0.01%)
logging.handlers 0.039 ms (0.01%)
ddtrace.debugging._import 0.034 ms (0.01%)
ddtrace.debugging._function.discovery 0.034 ms (0.01%)
ddtrace 0.431 ms (0.15%)
ddtrace._logger 0.186 ms (0.06%)
ddtrace.internal.telemetry 0.186 ms (0.06%)
ddtrace.internal.telemetry.writer 0.148 ms (0.05%)
http.client 0.148 ms (0.05%)
email.parser 0.148 ms (0.05%)
email.feedparser 0.148 ms (0.05%)
email._policybase 0.148 ms (0.05%)
email.header 0.148 ms (0.05%)
email.charset 0.148 ms (0.05%)
ddtrace.settings._config 0.167 ms (0.06%)
ddtrace.internal.gitmetadata 0.167 ms (0.06%)
ddtrace.ext.ci 0.167 ms (0.06%)
ddtrace.ext.git 0.167 ms (0.06%)
tempfile 0.167 ms (0.06%)
ddtrace.trace 0.078 ms (0.03%)
ddtrace._trace.tracer 0.021 ms (0.01%)
ddtrace.internal.debug 0.021 ms (0.01%)

The following import paths have shrunk:

ddtrace.auto 1.202 ms (0.42%)
ddtrace 0.669 ms (0.23%)
ddtrace.internal._unpatched 0.030 ms (0.01%)
json 0.030 ms (0.01%)
json.decoder 0.030 ms (0.01%)
re 0.030 ms (0.01%)
enum 0.030 ms (0.01%)
types 0.030 ms (0.01%)
ddtrace.bootstrap.sitecustomize 0.532 ms (0.19%)
ddtrace.bootstrap.preload 0.532 ms (0.19%)
ddtrace.internal.remoteconfig.client 0.532 ms (0.19%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 11, 2025

Benchmarks

Benchmark execution time: 2025-07-14 19:39:26

Comparing candidate commit f89f4a1 in PR branch push-xtxtmqtxtxny with baseline commit b4bdef9 in branch main.

Found 0 performance improvements and 2 performance regressions! Performance is the same for 546 metrics, 2 unstable metrics.

scenario:iastaspects-format_map_aspect

  • 🟥 execution_time [+450.417ns; +541.154ns] or [+13.994%; +16.813%]

scenario:iastaspectsospath-ospathjoin_aspect

  • 🟥 execution_time [+923.361ns; +999.649ns] or [+14.903%; +16.134%]

@nsrip-dd nsrip-dd force-pushed the push-xtxtmqtxtxny branch from 354e1d1 to c700d8e Compare July 8, 2025 19:37
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.
@nsrip-dd nsrip-dd force-pushed the push-xtxtmqtxtxny branch from c700d8e to 3c3895d Compare July 8, 2025 19:56
@nsrip-dd nsrip-dd marked this pull request as ready for review July 8, 2025 20:08
@nsrip-dd nsrip-dd requested review from a team as code owners July 8, 2025 20:08
@nsrip-dd nsrip-dd requested review from taegyunkim and wconti27 July 8, 2025 20:08
# that that's the main package, make sure it shows up as "my code" in
# the UI. Do this by leaving the kind blank (but not deleting the
# library so we can still associate the library with its files)
_, _, main_package = gitmetadata.get_git_tags()
Copy link
Contributor

Choose a reason for hiding this comment

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

(unrelated) I find it a bit weird that we have to retrieve this information via a git metadata utility module 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants