Skip to content

perf(runtime): use dd-trace loader registration - #819

Merged
joeyzhao2018 merged 2 commits into
mainfrom
BridgeAR/2026-08-28-loader-registration
Sep 1, 2026
Merged

perf(runtime): use dd-trace loader registration#819
joeyzhao2018 merged 2 commits into
mainfrom
BridgeAR/2026-08-28-loader-registration

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Aug 28, 2026

Copy link
Copy Markdown
Member

Load the function-local dd-trace registration entry during tracer initialization instead of registering another loader hook from the Lambda wrapper.

Direct Module.register() creates a loader worker and synchronous startup communication. The canonical entry can select in-process hooks. Older function-local tracers without register.js retain the direct fallback.

Paired Lambda trials reduced module load by 79.549 ms and startup total by 65.788 ms (21.47%). A fresh local Node 22.23.2 benchmark across 40 alternating pairs reduced module load by 45.881 ms and startup total by 45.264 ms (15.54%).

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 28, 2026

Copy link
Copy Markdown

Pipelines

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

DataDog/datadog-lambda-js | publish layer sandbox (node26): [us-west-2] — 🔄 Retry may pass, looks flaky

View more details · View in GitLab

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 457adeb | Docs | View more details | Give us feedback!

@BridgeAR
BridgeAR marked this pull request as ready for review August 28, 2026 20:43
@BridgeAR
BridgeAR requested review from a team as code owners August 28, 2026 20:43
@BridgeAR
BridgeAR requested a review from shreyamalpani August 28, 2026 20:43

@joeyzhao2018 joeyzhao2018 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Direct Module.register() forces a loader worker even when the installed tracer supports in-process hooks. Loading the function-local tracer registration entry preserves preload and older-runtime fallbacks.

Paired Lambda trials reduced module load by 79.549 ms and startup total by 65.788 ms (21.47%).
Function-local dd-trace v5.5 has loader-hook.mjs but no register.js. The fallback preserves ESM instrumentation while newer tracers use their optimized registration entry point.
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-08-28-loader-registration branch from 2faef26 to 457adeb Compare September 1, 2026 15:06

@joeyzhao2018 joeyzhao2018 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you

@joeyzhao2018
joeyzhao2018 merged commit c3f2cc9 into main Sep 1, 2026
53 of 55 checks passed
@joeyzhao2018
joeyzhao2018 deleted the BridgeAR/2026-08-28-loader-registration branch September 1, 2026 16:09
joeyzhao2018 added a commit that referenced this pull request Sep 2, 2026
Three conflicts, all resolved as unions of both sides:

- src/handler.mjs: main (#819) moved the ESM loader-hook registration out of
  handler.mjs into initTracer() in src/runtime/module_importer.js, so this
  branch's copy of esmLoaderAlreadyRegistered() and the Module.register()
  block are dropped in favor of main's. Kept this branch's new
  DD_TRACE_STARTUP_LOGS default. dd-trace 6.12.0 ships both register.js and
  loader-hook.mjs, so main's registration path works on the v6 line.

- integration_tests/container/cjs/Dockerfile: kept this branch's
  DD_TRACE_VERSION build-arg + `npm pkg set` override alongside main's
  `COPY package.json *.js` for the new manual-wrap fixture handlers.

- integration_tests/container/cjs/package.json: main's axios pin plus this
  branch's dd-trace 6.12.0.

main's integration_tests_local/run.sh already probes for scripts/install_deps.sh
and scripts/dd_trace_versions.sh and passes --build-arg DD_TRACE_VERSION, so the
new local harness picks up the per-runtime tracer split without changes.

Verified: yarn build, yarn test (638 tests, 52 suites — including main's new
src/handler.spec.ts and src/runtime/module-importer.spec.ts), yarn lint and
yarn check-formatting all pass against dd-trace 6.12.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants