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

Open
#1,337 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
frontend, web-dev

Research direction

Start at the Signals constructor where NetworkGenerator is registered and trace the SignalsPlugin configuration path. Check how the proposed disableNetworkSignals option should reach that registration, then verify that fetch no longer recurses with DataDog RUM while interaction and navigation signals remain enabled.

Written by the indexing model from the issue text.

Description

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
Dominant language
TypeScript
Stars
477
Forks
160
Avg merge
6h 19m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from segmentio/analytics-next

All issues in segmentio/analytics-next

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.