GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(esm): await dd-trace/register.mjs before loading handlers by pabloerhard · Pull Request #872 · DataDog/datadog-lambda-js

Conversation

@pabloerhard

@pabloerhard pabloerhard commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

  • When the tracer ships dd-trace/register.mjs (DataDog/dd-trace-js#11296), the programmatic bootstrap loads it with native import() and awaits it.
  • handler.mjs awaits initTracer(), so the hooks are installed before the custom trace extractor and the customer handler are loaded.
  • Tracers without register.mjs keep the existing path unchanged: register.js when module.register() exists, falling back to loader-hook.mjs for tracers without register.js.
  • Registration errors are still caught and logged at debug level, so they never break the customer's function.

Motivation

AWS Lambda disables require(esm). Requiring register.js therefore cannot install the synchronous loader hooks (Module.registerHooks) and falls back to the asynchronous module.register() loader, which Node.js 26 deprecates and nodejs/node#67090 removes. Without that loader, ES modules load without instrumentation. The bootstrap also skipped registration entirely when module.register() was absent.

register.mjs picks the synchronous hooks or the asynchronous fallback itself and does not register twice, so the bootstrap only needs to detect it and await it.

Testing Guidelines

  • yarn test: 55 suites, 734 tests pass. yarn lint and yarn check-formatting pass.
  • New src/handler-esm-registration.spec.ts runs the built dist/handler.mjs against a fake tracer with --no-experimental-require-module and module.register removed:
    • register.mjs loads before the extractor and the handler;
    • if register.mjs fails, the handler still loads and returns its result.
  • src/handler.spec.ts (durable handler, real tracer) now runs with --no-experimental-require-module and counts module.register / module.registerHooks calls instead of checking that register.js loaded. Without this, it would fail as soon as the dev dependency moves to a tracer with register.mjs (checked by swapping in dd-trace 6.27.0).
  • src/runtime/module-importer.spec.ts keeps covering tracers without register.mjs.
  • Affected specs also pass on Node 18.20.8, 20.19.5 and 22.19.0 (the durable tests are skipped below Node 22, as before).
  • Manual check with real tracers on Node 26 and --no-experimental-require-module, verifying that an ES module imported by the customer handler is intercepted:
    • dd-trace 6.27.0: instrumented through synchronous hooks, including with module.register removed (base: not instrumented when module.register is removed);
    • dd-trace 6.24.0: instrumented through module.register(), as today;
    • dd-trace 5.138.0 on Node 18.20.8: instrumented through module.register().

Additional Notes

  • The synchronous path requires a tracer that includes fix(esm): register synchronous hooks without require(esm) dd-trace-js#11296 (6.27.0 / 5.138.0). No dependency bump in this PR.
  • Preload detection (NODE_OPTIONS / execArgv) is unchanged.
  • No AWS deployment was run.

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

datadog-datadog-prod-us1[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@pabloerhard
fix(esm): await dd-trace/register.mjs before loading handlers
514ea93
Lambda disables require(esm), so requiring dd-trace/register.js cannot
install the synchronous loader hooks. It falls back to module.register(),
which Node.js 26 deprecates and nodejs/node#67090 removes, leaving ES
modules uninstrumented.

When the tracer ships register.mjs (DataDog/dd-trace-js#11296), import it
natively and await it before the custom extractor and customer handler are
loaded. Tracers without register.mjs keep the existing register.js path.
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 24, 2026 •
edited by datadog-prod-us1-6 Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Pipelines

✨ Unblock PR with BitsAI

❌ Errors

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

🚦 1 Pipeline job failed

DataDog/datadog-lambda-js | e2e-test-status — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

Useful? React with 👍 / 👎

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joeyzhao2018 joeyzhao2018 mentioned this pull request Nov 24, 2026
fix(esm): await tracer loader registration before loading handlers #871
Closed
3 of 11 tasks
joeyzhao2018
joeyzhao2018 approved these changes Nov 24, 2026
View reviewed changes
@pabloerhard
pabloerhard marked this pull request as ready for review November 24, 2026 22:39
@pabloerhard
pabloerhard requested a review from a team as a code owner November 24, 2026 22:39
datadog-datadog-prod-us1[bot]
datadog-datadog-prod-us1 Bot reviewed Nov 24, 2026
View reviewed changes

@datadog-datadog-prod-us1 datadog-datadog-prod-us1 Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Bits Code Review: PASS

More details

Loader registration completes before extractor and handler imports, while registration failures still allow handler startup. The static review identified no actionable regressions.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 514ea93

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@datadog-datadog-prod-us1 datadog-datadog-prod-us1[bot] datadog-datadog-prod-us1[bot] left review comments
@joeyzhao2018 joeyzhao2018 joeyzhao2018 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@pabloerhard @joeyzhao2018
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.