@datadog/mobile-react-native 1.0.0 → 1.1.0
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/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/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/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/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/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/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 +3 -3
- 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/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/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,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
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
4
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
5
|
+
* Copyright 2019-2020 Datadog, Inc.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
/// Internal attributes, passed to the iOS SDK.
|
|
11
|
+
/// Keep in sync with https://github.com/DataDog/dd-sdk-ios/blob/develop/Sources/Datadog/Core/Attributes/Attributes.swift.
|
|
12
|
+
internal struct CrossPlatformAttributes {
|
|
13
|
+
/// Custom app version passed from CP SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
|
|
14
|
+
/// It should replace the default native `version` read from `Info.plist`.
|
|
15
|
+
/// Expects `String` value (semantic version).
|
|
16
|
+
static let version: String = "_dd.version"
|
|
17
|
+
|
|
18
|
+
/// Custom SDK version passed from bridge SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
|
|
19
|
+
/// It should replace the default native `sdkVersion`.
|
|
20
|
+
/// Expects `String` value (semantic version).
|
|
21
|
+
static let sdkVersion: String = "_dd.sdk_version"
|
|
22
|
+
|
|
23
|
+
/// Custom SDK `source` passed from bridge SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
|
|
24
|
+
/// It should replace the default native `ddsource` value (`"ios"`).
|
|
25
|
+
/// Expects `String` value.
|
|
26
|
+
static let ddsource: String = "_dd.source"
|
|
27
|
+
|
|
28
|
+
/// Event timestamp passed from bridge SDK. Used for all RUM events issued by cross platform SDK.
|
|
29
|
+
/// It should replace event time obtained from `DateProvider` to ensure that events are not skewed due to time difference in native and cross-platform SDKs.
|
|
30
|
+
/// Expects `Int64` value (milliseconds).
|
|
31
|
+
static let timestampInMilliseconds = "_dd.timestamp"
|
|
32
|
+
|
|
33
|
+
/// Custom "source type" of the error passed from bridge SDK. Used in RUM errors reported by cross platform SDK.
|
|
34
|
+
/// It names the language or platform of the RUM error stack trace, so the SCI backend knows how to symbolicate it.
|
|
35
|
+
/// Expects `String` value.
|
|
36
|
+
static let errorSourceType = "_dd.error.source_type"
|
|
37
|
+
|
|
38
|
+
/// Custom attribute of the error passed from bridge SDK. Used in RUM errors reported by cross platform SDK.
|
|
39
|
+
/// It flags the error has being fatal for the host application.
|
|
40
|
+
/// Expects `Bool` value.
|
|
41
|
+
static let errorIsCrash = "_dd.error.is_crash"
|
|
42
|
+
|
|
43
|
+
/// Trace ID passed from bridge SDK. Used in RUM resources created by cross platform SDK.
|
|
44
|
+
/// When cross-platform SDK injects tracing headers to intercepted resource, we pass tracing information through this attribute
|
|
45
|
+
/// and send it within the RUM resource, so the RUM backend can issue corresponding APM span on behalf of the mobile app.
|
|
46
|
+
/// Expects `String` value.
|
|
47
|
+
static let traceID = "_dd.trace_id"
|
|
48
|
+
|
|
49
|
+
/// Span ID passed from bridge SDK. Used in RUM resources created by cross platform SDK.
|
|
50
|
+
/// When cross-platform SDK injects tracing headers to intercepted resource, we pass tracing information through this attribute
|
|
51
|
+
/// and send it within the RUM resource, so the RUM backend can issue corresponding APM span on behalf of the mobile app.
|
|
52
|
+
/// Expects `String` value.
|
|
53
|
+
static let spanID = "_dd.span_id"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Internal attributes used to configure the proxy.
|
|
57
|
+
internal struct ProxyAttributes {
|
|
58
|
+
/// Expects `String?` value.
|
|
59
|
+
static let address = "_dd.proxy.address"
|
|
60
|
+
|
|
61
|
+
/// Expects `String?` value
|
|
62
|
+
static let username = "_dd.proxy.username"
|
|
63
|
+
|
|
64
|
+
/// Expects `String?` value
|
|
65
|
+
static let password = "_dd.proxy.password"
|
|
66
|
+
|
|
67
|
+
/// Expects `String?` value
|
|
68
|
+
static let type = "_dd.proxy.type"
|
|
69
|
+
|
|
70
|
+
/// Expects `String?` or `Int?` value
|
|
71
|
+
static let port = "_dd.proxy.port"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Internal attributes used by the bridge only, passed from the javascript.
|
|
75
|
+
internal struct InternalConfigurationAttributes {
|
|
76
|
+
/// Enables native view tracking.
|
|
77
|
+
/// Expects `Bool?` value
|
|
78
|
+
static let nativeViewTracking = "_dd.native_view_tracking"
|
|
79
|
+
|
|
80
|
+
/// Enable overriding the service name.
|
|
81
|
+
/// Expects `String?` value
|
|
82
|
+
static let serviceName = "_dd.service_name"
|
|
83
|
+
|
|
84
|
+
/// Enable overriding the long task threshold for long task detection.
|
|
85
|
+
/// Expects `Double?` value
|
|
86
|
+
static let longTaskThreshold = "_dd.long_task.threshold"
|
|
87
|
+
|
|
88
|
+
/// Specify first party hosts for distributed tracing.
|
|
89
|
+
/// Even if the requests are intercepted at the javascript level, we have to pass this parameter to make sure the headers are
|
|
90
|
+
/// correctly set when sending the traces to the intake.
|
|
91
|
+
/// Expects `[String]?` value
|
|
92
|
+
static let firstPartyHosts = "_dd.first_party_hosts"
|
|
93
|
+
|
|
94
|
+
/// Specify native SDK verbosity
|
|
95
|
+
/// Expects `NSString?` value
|
|
96
|
+
static let sdkVerbosity = "_dd.sdk_verbosity"
|
|
97
|
+
|
|
98
|
+
/// Specify version suffix.
|
|
99
|
+
/// Expects `NSString?` value
|
|
100
|
+
static let versionSuffix = "_dd.version_suffix"
|
|
101
|
+
}
|