Automatic instrumentation for ESM projects is supported starting from dd-trace@>=5.38.0. To enable automatic instrumentation in your ESM projects, run your application with the following Node option:
--import dd-trace/register.js
For command-line setup, use the following option instead:
--import dd-trace/initialize.mjs
# or
--loader dd-trace/initialize.mjs
Troubleshooting: Custom loader for module incompatibility
If there are errors launching your application when using this option, it is likely a module incompatibility. You can create your own hook file with the module and file in question excluded:
// hook.mjs
import { register } from 'node:module';
register('import-in-the-middle/hook.mjs', import.meta.url, {
parentURL: import.meta.url,
data: { exclude: [
/langsmith/,
/openai\/_shims/,
/openai\/resources\/chat\/completions\/messages/,
// Add any other modules you want to exclude
]}
});
To use this custom loader, run your application with the following Node option: