Skip to content

Conversation

@hoolioh
Copy link
Contributor

@hoolioh hoolioh commented Jul 14, 2025

Both profiling and src/native depend on libdatadog, but slightly different manner prior to this PR.

  • Profiling consumed statically built libdatadog libraries
  • src/native Rust crate simply added libdatadog crates as dependencies

This PR makes sure that we build libdatadog dependency as part of src/native and export profiling ffi symbols there.

Regarding benchmark SLOs:

  • Mostly increasing max_rss_usage. Looks ok and acceptable to @taegyunkim. We're changing the way we build and consume libdatadog dependency.

PROF-12235

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

hoolioh added 8 commits July 14, 2025 16:55
* Add new cmake file to find libnative components.
* Modify dd_wrapper cmake in order to link against libnative.
* Modify ddup cmake in order to link against libnative.
* Change crashtracker compilation so it links agains libnative. Link to
  python runtime as a workaround to solve secondary dependencies from
  libnative.so (temporary until the crashtracker PyO3 bindings are
  ready).
* Call build_libnative from project's root folder.
* Fix FindLibNative in order not to include libnative whole folder
  structure.
* Workaround test linking.
@hoolioh hoolioh added the changelog/no-changelog A changelog entry is not required for this PR. label Jul 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

CODEOWNERS have been resolved as:

build_libnative.py                                                      @DataDog/apm-core-python
ddtrace/internal/datadog/profiling/cmake/FindLibNative.cmake            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/crashtracker/python_runtime_stub.c   @DataDog/profiling-python
src/native/.cargo/config.toml                                           @DataDog/apm-core-python
.github/workflows/build_deploy.yml                                      @DataDog/python-guild @DataDog/apm-core-python
.github/workflows/build_python_3.yml                                    @DataDog/python-guild @DataDog/apm-core-python
.github/workflows/system-tests.yml                                      @DataDog/python-guild @DataDog/apm-core-python
.gitlab/benchmarks/bp-runner.microbenchmarks.fail-on-breach.yml         @DataDog/python-guild @DataDog/apm-core-python
ddtrace/appsec/_iast/_taint_tracking/CMakeLists.txt                     @DataDog/asm-python
ddtrace/internal/datadog/profiling/build_standalone.sh                  @DataDog/profiling-python
ddtrace/internal/datadog/profiling/crashtracker/CMakeLists.txt          @DataDog/profiling-python
ddtrace/internal/datadog/profiling/dd_wrapper/CMakeLists.txt            @DataDog/profiling-python
ddtrace/internal/datadog/profiling/dd_wrapper/test/CMakeLists.txt       @DataDog/profiling-python
ddtrace/internal/datadog/profiling/ddup/CMakeLists.txt                  @DataDog/profiling-python
pyproject.toml                                                          @DataDog/python-guild
setup.py                                                                @DataDog/python-guild
src/native/Cargo.lock                                                   @DataDog/apm-core-python
src/native/Cargo.toml                                                   @DataDog/apm-core-python
src/native/lib.rs                                                       @DataDog/apm-core-python

@hoolioh hoolioh changed the title Julio/merge libraries new branch Consolidate libdatadog symbols in lib_native Jul 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

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

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

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

Import time breakdown

The following import paths have grown:

ddtrace.auto 0.293 ms (0.11%)
ddtrace 0.293 ms (0.11%)
ddtrace._logger 0.293 ms (0.11%)
ddtrace.internal.telemetry 0.293 ms (0.11%)
ddtrace.settings._agent 0.293 ms (0.11%)
ddtrace.settings._core 0.293 ms (0.11%)
ddtrace.internal.native 0.293 ms (0.11%)
ddtrace.internal.native._native 0.293 ms (0.11%)

The following import paths have shrunk:

ddtrace.auto 2.358 ms (0.85%)
ddtrace.bootstrap.sitecustomize 1.680 ms (0.60%)
ddtrace.bootstrap.preload 1.680 ms (0.60%)
ddtrace.internal.remoteconfig.client 0.661 ms (0.24%)
ddtrace.settings.crashtracker 0.290 ms (0.10%)
ddtrace.internal.datadog.profiling.crashtracker 0.290 ms (0.10%)
ddtrace.internal.datadog.profiling.crashtracker._crashtracker 0.290 ms (0.10%)
ddtrace 0.678 ms (0.24%)
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%)

hoolioh added 7 commits July 16, 2025 17:55
* Handle IS_EDITABLE when issuing pip install -e .
* Set soname dynamically for _native library so auditwheel is able to
  locate it.
* Set RPATH so the linker is able to locate the library without setting
  LD_LIBRARY_PATH.
@hoolioh hoolioh force-pushed the julio/merge-libraries-new-branch branch from fbfa05c to 97b05e7 Compare July 17, 2025 09:37
@taegyunkim taegyunkim force-pushed the julio/merge-libraries-new-branch branch from 117ef50 to 4f03739 Compare July 31, 2025 22:50
@taegyunkim
Copy link
Contributor

I've been seeing a very weird issue where _crashtracker.so is linked to a _native.so file with wrong python version. This was due to the fact that 1) we run build in same directory for all different versions and 2) libdd_wrapper.so didn't have different names for different python versions, and same libdd_wrapper.so was used for all different versions of Python and 3) _crashtracker.so -> libdd_wrapper.so->_native.so` this .so dependency chain.

Before this PR it was ok for libdd_wrapper.so to not be compiled differently for different versions of Python because it didn't reference any of Python symbols. However, with this PR, since it started to depend on _native.so, now it has to.

There are few other things that I discovered while debugging this PR

@taegyunkim taegyunkim merged commit 70cc39e into main Aug 1, 2025
925 of 927 checks passed
@taegyunkim taegyunkim deleted the julio/merge-libraries-new-branch branch August 1, 2025 23:11
gnufede pushed a commit that referenced this pull request Aug 4, 2025
Both profiling and src/native depend on libdatadog, but slightly
different manner prior to this PR.
- Profiling consumed statically built libdatadog libraries
- src/native Rust crate simply added libdatadog crates as dependencies

This PR makes sure that we build libdatadog dependency as part of
src/native and export profiling ffi symbols there.

Regarding benchmark SLOs: 
- Mostly increasing `max_rss_usage`. Looks ok and acceptable to
@taegyunkim. We're changing the way we build and consume libdatadog
dependency.


[PROF-12235](https://datadoghq.atlassian.net/browse/PROF-12235?atlOrigin=eyJpIjoiNzM4ODY4ZTI3MjFjNGMwMjgzMGUwNjhkODhlNjA1NjIiLCJwIjoiaiJ9)

## Checklist
- [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)


[PROF-12235]:
https://datadoghq.atlassian.net/browse/PROF-12235?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Signed-off-by: Taegyun Kim <[email protected]>
Co-authored-by: Taegyun Kim <[email protected]>
Co-authored-by: Gabriele N. Tornetta <[email protected]>
taegyunkim added a commit that referenced this pull request Aug 4, 2025
#13984 broke baseline:build job as 1) it upgraded in PyO3 version 2)
changed how _taint_tracking is built


## Checklist
- [x] 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](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## 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](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
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](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
taegyunkim added a commit that referenced this pull request Oct 21, 2025
## Description

Use Python version specific `CARGO_TARGET_DIR` for src/native, Rust
extension module. This has a few benefits

1. Parallelizing build_base_venv jobs. While working on #13984, I
noticed that since build_base_venv jobs on GitLab run in the same
dd-trace-py directory and use the same `CARGO_TARGET_DIR`, and there's
cargo lock, only one of them could run at a time.
2. Re-use Rust build artifacts as much as possible. Consider a scenario
one builds dd-trace-py using multiple different Python versions in a
row. In that case, the build had to spend extra time after switching to
a different Python version, as src/native has to be re-linked and
re-built with different Python binaries.

<!-- Provide an overview of the change and motivation for the change -->

## Testing

<!-- Describe your testing strategy or note what tests are included -->

## Risks

<!-- Note any risks associated with this change, or "None" if no risks
-->

## Additional Notes

<!-- Any other information that would be helpful for reviewers -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants