@datadog/mobile-react-native 1.0.0-rc9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +2 -1
- package/android/build.gradle +73 -3
- package/android/gradle.properties +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
- package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
- package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
- package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
- package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
- package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
- package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
- package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
- package/datadog-sourcemaps.gradle +137 -0
- package/ios/Sources/AnyEncodable.swift +138 -0
- package/ios/Sources/Attributes.swift +101 -0
- package/ios/Sources/DdLogs.swift +35 -11
- package/ios/Sources/DdRum.m +3 -1
- package/ios/Sources/DdRum.swift +184 -22
- package/ios/Sources/DdSdk.swift +190 -10
- package/ios/Sources/DdSdkConfiguration.swift +51 -0
- package/ios/Sources/DdTrace.swift +41 -6
- package/ios/Sources/GlobalState.swift +28 -0
- package/ios/Sources/QueueHolder.swift +10 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
- package/lib/commonjs/DdSdkReactNative.js +14 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/foundation.js +36 -2
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +36 -0
- package/lib/commonjs/nativeModulesTypes.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/commonjs/types.js +26 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +14 -0
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/foundation.js +36 -2
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +26 -0
- package/lib/module/nativeModulesTypes.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
- package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
- package/lib/module/types.js +23 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +2 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
- package/lib/typescript/foundation.d.ts +3 -2
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts +168 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
- package/lib/typescript/types.d.ts +42 -7
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -4
- package/src/DdSdkReactNative.tsx +20 -0
- package/src/DdSdkReactNativeConfiguration.tsx +20 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +76 -0
- package/src/__tests__/foundation.test.ts +79 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +8 -8
- package/src/foundation.tsx +40 -11
- package/src/index.tsx +3 -0
- package/src/nativeModulesTypes.ts +258 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
- package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +22 -0
- package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +8 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
- package/src/types.tsx +62 -7
- package/src/version.ts +1 -1
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
- package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit
|
|
8
|
+
|
|
9
|
+
import java.lang.reflect.Field
|
|
10
|
+
import java.lang.reflect.InvocationTargetException
|
|
11
|
+
import java.lang.reflect.Method
|
|
12
|
+
import java.lang.reflect.Modifier
|
|
13
|
+
import java.util.LinkedList
|
|
14
|
+
import kotlin.reflect.jvm.isAccessible
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instance of the given class name.
|
|
18
|
+
* @param className the full name of the class to instantiate
|
|
19
|
+
* @param params the parameters to provide the constructor
|
|
20
|
+
* @return the created instance
|
|
21
|
+
*/
|
|
22
|
+
@Suppress("SpreadOperator")
|
|
23
|
+
fun createInstance(
|
|
24
|
+
className: String,
|
|
25
|
+
vararg params: Any?
|
|
26
|
+
): Any {
|
|
27
|
+
return Class.forName(className)
|
|
28
|
+
.kotlin
|
|
29
|
+
.constructors.first()
|
|
30
|
+
.apply { isAccessible = true }
|
|
31
|
+
.call(*params)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets a static value on the target class.
|
|
36
|
+
* @param fieldName the name of the field
|
|
37
|
+
* @param fieldValue the value to set
|
|
38
|
+
*/
|
|
39
|
+
@Suppress("SwallowedException")
|
|
40
|
+
inline fun <reified T, R> Class<T>.setStaticValue(
|
|
41
|
+
fieldName: String,
|
|
42
|
+
fieldValue: R
|
|
43
|
+
) {
|
|
44
|
+
val field = getDeclaredField(fieldName)
|
|
45
|
+
|
|
46
|
+
// make it accessible
|
|
47
|
+
field.isAccessible = true
|
|
48
|
+
|
|
49
|
+
// Make it non final
|
|
50
|
+
try {
|
|
51
|
+
val modifiersField = Field::class.java.getDeclaredField("modifiers")
|
|
52
|
+
modifiersField.isAccessible = true
|
|
53
|
+
modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv())
|
|
54
|
+
} catch (e: NoSuchFieldException) {
|
|
55
|
+
// do nothing
|
|
56
|
+
@Suppress("PrintStackTrace")
|
|
57
|
+
e.printStackTrace()
|
|
58
|
+
}
|
|
59
|
+
field.set(null, fieldValue)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gets the static value from the target class.
|
|
64
|
+
* @param className the full name of the class
|
|
65
|
+
* @param fieldName the name of the field
|
|
66
|
+
*/
|
|
67
|
+
inline fun <reified R> getStaticValue(
|
|
68
|
+
className: String,
|
|
69
|
+
fieldName: String
|
|
70
|
+
): R {
|
|
71
|
+
val clazz = Class.forName(className)
|
|
72
|
+
val field = clazz.getDeclaredField(fieldName)
|
|
73
|
+
// make it accessible
|
|
74
|
+
field.isAccessible = true
|
|
75
|
+
|
|
76
|
+
return field.get(null) as R
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Gets the static value from the target class.
|
|
81
|
+
* @param fieldName the name of the field
|
|
82
|
+
*/
|
|
83
|
+
inline fun <reified T, reified R> Class<T>.getStaticValue(fieldName: String): R {
|
|
84
|
+
|
|
85
|
+
val field = getDeclaredField(fieldName)
|
|
86
|
+
|
|
87
|
+
// make it accessible
|
|
88
|
+
field.isAccessible = true
|
|
89
|
+
|
|
90
|
+
return field.get(null) as R
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sets the field value on the target instance.
|
|
95
|
+
* @param fieldName the name of the field
|
|
96
|
+
* @param fieldValue the value of the field
|
|
97
|
+
*/
|
|
98
|
+
@Suppress("SwallowedException")
|
|
99
|
+
inline fun <reified T> Any.setFieldValue(
|
|
100
|
+
fieldName: String,
|
|
101
|
+
fieldValue: T
|
|
102
|
+
): Boolean {
|
|
103
|
+
var field: Field? = null
|
|
104
|
+
val classesToSearch = LinkedList<Class<*>>()
|
|
105
|
+
classesToSearch.add(this.javaClass)
|
|
106
|
+
val classesSearched = mutableSetOf<Class<*>>()
|
|
107
|
+
|
|
108
|
+
while (field == null && classesToSearch.isNotEmpty()) {
|
|
109
|
+
val toSearchIn = classesToSearch.remove()
|
|
110
|
+
try {
|
|
111
|
+
field = toSearchIn.getDeclaredField(fieldName)
|
|
112
|
+
} catch (e: NoSuchFieldException) {
|
|
113
|
+
// do nothing
|
|
114
|
+
}
|
|
115
|
+
classesSearched.add(toSearchIn)
|
|
116
|
+
toSearchIn.superclass?.let {
|
|
117
|
+
if (!classesSearched.contains(it)) {
|
|
118
|
+
classesToSearch.add(it)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// make it accessible
|
|
124
|
+
if (field != null) {
|
|
125
|
+
field.isAccessible = true
|
|
126
|
+
|
|
127
|
+
// Make it non final
|
|
128
|
+
val modifiersField = Field::class.java.getDeclaredField("modifiers")
|
|
129
|
+
modifiersField.isAccessible = true
|
|
130
|
+
modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv())
|
|
131
|
+
|
|
132
|
+
field.set(this, fieldValue)
|
|
133
|
+
return true
|
|
134
|
+
} else {
|
|
135
|
+
return false
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the field value from the target instance.
|
|
141
|
+
* @param fieldName the name of the field
|
|
142
|
+
*/
|
|
143
|
+
inline fun <reified T, R : Any> R.getFieldValue(
|
|
144
|
+
fieldName: String,
|
|
145
|
+
enclosingClass: Class<R> = this.javaClass
|
|
146
|
+
): T {
|
|
147
|
+
val field = enclosingClass.getDeclaredField(fieldName)
|
|
148
|
+
field.isAccessible = true
|
|
149
|
+
return field.get(this) as T
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Invokes a method on the target instance.
|
|
154
|
+
* @param methodName the name of the method
|
|
155
|
+
* @param params the parameters to provide the method
|
|
156
|
+
* @return the result from the invoked method
|
|
157
|
+
*/
|
|
158
|
+
@Suppress("SpreadOperator", "UNCHECKED_CAST", "TooGenericExceptionCaught")
|
|
159
|
+
fun <T : Any> T.invokeMethod(
|
|
160
|
+
methodName: String,
|
|
161
|
+
vararg params: Any?
|
|
162
|
+
): Any? {
|
|
163
|
+
val declarationParams = Array<Class<*>?>(params.size) {
|
|
164
|
+
params[it]?.javaClass
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
val method = getDeclaredMethodRecursively(methodName, true, declarationParams)
|
|
168
|
+
val wasAccessible = method.isAccessible
|
|
169
|
+
|
|
170
|
+
val output: Any?
|
|
171
|
+
method.isAccessible = true
|
|
172
|
+
try {
|
|
173
|
+
output = if (params.isEmpty()) {
|
|
174
|
+
method.invoke(this)
|
|
175
|
+
} else {
|
|
176
|
+
method.invoke(this, *params)
|
|
177
|
+
}
|
|
178
|
+
} catch (e: InvocationTargetException) {
|
|
179
|
+
throw e.cause ?: e
|
|
180
|
+
} finally {
|
|
181
|
+
method.isAccessible = wasAccessible
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return output
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Invokes a method on the target instance, where one or more of the parameters
|
|
189
|
+
* are generics.
|
|
190
|
+
* @param methodName the name of the method
|
|
191
|
+
* @param params the parameters to provide the method
|
|
192
|
+
* @return the result from the invoked method
|
|
193
|
+
*/
|
|
194
|
+
@Suppress("SpreadOperator", "UNCHECKED_CAST")
|
|
195
|
+
fun <T : Any> T.invokeGenericMethod(
|
|
196
|
+
methodName: String,
|
|
197
|
+
vararg params: Any
|
|
198
|
+
): Any? {
|
|
199
|
+
val declarationParams = Array<Class<*>?>(params.size) {
|
|
200
|
+
params[it].javaClass
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
val method = getDeclaredMethodRecursively(methodName, false, declarationParams)
|
|
204
|
+
val wasAccessible = method.isAccessible
|
|
205
|
+
|
|
206
|
+
val output: Any?
|
|
207
|
+
method.isAccessible = true
|
|
208
|
+
try {
|
|
209
|
+
output = if (params.isEmpty()) {
|
|
210
|
+
method.invoke(this)
|
|
211
|
+
} else {
|
|
212
|
+
method.invoke(this, *params)
|
|
213
|
+
}
|
|
214
|
+
} catch (e: InvocationTargetException) {
|
|
215
|
+
throw e.cause ?: e
|
|
216
|
+
} finally {
|
|
217
|
+
method.isAccessible = wasAccessible
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return output
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@Suppress("TooGenericExceptionCaught", "SwallowedException", "SpreadOperator")
|
|
224
|
+
private fun <T : Any> T.getDeclaredMethodRecursively(
|
|
225
|
+
methodName: String,
|
|
226
|
+
matchingParams: Boolean,
|
|
227
|
+
declarationParams: Array<Class<*>?>
|
|
228
|
+
): Method {
|
|
229
|
+
val classesToSearch = mutableListOf<Class<*>>(this.javaClass)
|
|
230
|
+
val classesSearched = mutableListOf<Class<*>>()
|
|
231
|
+
var method: Method?
|
|
232
|
+
do {
|
|
233
|
+
val lookingInClass = classesToSearch.removeAt(0)
|
|
234
|
+
classesSearched.add(lookingInClass)
|
|
235
|
+
method = try {
|
|
236
|
+
if (matchingParams) {
|
|
237
|
+
lookingInClass.getDeclaredMethod(methodName, *declarationParams)
|
|
238
|
+
} else {
|
|
239
|
+
lookingInClass.declaredMethods.firstOrNull {
|
|
240
|
+
it.name == methodName &&
|
|
241
|
+
it.parameterTypes.size == declarationParams.size
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} catch (e: Throwable) {
|
|
245
|
+
null
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
val superclass = lookingInClass.superclass
|
|
249
|
+
if (superclass != null &&
|
|
250
|
+
!classesToSearch.contains(superclass) &&
|
|
251
|
+
!classesSearched.contains(superclass)
|
|
252
|
+
) {
|
|
253
|
+
classesToSearch.add(superclass)
|
|
254
|
+
}
|
|
255
|
+
lookingInClass.interfaces.forEach {
|
|
256
|
+
if (!classesToSearch.contains(it) && !classesSearched.contains(it)) {
|
|
257
|
+
classesToSearch.add(it)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} while (method == null && classesToSearch.isNotEmpty())
|
|
261
|
+
|
|
262
|
+
checkNotNull(method) {
|
|
263
|
+
"Unable to access method $methodName on ${javaClass.canonicalName}"
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return method
|
|
267
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit.forge
|
|
8
|
+
|
|
9
|
+
import fr.xgouchet.elmyr.Forge
|
|
10
|
+
import fr.xgouchet.elmyr.ForgeConfigurator
|
|
11
|
+
import fr.xgouchet.elmyr.jvm.useJvmFactories
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base implementation of a [ForgeConfigurator], adding the JVM Forgery Factories (Date, …) and
|
|
15
|
+
* a [ThrowableForgeryFactory].
|
|
16
|
+
*/
|
|
17
|
+
open class BaseConfigurator :
|
|
18
|
+
ForgeConfigurator {
|
|
19
|
+
/** @inheritDoc */
|
|
20
|
+
override fun configure(forge: Forge) {
|
|
21
|
+
forge.addFactory(ThrowableForgeryFactory())
|
|
22
|
+
forge.addFactory(DdSdkConfigurationForgeryFactory())
|
|
23
|
+
forge.addFactory(PackageInfoForgeryFactory())
|
|
24
|
+
forge.useJvmFactories()
|
|
25
|
+
}
|
|
26
|
+
}
|
package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit.forge
|
|
8
|
+
|
|
9
|
+
import com.datadog.reactnative.DdSdkConfiguration
|
|
10
|
+
import fr.xgouchet.elmyr.Forge
|
|
11
|
+
import fr.xgouchet.elmyr.ForgeryFactory
|
|
12
|
+
import java.util.UUID
|
|
13
|
+
|
|
14
|
+
class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
|
|
15
|
+
override fun getForgery(forge: Forge): DdSdkConfiguration {
|
|
16
|
+
return DdSdkConfiguration(
|
|
17
|
+
clientToken = forge.aStringMatching("pub[a-f0-9]{32}"),
|
|
18
|
+
env = forge.anAlphabeticalString(),
|
|
19
|
+
applicationId = forge.aNullable { getForgery<UUID>().toString() },
|
|
20
|
+
nativeCrashReportEnabled = forge.aNullable { aBool() },
|
|
21
|
+
sampleRate = forge.aNullable { aDouble(0.0, 100.0) },
|
|
22
|
+
site = forge.aNullable { anElementFrom("US", "EU", "GOV") },
|
|
23
|
+
additionalConfig = forge.aMap {
|
|
24
|
+
forge.anAsciiString() to forge.anElementFrom(
|
|
25
|
+
forge.aMap { forge.anAsciiString() to forge.aString() },
|
|
26
|
+
forge.aString(),
|
|
27
|
+
null
|
|
28
|
+
)
|
|
29
|
+
},
|
|
30
|
+
trackingConsent = forge.aNullable { anElementFrom("pending", "granted", "not_granted") }
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit.forge
|
|
8
|
+
|
|
9
|
+
import android.content.pm.PackageInfo
|
|
10
|
+
import fr.xgouchet.elmyr.Forge
|
|
11
|
+
import fr.xgouchet.elmyr.ForgeryFactory
|
|
12
|
+
import java.util.UUID
|
|
13
|
+
|
|
14
|
+
class PackageInfoForgeryFactory : ForgeryFactory<PackageInfo> {
|
|
15
|
+
override fun getForgery(forge: Forge): PackageInfo {
|
|
16
|
+
val packageInfo = PackageInfo();
|
|
17
|
+
packageInfo.versionName = forge.aStringMatching("[0-9]\\.[0-9]\\.[0-9]")
|
|
18
|
+
return packageInfo
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit.forge
|
|
8
|
+
|
|
9
|
+
import fr.xgouchet.elmyr.Forge
|
|
10
|
+
import fr.xgouchet.elmyr.ForgeryException
|
|
11
|
+
import java.io.FileNotFoundException
|
|
12
|
+
import java.io.IOException
|
|
13
|
+
import java.io.InvalidObjectException
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @return a random [Throwable] instance with a forged message.
|
|
17
|
+
*/
|
|
18
|
+
fun Forge.aThrowable(): Throwable {
|
|
19
|
+
val errorMessage = anAlphabeticalString()
|
|
20
|
+
return anElementFrom(
|
|
21
|
+
IOException(errorMessage),
|
|
22
|
+
IllegalStateException(errorMessage),
|
|
23
|
+
UnknownError(errorMessage),
|
|
24
|
+
ArrayIndexOutOfBoundsException(errorMessage),
|
|
25
|
+
NullPointerException(errorMessage),
|
|
26
|
+
ForgeryException(errorMessage),
|
|
27
|
+
InvalidObjectException(errorMessage),
|
|
28
|
+
UnsupportedOperationException(errorMessage),
|
|
29
|
+
FileNotFoundException(errorMessage)
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
package com.datadog.tools.unit.forge
|
|
8
|
+
|
|
9
|
+
import fr.xgouchet.elmyr.Forge
|
|
10
|
+
import fr.xgouchet.elmyr.ForgeryFactory
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A [ForgeryFactory] generating a random [Throwable] instance with a forged message.
|
|
14
|
+
*/
|
|
15
|
+
class ThrowableForgeryFactory :
|
|
16
|
+
ForgeryFactory<Throwable> {
|
|
17
|
+
/** @inheritDoc */
|
|
18
|
+
override fun getForgery(forge: Forge): Throwable {
|
|
19
|
+
return forge.aThrowable()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mock-maker-inline
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import org.apache.tools.ant.taskdefs.condition.Os
|
|
8
|
+
|
|
9
|
+
def reactConfig = project.hasProperty("react") ? project.react : [:]
|
|
10
|
+
def reactRoot = file(reactConfig.root ?: "../../")
|
|
11
|
+
|
|
12
|
+
afterEvaluate {
|
|
13
|
+
|
|
14
|
+
def androidExtension = extensions.findByName("android")
|
|
15
|
+
|
|
16
|
+
if (androidExtension == null || android.applicationVariants == null) {
|
|
17
|
+
throw new GradleException("Android extension is missing or running not in the application" +
|
|
18
|
+
" module. Make sure you've applied datadog-sourcemaps.gradle in the" +
|
|
19
|
+
" application module (usually it is located in the android/app/build.gradle file).")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
androidExtension.applicationVariants.all { variant ->
|
|
23
|
+
|
|
24
|
+
def releaseVersion = variant.versionName
|
|
25
|
+
def buildVersion = variant.versionCode
|
|
26
|
+
|
|
27
|
+
if (releaseVersion == null) {
|
|
28
|
+
throw new GradleException("Cannot determine application version. Make sure to" +
|
|
29
|
+
" define versionName property in the application/variant config.")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// locations and names are defined in "../../node_modules/react-native/react.gradle"
|
|
33
|
+
def targetName = variant.name.capitalize()
|
|
34
|
+
def targetPath = variant.dirName
|
|
35
|
+
|
|
36
|
+
def bundleTask = tasks.findByName("bundle${targetName}JsAndAssets")
|
|
37
|
+
|
|
38
|
+
if (bundleTask == null) {
|
|
39
|
+
logger.info("Cannot find JS bundle task for variant=${targetName}.")
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
if (!bundleTask.enabled) {
|
|
43
|
+
logger.info("JS bundle task for variant=${targetName} is not enabled.")
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
def serviceName = getServiceName(variant)
|
|
48
|
+
logger.info("Service name used for the upload of variant=${targetName} is ${serviceName}.")
|
|
49
|
+
|
|
50
|
+
def bundleAssetName = reactConfig.bundleAssetName ?: "index.android.bundle"
|
|
51
|
+
|
|
52
|
+
def jsBundleDir = file("$buildDir/generated/assets/react/${targetPath}")
|
|
53
|
+
def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
|
|
54
|
+
|
|
55
|
+
def jsSourceMapsDir = file("$buildDir/generated/sourcemaps/react/${targetPath}")
|
|
56
|
+
def jsOutputSourceMapFile = file("$jsSourceMapsDir/${bundleAssetName}.map")
|
|
57
|
+
|
|
58
|
+
def uploadTask = tasks.create("upload${targetName}Sourcemaps") {
|
|
59
|
+
group = "datadog"
|
|
60
|
+
description = "Uploads sourcemaps to Datadog."
|
|
61
|
+
|
|
62
|
+
def execCommand = [
|
|
63
|
+
"yarn",
|
|
64
|
+
"datadog-ci",
|
|
65
|
+
"react-native",
|
|
66
|
+
"upload",
|
|
67
|
+
"--platform",
|
|
68
|
+
"android",
|
|
69
|
+
"--service",
|
|
70
|
+
serviceName,
|
|
71
|
+
"--bundle",
|
|
72
|
+
jsBundleFile.absolutePath,
|
|
73
|
+
"--sourcemap",
|
|
74
|
+
jsOutputSourceMapFile.absolutePath,
|
|
75
|
+
"--release-version",
|
|
76
|
+
releaseVersion,
|
|
77
|
+
"--build-version",
|
|
78
|
+
buildVersion
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
doFirst {
|
|
82
|
+
if (!jsBundleFile.exists()) {
|
|
83
|
+
throw new GradleException("JS bundle file doesn't exist, aborting upload.")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!jsOutputSourceMapFile.exists()) {
|
|
87
|
+
throw new GradleException("JS sourcemap file doesn't exist, aborting upload.")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
runShellCommand(execCommand, reactRoot)
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
uploadTask.dependsOn bundleTask
|
|
96
|
+
bundleTask.finalizedBy uploadTask
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private def runShellCommand(
|
|
102
|
+
List<String> command,
|
|
103
|
+
File workingDirectory
|
|
104
|
+
) {
|
|
105
|
+
def outputStream = new ByteArrayOutputStream()
|
|
106
|
+
def errorStream = new ByteArrayOutputStream()
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
def result = exec {
|
|
110
|
+
workingDir = workingDirectory
|
|
111
|
+
standardOutput = outputStream
|
|
112
|
+
errorOutput = errorStream
|
|
113
|
+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
114
|
+
commandLine("cmd", "/c", *command)
|
|
115
|
+
} else {
|
|
116
|
+
commandLine(*command)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (result.exitValue != 0) {
|
|
121
|
+
logger.error(errorStream.toString("UTF-8"))
|
|
122
|
+
result.rethrowFailure()
|
|
123
|
+
} else {
|
|
124
|
+
logger.lifecycle(outputStream.toString("UTF-8"))
|
|
125
|
+
}
|
|
126
|
+
} catch (Exception e) {
|
|
127
|
+
def errorStreamContent = errorStream.toString("UTF-8")
|
|
128
|
+
def standardStreamContent = outputStream.toString("UTF-8")
|
|
129
|
+
logger.error("Exception raised during command execution," +
|
|
130
|
+
" stderr=${errorStreamContent}, stdout=${standardStreamContent}")
|
|
131
|
+
throw e
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static def getServiceName(variant) {
|
|
136
|
+
return variant.applicationId
|
|
137
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2019-2020 Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
|
|
9
|
+
internal func castAttributesToSwift(_ attributes: NSDictionary) -> [String: Encodable] {
|
|
10
|
+
return castAttributesToSwift(attributes as? [String: Any] ?? [:])
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
internal func castAttributesToSwift(_ attributes: [String: Any]) -> [String: Encodable] {
|
|
14
|
+
var casted: [String: Encodable] = [:]
|
|
15
|
+
|
|
16
|
+
attributes.forEach { key, value in
|
|
17
|
+
if let castedValue = castByPreservingTypeInformation(attributeValue: value) {
|
|
18
|
+
// If possible, cast attribute by preserving its type information
|
|
19
|
+
casted[key] = castedValue
|
|
20
|
+
} else {
|
|
21
|
+
// Otherwise, cast by preserving its encoded value (and loosing type information)
|
|
22
|
+
casted[key] = castByPreservingEncodedValue(attributeValue: value)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return casted
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Casts `Any` value to `Encodable` by preserving its type information.
|
|
30
|
+
private func castByPreservingTypeInformation(attributeValue: Any) -> Encodable? {
|
|
31
|
+
switch attributeValue {
|
|
32
|
+
case let string as String: // unpacking `NSTaggedPointerString`
|
|
33
|
+
return string // cast to String
|
|
34
|
+
case let number as NSNumber: // unpacking `__NSCFNumber`
|
|
35
|
+
switch CFNumberGetType(number) {
|
|
36
|
+
case .charType:
|
|
37
|
+
return number.boolValue // cast to Bool
|
|
38
|
+
case .sInt8Type:
|
|
39
|
+
return number.int8Value // cast to Int8
|
|
40
|
+
case .sInt16Type:
|
|
41
|
+
return number.int16Value // cast to Int16
|
|
42
|
+
case .sInt32Type:
|
|
43
|
+
return number.int32Value // cast to Int32
|
|
44
|
+
case .sInt64Type:
|
|
45
|
+
return number.int64Value // cast to Int64
|
|
46
|
+
case .shortType:
|
|
47
|
+
return number.uint16Value // cast to UInt 16
|
|
48
|
+
case .longType:
|
|
49
|
+
return number.uint32Value // cast to UInt32
|
|
50
|
+
case .longLongType:
|
|
51
|
+
return number.uint64Value // cast to UInt64
|
|
52
|
+
case .intType, .nsIntegerType, .cfIndexType:
|
|
53
|
+
return number.intValue // cast to Int
|
|
54
|
+
case .floatType, .float32Type:
|
|
55
|
+
return number.floatValue // cast to Float
|
|
56
|
+
case .doubleType, .float64Type, .cgFloatType:
|
|
57
|
+
return number.doubleValue // cast to Double
|
|
58
|
+
@unknown default:
|
|
59
|
+
return nil
|
|
60
|
+
}
|
|
61
|
+
default:
|
|
62
|
+
return nil
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Casts `Any` value to `Encodable` ereasing its type information, but preserving data representation
|
|
67
|
+
/// when value gets encoded.
|
|
68
|
+
private func castByPreservingEncodedValue(attributeValue: Any) -> Encodable {
|
|
69
|
+
return AnyEncodable(attributeValue)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// Type erasing `Encodable` wrapper to bridge Objective-C's `Any` to Swift `Encodable`.
|
|
73
|
+
///
|
|
74
|
+
/// Inspired by `AnyCodable` by Flight-School (MIT):
|
|
75
|
+
/// https://github.com/Flight-School/AnyCodable/blob/master/Sources/AnyCodable/AnyEncodable.swift
|
|
76
|
+
internal class AnyEncodable: Encodable {
|
|
77
|
+
internal let value: Any
|
|
78
|
+
|
|
79
|
+
init(_ value: Any) {
|
|
80
|
+
self.value = value
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func encode(to encoder: Encoder) throws {
|
|
84
|
+
var container = encoder.singleValueContainer()
|
|
85
|
+
|
|
86
|
+
switch value {
|
|
87
|
+
case let number as NSNumber:
|
|
88
|
+
try encodeNSNumber(number, into: &container)
|
|
89
|
+
case is NSNull, is Void:
|
|
90
|
+
try container.encodeNil()
|
|
91
|
+
case let string as String:
|
|
92
|
+
try container.encode(string)
|
|
93
|
+
case let date as Date:
|
|
94
|
+
try container.encode(date)
|
|
95
|
+
case let url as URL:
|
|
96
|
+
try container.encode(url)
|
|
97
|
+
case let array as [Any]:
|
|
98
|
+
try container.encode(array.map { AnyEncodable($0) })
|
|
99
|
+
case let dictionary as [String: Any]:
|
|
100
|
+
try container.encode(dictionary.mapValues { AnyEncodable($0) })
|
|
101
|
+
default:
|
|
102
|
+
let context = EncodingError.Context(
|
|
103
|
+
codingPath: container.codingPath,
|
|
104
|
+
debugDescription: "Value \(value) cannot be encoded - \(type(of: value)) is not supported by `AnyEncodable`."
|
|
105
|
+
)
|
|
106
|
+
throw EncodingError.invalidValue(value, context)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private func encodeNSNumber(_ nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws {
|
|
112
|
+
switch CFNumberGetType(nsnumber) {
|
|
113
|
+
case .charType:
|
|
114
|
+
try container.encode(nsnumber.boolValue)
|
|
115
|
+
case .sInt8Type:
|
|
116
|
+
try container.encode(nsnumber.int8Value)
|
|
117
|
+
case .sInt16Type:
|
|
118
|
+
try container.encode(nsnumber.int16Value)
|
|
119
|
+
case .sInt32Type:
|
|
120
|
+
try container.encode(nsnumber.int32Value)
|
|
121
|
+
case .sInt64Type:
|
|
122
|
+
try container.encode(nsnumber.int64Value)
|
|
123
|
+
case .shortType:
|
|
124
|
+
try container.encode(nsnumber.uint16Value)
|
|
125
|
+
case .longType:
|
|
126
|
+
try container.encode(nsnumber.uint32Value)
|
|
127
|
+
case .longLongType:
|
|
128
|
+
try container.encode(nsnumber.uint64Value)
|
|
129
|
+
case .intType, .nsIntegerType, .cfIndexType:
|
|
130
|
+
try container.encode(nsnumber.intValue)
|
|
131
|
+
case .floatType, .float32Type:
|
|
132
|
+
try container.encode(nsnumber.floatValue)
|
|
133
|
+
case .doubleType, .float64Type, .cgFloatType:
|
|
134
|
+
try container.encode(nsnumber.doubleValue)
|
|
135
|
+
@unknown default:
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
}
|