DataDog/dd-sdk-flutter

DatadogSdk fails to initialise on Web

Arthurius opened this issue · 10 comments

When implementing Datadog, web tracking does not work and throws:

[Datadog 🐶⚠️ ] DatadogSdk failed to initialize logging: TypeError: Cannot read properties of undefined (reading 'init')
[Datadog 🐶⚠️ ] Did you remember to add "datadog-logs" to your scripts?
[Datadog 🐶⚠️ ] DatadogSdk failed to initialize RUM: TypeError: Cannot read properties of undefined (reading 'init')
[Datadog 🐶⚠️ ] Did you remember to add "datadog-rum-slim" to your scripts?

I've followed all the steps needed (including adding the links to the scripts in the html file). When building for mobile it does work. But for our web-app it keeps throwing an error.

Steps to reproduce the issue:
create the template Flutter app, and setup the basic Datadog implementation for Flutter. Then run

Describe what you expected:
I expect to see incoming data, but whatever I try, the error remains.

Additional context
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.4, on macOS 14.0 23A344 darwin-arm64, locale en-NL)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.85.1)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Hi @Arthurius .

Did you add the following to your index.html (as documented here:

<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/us1/v5/datadog-logs.js"></script>
<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/us1/v5/datadog-rum-slim.js"></script>

Hi @fuzzybinary , yes I did

@Arthurius Are you seeing any network errors in the console when attempting to get those files from the CDN?

Also what version of Flutter DatadogSdk are you using? v2.x should be paired with the v5 browser SDK, and 1.x should be paired with v4.

@fuzzybinary ,

I'm using

datadog_flutter_plugin: ^2.1.0
datadog_tracking_http_client: ^2.0.0

with the v5 scripts

No networkerrors getting the scripts from CDN:
Screenshot 2023-12-19 at 16 16 37

I've uploaded my basic test to a repo. I've replaced the clientToken and applicationId with placeholders for safety:
https://github.com/Arthurius/ddog_flutter_test

@Arthurius I can't reproduce, even with your example code, in either Firefox or Chrome.

Can you see what the value of DD_LOGS is in the Javascript console? Here's what I get in Firefox:
image

For me in firefox it throws this:

Screenshot 2023-12-19 at 17 04 41

It does also give these warnings:
Screenshot 2023-12-19 at 17 07 28

@fuzzybinary
I think it's a problem on Mac.
I've just tested the same site on a Chromebook and a windows laptop. There it works fine.
On mac I tested it with Firefox, Chrome, Safari and Brave, and they all have the same problem..

@Arthurius Do you have a proxy on your Mac that's in the way of the CDN? Or an ad-blocker that flags Datadog?

I'm pretty sure we report the MIME type properly from the CDN, but if it's being overwritten for some reason, the bad MIME type will cause the javascript to fail to load.

@fuzzybinary
My mac indeed had a proxy. After disabling that it started working properly. Thank you for helping me sort this out!

Glad we could figure it out! Let us know if you have any other issues!