From fe2a49e69144741a8a60adc477cdf377a781bd24 Mon Sep 17 00:00:00 2001 From: Jonathan Moskovich <48201295+jonathanmos@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:57:58 +0200 Subject: [PATCH] Move logger to wrapper --- .../sessionreplay/DdSessionReplayImplementation.kt | 6 +----- .../ReactNativeSessionReplayExtensionSupport.kt | 4 ++-- .../reactnative/sessionreplay/SessionReplaySDKWrapper.kt | 9 +++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/DdSessionReplayImplementation.kt b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/DdSessionReplayImplementation.kt index 615a712b5..3eefe6ffb 100644 --- a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/DdSessionReplayImplementation.kt +++ b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/DdSessionReplayImplementation.kt @@ -6,8 +6,6 @@ package com.datadog.reactnative.sessionreplay -import com.datadog.android.Datadog -import com.datadog.android.api.feature.FeatureSdkCore import com.datadog.android.sessionreplay.SessionReplayConfiguration import com.datadog.android.sessionreplay.SessionReplayPrivacy import com.facebook.react.bridge.Promise @@ -29,11 +27,9 @@ class DdSessionReplayImplementation( * @param defaultPrivacyLevel The privacy level used for replay. */ fun enable(replaySampleRate: Double, defaultPrivacyLevel: String, promise: Promise) { - val sdkCore = Datadog.getInstance() as FeatureSdkCore - val logger = sdkCore.internalLogger val configuration = SessionReplayConfiguration.Builder(replaySampleRate.toFloat()) .setPrivacy(buildPrivacy(defaultPrivacyLevel)) - .addExtensionSupport(ReactNativeSessionReplayExtensionSupport(logger, reactContext)) + .addExtensionSupport(ReactNativeSessionReplayExtensionSupport(reactContext)) .build() sessionReplayProvider().enable(configuration) promise.resolve(null) diff --git a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.kt b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.kt index 482699eac..4f38a7bee 100644 --- a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.kt +++ b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/ReactNativeSessionReplayExtensionSupport.kt @@ -23,8 +23,8 @@ import com.facebook.react.views.textinput.ReactEditText import com.facebook.react.views.view.ReactViewGroup internal class ReactNativeSessionReplayExtensionSupport( - private val logger: InternalLogger, private val reactContext: ReactContext, + private val logger: InternalLogger? = SessionReplaySDKWrapper.getLogger() ) : ExtensionSupport { override fun getCustomViewMappers(): Map, WireframeMapper>> { @@ -51,7 +51,7 @@ internal class ReactNativeSessionReplayExtensionSupport( return try { reactContext.getNativeModule(UIManagerModule::class.java) } catch (e: IllegalStateException) { - logger.log( + logger?.log( level = InternalLogger.Level.WARN, targets = listOf(InternalLogger.Target.MAINTAINER, InternalLogger.Target.TELEMETRY), messageBuilder = { RESOLVE_UIMANAGERMODULE_ERROR }, diff --git a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/SessionReplaySDKWrapper.kt b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/SessionReplaySDKWrapper.kt index 7fa70e152..06842ddfc 100644 --- a/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/SessionReplaySDKWrapper.kt +++ b/packages/react-native-session-replay/android/src/main/kotlin/com/datadog/reactnative/sessionreplay/SessionReplaySDKWrapper.kt @@ -6,6 +6,9 @@ package com.datadog.reactnative.sessionreplay +import com.datadog.android.Datadog +import com.datadog.android.api.InternalLogger +import com.datadog.android.api.feature.FeatureSdkCore import com.datadog.android.sessionreplay.SessionReplay import com.datadog.android.sessionreplay.SessionReplayConfiguration @@ -21,4 +24,10 @@ internal class SessionReplaySDKWrapper : SessionReplayWrapper { sessionReplayConfiguration, ) } + + internal companion object { + internal fun getLogger(): InternalLogger? { + return (Datadog.getInstance() as? FeatureSdkCore)?.internalLogger + } + } }