DataDog / dd-sdk-flutter

Flutter bindings and tools for utilizing Datadog Mobile SDKs
Apache License 2.0
43 stars 42 forks source link

DatadogSdk fails to initialise on Web #535

Closed Arthurius closed 9 months ago

Arthurius commented 9 months ago

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!

fuzzybinary commented 9 months ago

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>
Arthurius commented 9 months ago

Hi @fuzzybinary , yes I did

fuzzybinary commented 9 months ago

@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.

Arthurius commented 9 months ago

@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

fuzzybinary commented 9 months ago

@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
Arthurius commented 9 months ago

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
Arthurius commented 9 months ago

@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..

fuzzybinary commented 9 months ago

@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.

Arthurius commented 9 months ago

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

fuzzybinary commented 9 months ago

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