Skip to content

Maximum call stack size exceeded when SignalsPlugin and DataDog RUM are both active #1337

@bwhiting2356

Description

@bwhiting2356

When using SignalsPlugin alongside DataDog RUM (@datadog/browser-rum), the app crashes with:

RangeError: Maximum call stack size exceeded

This is caused by infinite recursion between the two libraries’ fetch instrumentation.


❗ Error

RangeError: Maximum call stack size exceeded
    at interceptedFetch (@segment/analytics-signals)
    at instrumentation (@datadog/browser-rum)
    at interceptedFetch (@segment/analytics-signals)
    at instrumentation (@datadog/browser-rum)
    ... (repeats infinitely)

🔁 Steps to Reproduce

  1. Install Segment packages:

     npm install @segment/analytics-next @segment/analytics-signals
    
  2. Install DataDog RUM:

     npm install @datadog/browser-rum
    
  3. Initialize both:

Segment with SignalsPlugin

    const analytics = new AnalyticsBrowser();

    await analytics.load({
      writeKey: 'xxx',
      plugins: [new SignalsPlugin()],
    });

DataDog RUM

    datadogRum.init({
      applicationId: 'xxx',
      clientToken: 'xxx',
      trackResources: true, // default
    });
  1. App crashes immediately with a stack overflow.

🔍 Root Cause

Both libraries wrap the global fetch API.
When a fetch call is made, each wrapper calls the other in an infinite loop.

The NetworkGenerator is registered unconditionally in the Signals constructor:

    void this.registerGenerator([...domGenerators, new NetworkGenerator()]);

The existing config options (networkSignalsAllowSameDomain, networkSignalsAllowList, etc.) only filter which signals are emitted — the fetch wrapper is still installed and causes the conflict.


🛠️ Workaround

We’re using patch-package to remove NetworkGenerator from the registered generators:

    - void this.registerGenerator([...domGenerators, new NetworkGenerator()]);
    + void this.registerGenerator([...domGenerators]);

This disables network signals but keeps interaction and navigation signals working.


💡 Suggested Fix

Add a configuration option to disable network signal generation entirely:

    new SignalsPlugin({
      disableNetworkSignals: true,
    });

This would skip registering NetworkGenerator, avoiding conflicts with other tools that instrument fetch (DataDog, Sentry, New Relic, etc.).


🧪 Environment

  • @segment/analytics-signals: 2.4.4
  • @segment/analytics-next: 1.76.0
  • @datadog/browser-rum: 5.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions