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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nsrip-dd
Copy link
Contributor

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

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.
Copy link
Contributor

CODEOWNERS have been resolved as:

ddtrace/internal/datadog/profiling/code_provenance.py                   @DataDog/profiling-python
tests/profiling_v2/test_code_provenance.py                              @DataDog/profiling-python

Copy link
Contributor

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 279 ± 2 ms.

The average import time from base is: 282 ± 3 ms.

The import time difference between this PR and base is: -2.0 ± 0.1 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 1.975 ms (0.71%)
ddtrace.bootstrap.sitecustomize 1.301 ms (0.47%)
ddtrace.bootstrap.preload 1.301 ms (0.47%)
ddtrace.internal.remoteconfig.client 0.639 ms (0.23%)
ddtrace 0.674 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%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 11, 2025

Benchmarks

Benchmark execution time: 2025-06-11 18:38:55

Comparing candidate commit 354e1d1 in PR branch push-xtxtmqtxtxny with baseline commit 55e0c06 in branch main.

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

scenario:telemetryaddmetric-1-distribution-metric-1-times

  • 🟥 execution_time [+307.284ns; +366.095ns] or [+10.437%; +12.434%]

scenario:telemetryaddmetric-1-gauge-metric-1-times

  • 🟥 execution_time [+240.314ns; +288.065ns] or [+11.028%; +13.220%]

# specified that that's the main package, make sure it shows up as
# "my code" in the UI. Do this by leaving the "kind" blank
kind = "library" if name != main_package else ""

lib = libraries.get(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove main_package from libraries instead of doing a ternary in a loop?

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