Skip to content

Commit

Permalink
Move logger to wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmos committed Dec 19, 2023
1 parent e4e04b4 commit fe2a49e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionReplayPrivacy, Map<Class<*>, WireframeMapper<View, *>>> {
Expand All @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -21,4 +24,10 @@ internal class SessionReplaySDKWrapper : SessionReplayWrapper {
sessionReplayConfiguration,
)
}

internal companion object {
internal fun getLogger(): InternalLogger? {
return (Datadog.getInstance() as? FeatureSdkCore)?.internalLogger
}
}
}

0 comments on commit fe2a49e

Please sign in to comment.