Skip to content

Add configuration option to disable lazy loading of session replay recorder module #3939

@asif-st-republic

Description

@asif-st-republic

Problem

The Datadog RUM SDK lazy-loads the session replay recorder module using dynamic import(), which causes issues in environments that don't support code splitting or dynamic chunk loading, such as:

  • Rails asset pipeline (Sprockets)
  • Legacy webpack configurations without chunkFilename configured
  • Build systems that require all assets to be declared in a manifest

When session replay is enabled (sessionReplaySampleRate > 0), the SDK attempts to fetch the recorder module at runtime:

GET /assets/startRecording

This results in a 404 error and session replay fails to initialize:

Datadog Browser SDK: Recorder failed to start: an error occurred while initializing the module: 
TypeError: Failed to fetch dynamically imported module: https://example.com/assets/startRecording

Requested Feature

Add a configuration option to the datadogRum.init() call that statically bundles the recorder module instead of lazy-loading it:

datadogRum.init({
  applicationId: 'xxx',
  clientToken: 'xxx',
  site: 'datadoghq.com',
  service: 'my-app',
  sessionReplaySampleRate: 100,
  // NEW OPTION:
  bundleRecorderModule: true // or lazyLoadRecorder: false
})

When this option is enabled, the SDK should:

  1. Import the recorder module statically at build time
  2. Skip the dynamic import() call
  3. Use the bundled recorder directly

Workarounds

Currently, the only workarounds are:

  1. Disable session replay entirely (sessionReplaySampleRate: 0)
  2. Suppress console errors (poor UX)
  3. Migrate to a different build system (significant effort)

Environment

  • Browser: All
  • SDK Version: @datadog/browser-rum 6.23.0
  • Build System: Rails asset pipeline (Sprockets)
  • Webpack: 4.x without code splitting configured

Impact

This affects any application using Rails, Django, or other traditional server-rendered frameworks with asset pipelines that don't support dynamic module loading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions