Skip to content

🐛 Datadog browser SDK not fully tree-shakable due to side effects #4088

Open

Description

@Lav39

We are using the @datadog/browser-logs, @datadog/browser-rum npm libraries and noticed that they are not being properly tree-shaken in our build. As a result, a large amount of unused code (thousands of lines) is included in the final bundle.

The root cause appears to be side effects introduced at module scope. For example, in the following file:

https://github.com/DataDog/browser-sdk/blob/main/packages/logs/src/entries/main.ts#L60

The lines below introduce side effects during import:

export const datadogLogs = makeLogsPublicApi(startLogs)
defineGlobal(getGlobalObject<BrowserWindow>(), 'DD_LOGS', datadogLogs)

which prevents effective tree-shaking by bundlers.

This behavior makes it difficult to exclude unused functionality and leads to unnecessary bundle size increase.

To Reproduce
Steps to reproduce the behavior:
Just add imports

import { datadogRum } from '@datadog/browser-rum';
import { datadogLogs } from '@datadog/browser-logs/';

and you will end up adding thousands of line of code in your bundle.

Expected behavior
Bundle should only contain functions which is getting used.

Activity

  1. added
    bug
    on Jan 14, 2026
  2. BenoitZugmeyer commented on Feb 2, 2026

    @BenoitZugmeyer
    Member

    Thank you for your feedback. This is a known limitation and we are looking into changing this pattern in a future major version.

  3. added
    enhancement
    and removed
    bug
    on Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmajor version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions