DataDog / dd-sdk-flutter

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

FirstPartyHosts formatting #603

Closed curt-weber closed 1 month ago

curt-weber commented 1 month ago

Describe the bug

The DatadogConfiguration accepts first party hosts as a List<String>, but when the js script loads it complains about the format: Datadog Browser SDK: Allowed Tracing Urls parameters should be a string, RegExp, function, or an object. Ignoring parameter. It could be that some transformation needs to take place within the plugin to put it into a format the script expects.

Reproduction steps

DatadogConfiguration(
   firstPartyHosts: ['site.com'],
)..enableHttpTracking()

SDK logs

No response

Expected behavior

No response

Affected SDK versions

2.4.0 https://www.datadoghq-browser-agent.com/us1/v5/datadog-logs.js https://www.datadoghq-browser-agent.com/us1/v5/datadog-rum-slim.js

Latest working SDK version

No response

Did you confirm if the latest SDK version fixes the bug?

Yes

Flutter Version

3.16.9

Setup Type

No response

Device Information

No response

Other relevant information

No response

fuzzybinary commented 1 month ago

Hi @curt-weber ,

Weirdly, we do perform the transformation to the object type the JavaScript expects.

I also can't reproduce with 2.4.0 with our simple example.

A few questions that might help me track this down:

Is the first party host you're setting more complex than just "site.com"? Do you know if it's working on some browsers and not others (I only tested on Chrome)? Is there anything else weird about your setup?

curt-weber commented 1 month ago

No, for us it's just kw.com. Yes it also occurs in firefox.

curt-weber commented 1 month ago

Unfortunately the js is obfuscated/minified so it's harder to trace, but here it returns false:

function Nn(t) {
        var e = H(t);
        return "string" === e || "function" === e || t instanceof RegExp
    }

firstpartyhosts

curt-weber commented 1 month ago

Actually that screenshot is from the first time it goes through that function, it goes through again but the result is the same.

fuzzybinary commented 1 month ago

This is the code that's doing the validation. The first time it calls isMatchOption (the function that's obfuscated above) it should fail, but isTracingOption should pass in the proper match portion of the object.

What's e during the second call?

curt-weber commented 1 month ago

e is "object" both times - if it helps, here is a live example: kw.com/search

fuzzybinary commented 1 month ago

That does help a bit, thanks!

It's very, very strange though. We have specific code to convert the Dart RegExp to a JavaScript RegExp but in your case it looks like something might be interfering with it. Does this happen in debug builds? Is there any chance you can see what type t is during the call? It looks like a Dart RegExp to me, but I can't be sure.

fuzzybinary commented 1 month ago

I knew I saw this before -- are you sure you're using 2.4.0? The code to perform this conversion was released in 2.3.0 (see #554) and even from the obfuscated code it looks like the RegExp conversion isn't happening. Side by side of your release code vs. mine in our sample app:

image
curt-weber commented 1 month ago

It looks like we are on 2.2.0 - this is my fault. Apologies for the wasted cycles.

curt-weber commented 1 month ago

We will upgrade and confirm this works and close.

curt-weber commented 1 month ago

Confirmed as working - thanks for looking into this @fuzzybinary!