@datadog/mobile-react-native 2.1.1 → 2.3.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 +8 -7
- package/android/build.gradle +5 -4
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +11 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +5 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +3 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +64 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +164 -4
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +6 -354
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +351 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +5 -3
- package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +10 -0
- package/android/src/main/kotlin/com/datadog/reactnative/JSONFileReader.kt +20 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +4 -1
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +10 -0
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +3 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +3 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkConfigurationTest.kt +196 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +181 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +12 -271
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +10 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +28 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +24 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +9 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +1 -1
- package/android/src/test/resources/input/complete-configuration.json +48 -0
- package/android/src/test/resources/input/malformed-configuration.json +5 -0
- package/android/src/test/resources/input/minimal-configuration.json +8 -0
- package/datadog-configuration.gradle +57 -0
- package/datadog-configuration.schema.json +200 -0
- package/ios/Sources/DatadogSDKWrapper.swift +22 -19
- package/ios/Sources/DdLogsImplementation.swift +14 -0
- package/ios/Sources/DdSdk.h +2 -0
- package/ios/Sources/DdSdk.mm +6 -1
- package/ios/Sources/DdSdkConfiguration.swift +47 -56
- package/ios/Sources/DdSdkImplementation.swift +10 -279
- package/ios/Sources/DdSdkNativeInitialization.swift +218 -0
- package/ios/Sources/DdTraceImplementation.swift +3 -1
- package/ios/Sources/GlobalState.swift +1 -1
- package/ios/Sources/JSONFileReader.swift +28 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +227 -9
- package/ios/Sources/SdkVersion.swift +10 -0
- package/lib/commonjs/DdSdkReactNative.js +24 -66
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -4
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/ProxyConfiguration.js +15 -2
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +2 -2
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js +214 -0
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/commonjs/types.js +10 -2
- 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 +23 -65
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +22 -4
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/ProxyConfiguration.js +15 -2
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +2 -2
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js +197 -0
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/module/types.js +10 -2
- 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 +0 -9
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +43 -3
- package/lib/typescript/ProxyConfiguration.d.ts +4 -12
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts +2 -2
- package/lib/typescript/sdk/DatadogProvider/DatadogProvider.d.ts +2 -1
- package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +31 -0
- package/lib/typescript/types.d.ts +29 -3
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +58 -101
- package/src/DdSdkReactNativeConfiguration.tsx +26 -7
- package/src/ProxyConfiguration.tsx +17 -3
- package/src/__tests__/DdSdkReactNative.test.tsx +134 -112
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +19 -10
- package/src/__tests__/mock.test.ts +0 -9
- package/src/index.tsx +2 -0
- package/src/nativeModulesTypes.ts +1 -1
- package/src/sdk/DatadogProvider/DatadogProvider.tsx +3 -1
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +12 -5
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -2
- package/src/sdk/FileBasedConfiguration/FileBasedConfiguration.ts +235 -0
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +245 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/configuration-all-fields.json +22 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/malformed-configuration.json +5 -0
- package/src/types.tsx +21 -2
- package/src/version.ts +1 -1
|
@@ -0,0 +1,351 @@
|
|
|
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.reactnative
|
|
8
|
+
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.content.pm.PackageManager
|
|
11
|
+
import android.util.Log
|
|
12
|
+
import com.datadog.android.DatadogSite
|
|
13
|
+
import com.datadog.android.core.configuration.BatchSize
|
|
14
|
+
import com.datadog.android.core.configuration.Configuration
|
|
15
|
+
import com.datadog.android.core.configuration.UploadFrequency
|
|
16
|
+
import com.datadog.android.event.EventMapper
|
|
17
|
+
import com.datadog.android.log.LogsConfiguration
|
|
18
|
+
import com.datadog.android.privacy.TrackingConsent
|
|
19
|
+
import com.datadog.android.rum.RumConfiguration
|
|
20
|
+
import com.datadog.android.rum._RumInternalProxy
|
|
21
|
+
import com.datadog.android.rum.configuration.VitalsUpdateFrequency
|
|
22
|
+
import com.datadog.android.rum.model.ActionEvent
|
|
23
|
+
import com.datadog.android.rum.model.ResourceEvent
|
|
24
|
+
import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
|
|
25
|
+
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
|
|
26
|
+
import com.datadog.android.trace.TraceConfiguration
|
|
27
|
+
import com.google.gson.Gson
|
|
28
|
+
import java.util.Locale
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initializes the Android Datadog SDK.
|
|
32
|
+
*/
|
|
33
|
+
class DdSdkNativeInitialization internal constructor(
|
|
34
|
+
private val appContext: Context,
|
|
35
|
+
private val datadog: DatadogWrapper = DatadogSDKWrapper(),
|
|
36
|
+
private val jsonFileReader: JSONFileReader = JSONFileReader()
|
|
37
|
+
) {
|
|
38
|
+
internal fun initialize(ddSdkConfiguration: DdSdkConfiguration) {
|
|
39
|
+
val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration)
|
|
40
|
+
val rumConfiguration = buildRumConfiguration(ddSdkConfiguration)
|
|
41
|
+
val logsConfiguration = buildLogsConfiguration(ddSdkConfiguration)
|
|
42
|
+
val traceConfiguration = buildTraceConfiguration(ddSdkConfiguration)
|
|
43
|
+
val trackingConsent = buildTrackingConsent(ddSdkConfiguration.trackingConsent)
|
|
44
|
+
|
|
45
|
+
configureSdkVerbosity(ddSdkConfiguration)
|
|
46
|
+
configureRumAndTracesForLogs(ddSdkConfiguration)
|
|
47
|
+
|
|
48
|
+
datadog.initialize(appContext, sdkConfiguration, trackingConsent)
|
|
49
|
+
|
|
50
|
+
datadog.enableRum(rumConfiguration)
|
|
51
|
+
|
|
52
|
+
datadog.enableTrace(traceConfiguration)
|
|
53
|
+
|
|
54
|
+
datadog.enableLogs(logsConfiguration)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fun configureRumAndTracesForLogs(configuration: DdSdkConfiguration) {
|
|
58
|
+
configuration.bundleLogsWithRum?.let {
|
|
59
|
+
datadog.bundleLogsWithRum = it
|
|
60
|
+
}
|
|
61
|
+
configuration.bundleLogsWithTraces?.let {
|
|
62
|
+
datadog.bundleLogsWithTraces = it
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private fun configureSdkVerbosity(configuration: DdSdkConfiguration) {
|
|
67
|
+
val verbosity =
|
|
68
|
+
when (configuration.verbosity?.lowercase(Locale.US)) {
|
|
69
|
+
"debug" -> Log.DEBUG
|
|
70
|
+
"info" -> Log.INFO
|
|
71
|
+
"warn" -> Log.WARN
|
|
72
|
+
"error" -> Log.ERROR
|
|
73
|
+
else -> null
|
|
74
|
+
}
|
|
75
|
+
if (verbosity != null) {
|
|
76
|
+
datadog.setVerbosity(verbosity)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private fun getDefaultAppVersion(): String {
|
|
81
|
+
val packageName = appContext.packageName
|
|
82
|
+
val packageInfo =
|
|
83
|
+
try {
|
|
84
|
+
appContext.packageManager.getPackageInfo(packageName, 0)
|
|
85
|
+
} catch (e: PackageManager.NameNotFoundException) {
|
|
86
|
+
datadog.telemetryError(e.message ?: DdSdkImplementation.PACKAGE_INFO_NOT_FOUND_ERROR_MESSAGE, e)
|
|
87
|
+
return DdSdkImplementation.DEFAULT_APP_VERSION
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return packageInfo?.let {
|
|
91
|
+
// we need to use the deprecated method because getLongVersionCode method is only
|
|
92
|
+
// available from API 28 and above
|
|
93
|
+
@Suppress("DEPRECATION")
|
|
94
|
+
it.versionName ?: it.versionCode.toString()
|
|
95
|
+
}
|
|
96
|
+
?: DdSdkImplementation.DEFAULT_APP_VERSION
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun buildRumConfiguration(configuration: DdSdkConfiguration): RumConfiguration {
|
|
100
|
+
val configBuilder =
|
|
101
|
+
RumConfiguration.Builder(
|
|
102
|
+
applicationId = configuration.applicationId
|
|
103
|
+
)
|
|
104
|
+
if (configuration.sampleRate != null) {
|
|
105
|
+
configBuilder.setSessionSampleRate(configuration.sampleRate.toFloat())
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
configBuilder.trackFrustrations(configuration.trackFrustrations ?: true)
|
|
109
|
+
configBuilder.trackBackgroundEvents(configuration.trackBackgroundEvents ?: false)
|
|
110
|
+
|
|
111
|
+
configBuilder.setVitalsUpdateFrequency(
|
|
112
|
+
buildVitalUpdateFrequency(configuration.vitalsUpdateFrequency)
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat()
|
|
116
|
+
telemetrySampleRate?.let { configBuilder.setTelemetrySampleRate(it) }
|
|
117
|
+
|
|
118
|
+
val longTask = (configuration.nativeLongTaskThresholdMs as? Number)?.toLong()
|
|
119
|
+
if (longTask != null) {
|
|
120
|
+
configBuilder.trackLongTasks(longTask)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (configuration.nativeViewTracking == true) {
|
|
124
|
+
// Use sensible default
|
|
125
|
+
configBuilder.useViewTrackingStrategy(ActivityViewTrackingStrategy(false))
|
|
126
|
+
} else {
|
|
127
|
+
configBuilder.useViewTrackingStrategy(NoOpViewTrackingStrategy)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (configuration.nativeInteractionTracking == false) {
|
|
131
|
+
configBuilder.disableUserInteractionTracking()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
configBuilder.setResourceEventMapper(
|
|
135
|
+
object : EventMapper<ResourceEvent> {
|
|
136
|
+
override fun map(event: ResourceEvent): ResourceEvent? {
|
|
137
|
+
if (event.context?.additionalProperties?.containsKey(DdSdkImplementation.DD_DROP_RESOURCE) ==
|
|
138
|
+
true
|
|
139
|
+
) {
|
|
140
|
+
return null
|
|
141
|
+
}
|
|
142
|
+
return event
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
configBuilder.setActionEventMapper(
|
|
148
|
+
object : EventMapper<ActionEvent> {
|
|
149
|
+
override fun map(event: ActionEvent): ActionEvent? {
|
|
150
|
+
if (event.context?.additionalProperties?.containsKey(DdSdkImplementation.DD_DROP_ACTION) == true
|
|
151
|
+
) {
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
return event
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
_RumInternalProxy.setTelemetryConfigurationEventMapper(
|
|
160
|
+
configBuilder,
|
|
161
|
+
object : EventMapper<TelemetryConfigurationEvent> {
|
|
162
|
+
override fun map(
|
|
163
|
+
event: TelemetryConfigurationEvent
|
|
164
|
+
): TelemetryConfigurationEvent? {
|
|
165
|
+
event.telemetry.configuration.trackNativeErrors =
|
|
166
|
+
configuration.nativeCrashReportEnabled
|
|
167
|
+
// trackCrossPlatformLongTasks will be deprecated for trackLongTask
|
|
168
|
+
event.telemetry.configuration.trackCrossPlatformLongTasks =
|
|
169
|
+
configuration.longTaskThresholdMs != 0.0
|
|
170
|
+
event.telemetry.configuration.trackLongTask =
|
|
171
|
+
configuration.longTaskThresholdMs != 0.0
|
|
172
|
+
event.telemetry.configuration.trackNativeLongTasks =
|
|
173
|
+
configuration.nativeLongTaskThresholdMs != 0.0
|
|
174
|
+
|
|
175
|
+
event.telemetry.configuration.initializationType =
|
|
176
|
+
configuration.configurationForTelemetry?.initializationType
|
|
177
|
+
event.telemetry.configuration.trackInteractions =
|
|
178
|
+
configuration.configurationForTelemetry?.trackInteractions
|
|
179
|
+
event.telemetry.configuration.trackErrors =
|
|
180
|
+
configuration.configurationForTelemetry?.trackErrors
|
|
181
|
+
event.telemetry.configuration.trackResources =
|
|
182
|
+
configuration.configurationForTelemetry?.trackNetworkRequests
|
|
183
|
+
event.telemetry.configuration.trackNetworkRequests =
|
|
184
|
+
configuration.configurationForTelemetry?.trackNetworkRequests
|
|
185
|
+
event.telemetry.configuration.reactVersion =
|
|
186
|
+
configuration.configurationForTelemetry?.reactVersion
|
|
187
|
+
event.telemetry.configuration.reactNativeVersion =
|
|
188
|
+
configuration.configurationForTelemetry?.reactNativeVersion
|
|
189
|
+
|
|
190
|
+
return event
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
configuration.customEndpoints?.rum?.let {
|
|
196
|
+
configBuilder.useCustomEndpoint(it)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return configBuilder.build()
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private fun buildLogsConfiguration(configuration: DdSdkConfiguration): LogsConfiguration {
|
|
203
|
+
val configBuilder = LogsConfiguration.Builder()
|
|
204
|
+
configuration.customEndpoints?.logs?.let {
|
|
205
|
+
configBuilder.useCustomEndpoint(it)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return configBuilder.build()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private fun buildTraceConfiguration(configuration: DdSdkConfiguration): TraceConfiguration {
|
|
212
|
+
val configBuilder = TraceConfiguration.Builder()
|
|
213
|
+
configuration.customEndpoints?.trace?.let {
|
|
214
|
+
configBuilder.useCustomEndpoint(it)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return configBuilder.build()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private fun buildSdkConfiguration(configuration: DdSdkConfiguration): Configuration {
|
|
221
|
+
val configBuilder = Configuration.Builder(
|
|
222
|
+
clientToken = configuration.clientToken,
|
|
223
|
+
env = configuration.env,
|
|
224
|
+
variant = "",
|
|
225
|
+
service = configuration.serviceName
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
val additionalConfig = configuration.additionalConfig?.toMutableMap()
|
|
229
|
+
val versionSuffix = configuration.additionalConfig?.get(DdSdkImplementation.DD_VERSION_SUFFIX) as? String
|
|
230
|
+
if (versionSuffix != null && additionalConfig != null) {
|
|
231
|
+
val defaultVersion = getDefaultAppVersion()
|
|
232
|
+
additionalConfig.put(DdSdkImplementation.DD_VERSION, defaultVersion + versionSuffix)
|
|
233
|
+
}
|
|
234
|
+
configBuilder.setAdditionalConfiguration(
|
|
235
|
+
additionalConfig?.filterValues { it != null }?.mapValues {
|
|
236
|
+
it.value
|
|
237
|
+
} as Map<String, Any>? ?: emptyMap()
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
configBuilder.setCrashReportsEnabled(configuration.nativeCrashReportEnabled ?: false)
|
|
241
|
+
configBuilder.useSite(buildSite(configuration.site))
|
|
242
|
+
configBuilder.setUploadFrequency(
|
|
243
|
+
buildUploadFrequency(configuration.uploadFrequency)
|
|
244
|
+
)
|
|
245
|
+
configBuilder.setBatchSize(
|
|
246
|
+
buildBatchSize(configuration.batchSize)
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
configuration.proxyConfig?.let { (proxy, authenticator) ->
|
|
250
|
+
configBuilder.setProxy(proxy, authenticator)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (configuration.firstPartyHosts != null) {
|
|
254
|
+
configBuilder.setFirstPartyHostsWithHeaderType(configuration.firstPartyHosts)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return configBuilder.build()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private fun buildTrackingConsent(trackingConsent: String?): TrackingConsent {
|
|
261
|
+
return when (trackingConsent?.lowercase(Locale.US)) {
|
|
262
|
+
"pending" -> TrackingConsent.PENDING
|
|
263
|
+
"granted" -> TrackingConsent.GRANTED
|
|
264
|
+
"not_granted" -> TrackingConsent.NOT_GRANTED
|
|
265
|
+
else -> {
|
|
266
|
+
Log.w(
|
|
267
|
+
DdSdk::class.java.canonicalName,
|
|
268
|
+
"Unknown consent given: $trackingConsent, " +
|
|
269
|
+
"using ${TrackingConsent.PENDING} as default"
|
|
270
|
+
)
|
|
271
|
+
TrackingConsent.PENDING
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private fun buildSite(site: String?): DatadogSite {
|
|
277
|
+
val siteLower = site?.lowercase(Locale.US)
|
|
278
|
+
return when (siteLower) {
|
|
279
|
+
"us1", "us" -> DatadogSite.US1
|
|
280
|
+
"eu1", "eu" -> DatadogSite.EU1
|
|
281
|
+
"us3" -> DatadogSite.US3
|
|
282
|
+
"us5" -> DatadogSite.US5
|
|
283
|
+
"us1_fed", "gov" -> DatadogSite.US1_FED
|
|
284
|
+
"ap1" -> DatadogSite.AP1
|
|
285
|
+
else -> DatadogSite.US1
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private fun buildVitalUpdateFrequency(vitalsUpdateFrequency: String?): VitalsUpdateFrequency {
|
|
290
|
+
val vitalUpdateFrequencyLower = vitalsUpdateFrequency?.lowercase(Locale.US)
|
|
291
|
+
return when (vitalUpdateFrequencyLower) {
|
|
292
|
+
"never" -> VitalsUpdateFrequency.NEVER
|
|
293
|
+
"rare" -> VitalsUpdateFrequency.RARE
|
|
294
|
+
"average" -> VitalsUpdateFrequency.AVERAGE
|
|
295
|
+
"frequent" -> VitalsUpdateFrequency.FREQUENT
|
|
296
|
+
else -> VitalsUpdateFrequency.AVERAGE
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private fun buildUploadFrequency(uploadFrequency: String?): UploadFrequency {
|
|
301
|
+
return when (uploadFrequency?.lowercase(Locale.US)) {
|
|
302
|
+
"rare" -> UploadFrequency.RARE
|
|
303
|
+
"average" -> UploadFrequency.AVERAGE
|
|
304
|
+
"frequent" -> UploadFrequency.FREQUENT
|
|
305
|
+
else -> UploadFrequency.AVERAGE
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private fun buildBatchSize(batchSize: String?): BatchSize {
|
|
310
|
+
return when (batchSize?.lowercase(Locale.US)) {
|
|
311
|
+
"small" -> BatchSize.SMALL
|
|
312
|
+
"medium" -> BatchSize.MEDIUM
|
|
313
|
+
"large" -> BatchSize.LARGE
|
|
314
|
+
else -> BatchSize.MEDIUM
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
internal fun getConfigurationFromJSONFile(): DdSdkConfiguration {
|
|
319
|
+
try {
|
|
320
|
+
val jsonString = jsonFileReader.parseAssetsJSONFile(appContext, "datadog-configuration.json")
|
|
321
|
+
|
|
322
|
+
val configuration = Gson().fromJson(jsonString, JSONConfigurationFile::class.java).configuration
|
|
323
|
+
|
|
324
|
+
return configuration.asDdSdkConfiguration()
|
|
325
|
+
} catch (@Suppress("TooGenericExceptionCaught") exception: Exception) {
|
|
326
|
+
throw BadConfigurationException(exception)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
companion object {
|
|
331
|
+
/**
|
|
332
|
+
* Initializes the Datadog React Native SDK from your MainApplication.
|
|
333
|
+
*
|
|
334
|
+
* @param appContext: The application context of your React Native application.
|
|
335
|
+
*/
|
|
336
|
+
@JvmStatic
|
|
337
|
+
fun initFromNative(appContext: Context) {
|
|
338
|
+
val nativeInitialization = DdSdkNativeInitialization(appContext.applicationContext)
|
|
339
|
+
try {
|
|
340
|
+
nativeInitialization.initialize(nativeInitialization.getConfigurationFromJSONFile())
|
|
341
|
+
} catch (@Suppress("TooGenericExceptionCaught") error: Exception) {
|
|
342
|
+
Log.w(
|
|
343
|
+
DdSdkNativeInitialization::class.java.canonicalName,
|
|
344
|
+
"Failed to initialize the Datadog SDK: $error"
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
internal class BadConfigurationException(exception: Exception) : RuntimeException(exception)
|
|
@@ -16,12 +16,14 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
|
16
16
|
* Package of native dd-sdk-reactnative native modules.
|
|
17
17
|
*/
|
|
18
18
|
class DdSdkReactNativePackage : TurboReactPackage() {
|
|
19
|
+
private val sdkWrapper = DatadogSDKWrapper()
|
|
20
|
+
|
|
19
21
|
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
20
22
|
return when (name) {
|
|
21
|
-
DdSdkImplementation.NAME -> DdSdk(reactContext)
|
|
22
|
-
DdRumImplementation.NAME -> DdRum(reactContext)
|
|
23
|
+
DdSdkImplementation.NAME -> DdSdk(reactContext, sdkWrapper)
|
|
24
|
+
DdRumImplementation.NAME -> DdRum(reactContext, sdkWrapper)
|
|
23
25
|
DdTraceImplementation.NAME -> DdTrace(reactContext)
|
|
24
|
-
DdLogsImplementation.NAME -> DdLogs(reactContext)
|
|
26
|
+
DdLogsImplementation.NAME -> DdLogs(reactContext, sdkWrapper)
|
|
25
27
|
else -> null
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -11,6 +11,7 @@ import com.datadog.android.trace.Trace
|
|
|
11
11
|
import com.datadog.android.trace.TraceConfiguration
|
|
12
12
|
import com.facebook.react.bridge.Promise
|
|
13
13
|
import com.facebook.react.bridge.ReadableMap
|
|
14
|
+
import io.opentracing.Scope
|
|
14
15
|
import io.opentracing.Span
|
|
15
16
|
import io.opentracing.Tracer
|
|
16
17
|
import io.opentracing.util.GlobalTracer
|
|
@@ -28,6 +29,7 @@ class DdTraceImplementation(
|
|
|
28
29
|
}
|
|
29
30
|
) {
|
|
30
31
|
private val spanMap: MutableMap<String, Span> = mutableMapOf()
|
|
32
|
+
private val scopeMap: MutableMap<String, Scope> = mutableMapOf()
|
|
31
33
|
|
|
32
34
|
// lazy here is on purpose. The thing is that this class will be instantiated even
|
|
33
35
|
// before Sdk.initialize is called, but Tracer can be created only after SDK is initialized.
|
|
@@ -43,12 +45,17 @@ class DdTraceImplementation(
|
|
|
43
45
|
val span = tracer.buildSpan(operation)
|
|
44
46
|
.withStartTimestamp(TimeUnit.MILLISECONDS.toMicros(timestampMs.toLong()))
|
|
45
47
|
.start()
|
|
48
|
+
|
|
49
|
+
// This is required for traces to be able to be bundled with logs.
|
|
50
|
+
val scope = tracer.scopeManager().activate(span)
|
|
51
|
+
|
|
46
52
|
val spanContext = span.context()
|
|
47
53
|
|
|
48
54
|
span.setTags(context.toHashMap())
|
|
49
55
|
span.setTags(GlobalState.globalAttributes)
|
|
50
56
|
val spanId = spanContext.toSpanId()
|
|
51
57
|
spanMap[spanId] = span
|
|
58
|
+
scopeMap[spanId] = scope
|
|
52
59
|
|
|
53
60
|
promise.resolve(spanId)
|
|
54
61
|
}
|
|
@@ -60,6 +67,9 @@ class DdTraceImplementation(
|
|
|
60
67
|
* @param timestampMs The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
61
68
|
*/
|
|
62
69
|
fun finishSpan(spanId: String, context: ReadableMap, timestampMs: Double, promise: Promise) {
|
|
70
|
+
val scope = scopeMap.remove(spanId)
|
|
71
|
+
scope?.close()
|
|
72
|
+
|
|
63
73
|
val span = spanMap.remove(spanId)
|
|
64
74
|
if (span == null) {
|
|
65
75
|
promise.resolve(null)
|
|
@@ -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.reactnative
|
|
8
|
+
|
|
9
|
+
import android.content.Context
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Utility for parsing JSON files from the app assets.
|
|
13
|
+
*/
|
|
14
|
+
internal class JSONFileReader {
|
|
15
|
+
internal fun parseAssetsJSONFile(appContext: Context, filePath: String): String {
|
|
16
|
+
return appContext.assets.open(filePath).use {
|
|
17
|
+
it.bufferedReader().readText()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -13,7 +13,10 @@ import okhttp3.Request
|
|
|
13
13
|
import okhttp3.Response
|
|
14
14
|
import okhttp3.Route
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Class representing the authentication for Proxy.
|
|
18
|
+
*/
|
|
19
|
+
class ProxyAuthenticator(
|
|
17
20
|
internal val username: String,
|
|
18
21
|
internal val password: String
|
|
19
22
|
) : Authenticator {
|
|
@@ -0,0 +1,10 @@
|
|
|
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.reactnative
|
|
8
|
+
|
|
9
|
+
// This is automatically updated by the update-version.sh script
|
|
10
|
+
internal const val SDK_VERSION = "2.3.0"
|
|
@@ -16,10 +16,11 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
16
16
|
* The entry point to use Datadog's Logs feature.
|
|
17
17
|
*/
|
|
18
18
|
class DdLogs(
|
|
19
|
-
reactContext: ReactApplicationContext
|
|
19
|
+
reactContext: ReactApplicationContext,
|
|
20
|
+
datadogWrapper: DatadogWrapper
|
|
20
21
|
) : ReactContextBaseJavaModule(reactContext) {
|
|
21
22
|
|
|
22
|
-
private val implementation = DdLogsImplementation()
|
|
23
|
+
private val implementation = DdLogsImplementation(datadog = datadogWrapper)
|
|
23
24
|
|
|
24
25
|
override fun getName(): String = DdLogsImplementation.NAME
|
|
25
26
|
|
|
@@ -16,9 +16,12 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
16
16
|
* The entry point to use Datadog's RUM feature.
|
|
17
17
|
*/
|
|
18
18
|
@Suppress("TooManyFunctions")
|
|
19
|
-
class DdRum(
|
|
19
|
+
class DdRum(
|
|
20
|
+
reactContext: ReactApplicationContext,
|
|
21
|
+
datadogWrapper: DatadogWrapper
|
|
22
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
20
23
|
|
|
21
|
-
private val implementation = DdRumImplementation()
|
|
24
|
+
private val implementation = DdRumImplementation(datadog = datadogWrapper)
|
|
22
25
|
|
|
23
26
|
override fun getName(): String = DdRumImplementation.NAME
|
|
24
27
|
|
|
@@ -14,10 +14,11 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
14
14
|
|
|
15
15
|
/** The entry point to initialize Datadog's features. */
|
|
16
16
|
class DdSdk(
|
|
17
|
-
reactContext: ReactApplicationContext
|
|
17
|
+
reactContext: ReactApplicationContext,
|
|
18
|
+
datadogWrapper: DatadogWrapper = DatadogSDKWrapper()
|
|
18
19
|
) : ReactContextBaseJavaModule(reactContext) {
|
|
19
20
|
|
|
20
|
-
private val implementation = DdSdkImplementation(reactContext)
|
|
21
|
+
private val implementation = DdSdkImplementation(reactContext, datadog = datadogWrapper)
|
|
21
22
|
|
|
22
23
|
override fun getName(): String = DdSdkImplementation.NAME
|
|
23
24
|
|