Warnings on import: "SDK is loaded more than once. This is unsupported and might have unexpected behavior"
SargisPlusPlus opened this issue · 5 comments
Steps to Reproduce
- Have a Chrome extension that injects content scripts into a webpage.
- Import
DatadogLogs
in both the webpage and the Chrome extension's content script. - Observe that the warning appears in the console.
On import, the Datadog SDK calls defineGlobal
on the window
object and produces the warning: "SDK is loaded more than once. This is unsupported and might have unexpected behavior."
Environment
- Datadog SDK version: ^5.23.3
- Node version: v20.8.1
- Browser: Chrome
Additional Context
This issue occurs because my Chrome extension and the webpage share the same window
object, resulting in two Datadog loggers being defined on the same window
.
This is expected, only one instance of the Logs SDK should be loaded at a time. Beside using a global variable (which doesn't cause any issue if you don't use it), the Logs SDK is also ding a few things globally:
-
a session is store in a cookie. If two SDK instances are configured differently (ex: with a different sample rate), it can lead to unexpected behavior
-
global errors and console.logs are collected by the SDK. If two SDK instances are configured to do so, we'd collect data twice.
That being said, this is not the first time we've had that request, and we probably should do something about it. In the meantime, you could ignore the warning.