-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make all dd attribute sources reactive instead of individual coroutines
This works around the issue over at DataDog/dd-sdk-android#2132 which does not let one call setUserInfo without having to also clear all previously set attributes. With this change, we instead keep a flow for all of our source of truth, and combine them together so if any single one of them change, we re-apply all of them together with one `setUserInfo` call. We do the same for RUM too, all inside DatadogAttributesManager
- Loading branch information
1 parent
12a4231
commit f678ffb
Showing
12 changed files
with
143 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...re/src/main/kotlin/com/hedvig/android/datadog/core/attributestracking/DeviceIdProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.hedvig.android.datadog.core.attributestracking | ||
|
||
import com.hedvig.android.core.datastore.DeviceIdDataStore | ||
import com.hedvig.android.logger.LogPriority | ||
import com.hedvig.android.logger.logcat | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
internal class DeviceIdProvider( | ||
private val deviceIdDataStore: DeviceIdDataStore, | ||
) : DatadogAttributeProvider { | ||
override fun provide(): Flow<Pair<String, Any?>> { | ||
return deviceIdDataStore | ||
.observeDeviceId() | ||
.onEach { deviceId -> | ||
logcat(LogPriority.VERBOSE) { "Datadog stored device id attribute: $deviceId" } | ||
} | ||
.map { deviceId -> | ||
DEVICE_ID_KEY to deviceId | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DEVICE_ID_KEY = "device_id" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...in/kotlin/com/hedvig/android/datadog/core/attributestracking/MemberMemberIdTrackingKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.hedvig.android.datadog.core.attributestracking | ||
|
||
import com.hedvig.android.auth.MemberIdService | ||
import com.hedvig.android.logger.LogPriority | ||
import com.hedvig.android.logger.logcat | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
internal class DatadogMemberIdProviderImpl( | ||
private val memberIdService: MemberIdService, | ||
) : DatadogMemberIdProvider { | ||
override fun provide(): Flow<Pair<String, String?>> { | ||
return memberIdService | ||
.getMemberId() | ||
.map { MEMBER_ID_TRACKING_KEY to it } | ||
.onEach { (key, memberId) -> | ||
logcat(LogPriority.INFO) { | ||
if (memberId == null) { | ||
"Removing from global RUM attribute:$MEMBER_ID_TRACKING_KEY" | ||
} else { | ||
"Appending to global RUM attribute:$MEMBER_ID_TRACKING_KEY = $memberId" | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
/** | ||
* Key to be passed to [com.hedvig.android.datadog.core.attributestracking.DatadogAttributesManager] to track the | ||
* member ID after we've logged into the app | ||
*/ | ||
private const val MEMBER_ID_TRACKING_KEY = "member_id" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...g-core/src/main/kotlin/com/hedvig/android/datadog/core/memberid/DatadogMemberIdUpdater.kt
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
...adog-core/src/main/kotlin/com/hedvig/android/datadog/core/memberid/MemberIdTrackingKey.kt
This file was deleted.
Oops, something went wrong.
27 changes: 12 additions & 15 deletions
27
...cking/src/main/kotlin/com/hedvig/android/datadog/demo/tracking/DatadogDemoModeTracking.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
package com.hedvig.android.datadog.demo.tracking | ||
|
||
import com.hedvig.android.core.common.ApplicationScope | ||
import com.hedvig.android.core.demomode.DemoManager | ||
import com.hedvig.android.datadog.core.attributestracking.DatadogAttributesManager | ||
import com.hedvig.android.initializable.Initializable | ||
import com.hedvig.android.datadog.core.attributestracking.DatadogAttributeProvider | ||
import com.hedvig.android.logger.LogPriority | ||
import com.hedvig.android.logger.logcat | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
class DatadogDemoModeTracking( | ||
private val applicationScope: ApplicationScope, | ||
private val demoManager: DemoManager, | ||
private val datadogAttributesManager: DatadogAttributesManager, | ||
) : Initializable { | ||
override fun initialize() { | ||
applicationScope.launch { | ||
demoManager.isDemoMode().collect { isDemoMode -> | ||
logcat(LogPriority.INFO) { "Demo mode changed to:$isDemoMode" } | ||
datadogAttributesManager.storeAttribute(IS_DEMO_MODE_TRACKING_KEY, isDemoMode) | ||
} | ||
) : DatadogAttributeProvider { | ||
override fun provide(): Flow<Pair<String, Any?>> { | ||
return demoManager.isDemoMode().map { isDemoMode -> | ||
logcat(LogPriority.INFO) { "Demo mode changed to:$isDemoMode" } | ||
IS_DEMO_MODE_TRACKING_KEY to isDemoMode | ||
} | ||
} | ||
} | ||
|
||
private const val IS_DEMO_MODE_TRACKING_KEY = "is_demo_mode" | ||
companion object { | ||
private const val IS_DEMO_MODE_TRACKING_KEY = "is_demo_mode" | ||
} | ||
} |
8 changes: 3 additions & 5 deletions
8
.../src/main/kotlin/com/hedvig/android/datadog/demo/tracking/di/DatadogDemoTrackingModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
package com.hedvig.android.datadog.demo.tracking.di | ||
|
||
import com.hedvig.android.core.common.ApplicationScope | ||
import com.hedvig.android.core.demomode.DemoManager | ||
import com.hedvig.android.datadog.core.attributestracking.DatadogAttributesManager | ||
import com.hedvig.android.datadog.core.attributestracking.DatadogAttributeProvider | ||
import com.hedvig.android.datadog.demo.tracking.DatadogDemoModeTracking | ||
import com.hedvig.android.initializable.Initializable | ||
import org.koin.dsl.bind | ||
import org.koin.dsl.module | ||
|
||
val datadogDemoTrackingModule = module { | ||
single<DatadogDemoModeTracking> { | ||
DatadogDemoModeTracking(get<ApplicationScope>(), get<DemoManager>(), get<DatadogAttributesManager>()) | ||
} bind Initializable::class | ||
DatadogDemoModeTracking(get<DemoManager>()) | ||
} bind DatadogAttributeProvider::class | ||
} |