Skip to content

Commit

Permalink
Android implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
louiszawadzki committed Dec 5, 2023
1 parent 876dac1 commit b1c4c9e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compileOnly "com.squareup.okhttp3:okhttp:3.12.13"

implementation "com.datadoghq:dd-sdk-android-rum:2.2.0"
implementation "com.datadoghq:dd-sdk-android-logs:2.2.0"
implementation "com.datadoghq:dd-sdk-android-trace:2.2.0"
implementation "com.datadoghq:dd-sdk-android-webview:2.2.0"
implementation "com.datadoghq:dd-sdk-android-rum:2.4.0-SNAPSHOT"
implementation "com.datadoghq:dd-sdk-android-logs:2.4.0-SNAPSHOT"
implementation "com.datadoghq:dd-sdk-android-trace:2.4.0-SNAPSHOT"
implementation "com.datadoghq:dd-sdk-android-webview:2.4.0-SNAPSHOT"
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.reactnative

import com.datadog.android.Datadog
import com.datadog.android.core.DatadogCoreProxy
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap

/**
* The entry point to use Datadog's Core Tests feature.
*/
class DdCoreTestsImplementation() {
fun clearData(promise: Promise) {
val core = Datadog.getInstance() as DatadogCoreProxy
core.clearData("logs")
core.clearData("rum")
core.clearData("tracing")
core.clearData("session-replay")

promise.resolve(null)
}

fun getAllEventsData(feature: String, promise: Promise) {
val core = Datadog.getInstance() as DatadogCoreProxy
val events = core.eventsWritten(feature)
promise.resolve(events.toString())
}

companion object {
internal const val NAME = "DdCoreTests"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DdSdkReactNativePackage : TurboReactPackage() {
DdRumImplementation.NAME -> DdRum(reactContext)
DdTraceImplementation.NAME -> DdTrace(reactContext)
DdLogsImplementation.NAME -> DdLogs(reactContext)
DdCoreTestsImplementation.NAME -> DdCoreTests(reactContext)
else -> null
}
}
Expand All @@ -33,7 +34,8 @@ class DdSdkReactNativePackage : TurboReactPackage() {
DdSdkImplementation.NAME,
DdRumImplementation.NAME,
DdTraceImplementation.NAME,
DdLogsImplementation.NAME
DdLogsImplementation.NAME,
DdCoreTestsImplementation.NAME
).associateWith {
ReactModuleInfo(
it,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.reactnative

import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap

/**
* The entry point to use Datadog's Core Tests feature.
*/
class DdCoreTests(
reactContext: ReactApplicationContext,
) : NativeDdCoreTestsSpec(reactContext) {

private val implementation = DdCoreTestsImplementation()

override fun getName(): String = DdCoreTestsImplementation.NAME

@ReactMethod
override fun clearData(promise: Promise) {
implementation.clearData(promise)
}

@ReactMethod
override fun getAllEventsData(feature: String, promise: Promise) {
implementation.getAllEventsData(feature, promise)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.reactnative

import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap

/**
* The entry point to use Datadog's Core Tests feature.
*/
class DdCoreTests(
reactContext: ReactApplicationContext
) : ReactContextBaseJavaModule(reactContext) {

private val implementation = DdCoreTestsImplementation()

override fun getName(): String = DdCoreTestsImplementation.NAME

@ReactMethod
fun clearData(promise: Promise) {
implementation.clearData(promise)
}

@ReactMethod
fun getAllEventsData(feature: String, promise: Promise) {
implementation.getAllEventsData(feature, promise)
}
}
11 changes: 8 additions & 3 deletions packages/core/src/DdCoreTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Copyright 2016-Present Datadog, Inc.
*/

import { Platform } from 'react-native';

import type { DdNativeCoreTestsType } from './nativeModulesTypes';
import { base64 } from './utils/base64';

Expand Down Expand Up @@ -222,9 +224,12 @@ class DdCoreTestsWrapper {
};
getAllEventsData = async (feature: Feature) => {
const events = await this.nativeDdCoreTests.getAllEventsData(feature);
return (JSON.parse(events) as string[]).map(event =>
JSON.parse(base64.decode(event))
);
if (Platform.OS === 'ios') {
return (JSON.parse(events) as string[]).map(event =>
JSON.parse(base64.decode(event))
);
}
return JSON.parse(events);
};
getTraces = async (): Promise<TracingResult> => {
const traces = await this.getAllEventsData('tracing');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-session-replay/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ dependencies {
api "com.facebook.react:react-android:$reactNativeVersion"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.datadoghq:dd-sdk-android-session-replay:2.2.0"
implementation "com.datadoghq:dd-sdk-android-session-replay:2.4.0-SNAPSHOT"

testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
Expand Down

0 comments on commit b1c4c9e

Please sign in to comment.