Skip to content

ghost91-/dd-trace-esm-memory-leak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Datadog Trace Memory Leak Example

This repository demonstrates a memory leak issue with dd-trace when using ESM modules. The leak occurs when the application handles requests after being started with Datadog's ESM integration.

Problem Description

The memory leak is triggered when:

  1. The application is started with Datadog's ESM integration (--import dd-trace/initialize.mjs)
  2. A dynamic import that fails at runtime is executed
  3. Requests are made to the application

While failing dynamic imports may not be typical, they are used in some applications to conditionally execute code based on whether dependencies are installed.

Setup

  1. Install dependencies:
npm install
  1. Build the application:
npm run build

Reproducing the Issue

  1. Start the application with Datadog tracing:
npm start
  1. In another terminal, continuously call the endpoint to trigger the memory leak:
./continueslyCallEndpoint.sh
  1. Monitor memory usage - you should observe increasing memory consumption over time.

Code Details

The issue is in index.ts where a failing dynamic import is executed on each request:

await import("non-existing-module"); // Always throws

This pattern, combined with Datadog's ESM integration, causes spans and other objects to not be garbage collected properly.

Expected Behavior

Memory usage should remain stable.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors