DataDog / dd-sdk-flutter

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

fix: Do not use singletons for RUM / Logs plugins #626

Closed fuzzybinary closed 3 days ago

fuzzybinary commented 4 days ago

What and why?

Under certain circumstances, Flutter can create two FlutterEngines which each have their own method channels. If this happens, we could end up in a situation where RUM and Logs were not properly attached to a MethodChannel, resulting in error messages and lost calls.

refs: #596 #580 RUM-491 RUM-4438

How?

We're removing the DatadogRumPlugin and DatadogLogsPlugin singletons and replacing them with instances to avoid this. Both plugins will attach to existing Datadog Logs and RUM instances during initialization if they have already been inititalized.

However, this breaks our current mapper implementation. Since Datadog expects the mapper during initialization, and holds it during the life of the application, we have to move the mappers to a companion object of the *Plugin classes to avoid issues with multiple or disconnected MethodChannels.

This potentially also helps us with multiple isolate tracking, but is just the first step of that.

Review checklist