Skip to content

vendor bundled non-datadog dependencies#6958

Merged
rochdev merged 95 commits intomasterfrom
vendor-deps
Dec 11, 2025
Merged

vendor bundled non-datadog dependencies#6958
rochdev merged 95 commits intomasterfrom
vendor-deps

Conversation

@rochdev
Copy link
Copy Markdown
Member

@rochdev rochdev commented Nov 21, 2025

What does this PR do?

Vendor bundled versions of non-Datadog dependencies.

Motivation

As we start supporting more and more non-server environments, our package size becomes increasingly problematic. Other than native addons (which are not included in non-server environments anyway), most of it comes from our dependencies, and most of their size comes from files that they package but never actually use. But even the code they do use is often unoptimized as it's not minified and is spread across many files. All of this not only makes their package bigger but also slower to load. By including vendored versions of our dependencies, we can make sure all of them are optimized in the way we want. This also has several other benefits:

  • Determinism: Right now what we test is not necessarily what the user installs. Even our tests themselves are inconsistent as unit tests use the lockfile, but not integration tests since they do a real install. This also means that once all dependencies are vendored, we could even skip the install completely in tests.
  • Speed: Installing dd-trace and all of its dependencies can take several seconds because of the resolution stage and the hundred or so additional transitive dependencies that have to be downloaded. With vendors the resolution is instant and no additional download is needed.
  • Isolation: Once all dependencies are included (right now dependencies under @datadog are not included) then the tracer becomes self-contained. Once packed, it can be unpacked and already fully functional without any additional install. This also has the benefit of avoiding side-effects when merging node_modules, for example with the Lambda extension.
  • Consistency: This is already basically how we ship the SDK in Serverless and SSI environments, but today it's done with brittle hacks in the builds of each target instead of upstream in the library. Other languages also already vendor their dependencies (Java, .NET, etc).

Additional Notes

A next step would be to make the native addons a separate package so that they don't need to be removed when repackaging in a non-server environment and would instead simply not be installed in the first place.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 21, 2025

Overall package size

Self size: 3.56 MB
Deduped: 4.45 MB
No deduping: 4.45 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 1.15.0 | 127.66 kB | 856.24 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.82%. Comparing base (519137b) to head (5bf77bd).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6958   +/-   ##
=======================================
  Coverage   84.82%   84.82%           
=======================================
  Files         515      515           
  Lines       22021    22022    +1     
=======================================
+ Hits        18680    18681    +1     
  Misses       3341     3341           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-official

This comment has been minimized.

@pr-commenter
Copy link
Copy Markdown

pr-commenter Bot commented Nov 21, 2025

Benchmarks

Benchmark execution time: 2025-12-11 17:17:45

Comparing candidate commit 5bf77bd in PR branch vendor-deps with baseline commit 519137b in branch master.

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

@rochdev rochdev force-pushed the vendor-deps branch 3 times, most recently from 25ff3b5 to 2293587 Compare November 24, 2025 17:54
@rochdev rochdev marked this pull request as ready for review November 26, 2025 02:01
@rochdev rochdev requested review from a team as code owners November 26, 2025 02:01
@simon-id
Copy link
Copy Markdown
Member

simon-id commented Nov 27, 2025

Uuuh, i am ok with vendoring, but should we really commit obfuscated code like that ? I don't feel comfortable with that for security reasons, anyone can just hide shit mean things:) in there, and pretend it's just an update of the lib. I'd prefere if this was done by a script in the CI or something, before publishing the package.

@rochdev
Copy link
Copy Markdown
Member Author

rochdev commented Dec 1, 2025

I'd prefere if this was done by a script in the CI or something, before publishing the package.

Altering what you ship before shipping it is in itself a security risk, but it also means you're shipping something untested, so that's not an option.

anyone can just hide shit in there, and pretend it's just an update of the lib

This is already true for any update to one of our libraries, but I get what you're saying in that it would now be in the actual codebase. The problem is that some of our dependencies are already minified, so I'm not sure how we would be able to handle those as even if we disable minification on our end those would still not be human readable. Any suggestions for those cases?

@simon-id
Copy link
Copy Markdown
Member

simon-id commented Dec 2, 2025

Altering what you ship before shipping it is in itself a security risk, but it also means you're shipping something untested, so that's not an option.

Sorry I meant bundling before testing of course 👍 like i don't want it to be bundling just as the last step before release. I mean bundling as a npm script to run after a dev install: when creating a new dev setup, when installing the package in the CI, before testing, etc, etc.

[your second point]

We have minified dependencies ??? what if we just stop using them ? sounds not great to have minified dependencies imo.

@rochdev
Copy link
Copy Markdown
Member Author

rochdev commented Dec 3, 2025

I mean bundling as a npm script to run after a dev install: when creating a new dev setup, when installing the package in the CI, before testing, etc, etc.

I think that could work, I'd need to add some sort of bundling workflow that runs before all other workflows and stores the output in a cache or an artifact. I'm a bit worried about artifacts though given all the issues we've been having in system tests. @cbeauchesne Did we ever get an answer from GitHub as to what is going on?

Generally speaking I'm not sure which option I prefer. We could always just have a validation step that ensures the bundle was not tempered with and push it to GitHub. This would avoid having to rebuild it everywhere every time, but at the cost of committed code that is not readable. This also has the benefit of the library being usable directly from Git as it is today. Or we can do as you say and build every time which ensures the build is always fresh and doesn't pollute the repo, but then everyone pays the cost of bundling every time and the library can no longer be installed directly from Git.

I think because of the latter point I tend to lean towards committing the files to preserve that ability and simply add a validation step, but otherwise it's very similar as the build time is in milliseconds and not seconds or minutes. WDYT?

We have minified dependencies ??? what if we just stop using them ? sounds not great to have minified dependencies imo.

We don't decide how dependencies are packaged, and if we don't trust our dependencies our only option is to stop using all of them. Short of that, we just have to accept that there is no standard way to package and everyone does their own thing which may also change over time.

@simon-id
Copy link
Copy Markdown
Member

simon-id commented Dec 3, 2025

Did we ever get an answer from GitHub as to what is going on?

they told us "works on my machine"

@rochdev rochdev marked this pull request as draft December 4, 2025 02:41
@rochdev rochdev force-pushed the vendor-deps branch 2 times, most recently from f14532a to 4503806 Compare December 4, 2025 18:22
@cbeauchesne
Copy link
Copy Markdown
Contributor

Did we ever get an answer from GitHub as to what is going on?

Unfortunately no. At some point we'll need more data to prove them the impact this issue have. But TBH, it happened a little bit less those past weeks.

@rochdev rochdev marked this pull request as ready for review December 4, 2025 22:54
@rochdev rochdev marked this pull request as draft December 5, 2025 19:15
@rochdev rochdev dismissed stale reviews from BridgeAR and watson via bfd1416 December 11, 2025 17:05
@rochdev rochdev merged commit ffa3de4 into master Dec 11, 2025
889 of 894 checks passed
@rochdev rochdev deleted the vendor-deps branch December 11, 2025 21:01
dd-octo-sts Bot pushed a commit that referenced this pull request Dec 12, 2025
@dd-octo-sts dd-octo-sts Bot mentioned this pull request Dec 12, 2025
nina9753 pushed a commit that referenced this pull request Dec 20, 2025
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.

7 participants