@datadog/mobile-react-native 1.0.0-rc4 → 1.0.0-rc7
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 +1 -1
- package/README.md +47 -16
- package/android/build.gradle +1 -1
- package/android/gradle.properties +4 -4
- package/lib/commonjs/DdSdkReactNative.js +38 -23
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +56 -0
- package/lib/commonjs/InternalLog.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js +26 -0
- package/lib/commonjs/SdkVerbosity.js.map +1 -0
- package/lib/commonjs/TimeProvider.js +72 -0
- package/lib/commonjs/TimeProvider.js.map +1 -0
- package/lib/commonjs/Timer.js +10 -23
- package/lib/commonjs/Timer.js.map +1 -1
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +51 -11
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +34 -18
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +14 -5
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +34 -23
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +62 -36
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -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 +31 -23
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +52 -0
- package/lib/module/InternalLog.js.map +1 -0
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js +18 -0
- package/lib/module/SdkVerbosity.js.map +1 -0
- package/lib/module/TimeProvider.js +63 -0
- package/lib/module/TimeProvider.js.map +1 -0
- package/lib/module/Timer.js +14 -23
- package/lib/module/Timer.js.map +1 -1
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +31 -11
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +30 -23
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -34
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
- 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 +6 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/InternalLog.d.ts +11 -0
- package/lib/typescript/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/src/DdSdkReactNative.tsx +112 -62
- package/src/DdSdkReactNativeConfiguration.tsx +22 -14
- package/src/InternalLog.tsx +50 -0
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
- package/src/TimeProvider.tsx +64 -0
- package/src/Timer.ts +20 -35
- package/src/TrackingConsent.tsx +3 -3
- package/src/__mocks__/InternalLog.tsx +9 -0
- package/src/__tests__/DdRumWrapper.test.tsx +40 -33
- package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
- package/src/__tests__/InternalLog.test.tsx +379 -0
- package/src/__tests__/TimeProvider.test.tsx +75 -0
- package/src/__tests__/Timer.test.ts +148 -57
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +179 -106
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +80 -61
- package/src/index.tsx +15 -3
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +61 -49
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +307 -233
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
- package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
- package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
- package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
- package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
- package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
- package/src/types.tsx +199 -158
- package/src/version.ts +1 -1
- package/lib/commonjs/NativeSdkVerbosity.js +0 -26
- package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
- package/lib/module/NativeSdkVerbosity.js +0 -18
- package/lib/module/NativeSdkVerbosity.js.map +0 -1
- package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -4,83 +4,111 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { DdSdkReactNativeConfiguration } from
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
import {
|
|
7
|
+
import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
8
|
+
import { InternalLog } from './InternalLog';
|
|
9
|
+
import { ProxyType } from './ProxyConfiguration';
|
|
10
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
11
|
+
import type { TrackingConsent } from './TrackingConsent';
|
|
12
|
+
import { DdSdk } from './foundation';
|
|
13
|
+
import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';
|
|
14
|
+
import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking';
|
|
15
|
+
import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';
|
|
16
|
+
import { DdSdkConfiguration } from './types';
|
|
17
|
+
import { version as sdkVersion } from './version';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
20
21
|
*/
|
|
21
22
|
export class DdSdkReactNative {
|
|
22
|
-
|
|
23
|
-
private static readonly
|
|
24
|
-
private static readonly
|
|
25
|
-
private static readonly
|
|
26
|
-
private static readonly
|
|
27
|
-
|
|
23
|
+
private static readonly DD_SOURCE_KEY = '_dd.source';
|
|
24
|
+
private static readonly DD_SDK_VERSION = '_dd.sdk_version';
|
|
25
|
+
private static readonly DD_SERVICE_NAME = '_dd.service_name';
|
|
26
|
+
private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';
|
|
27
|
+
private static readonly DD_NATIVE_VIEW_TRACKING_KEY =
|
|
28
|
+
'_dd.native_view_tracking';
|
|
28
29
|
|
|
29
30
|
// Proxy
|
|
30
|
-
private static readonly DD_PROXY_TYPE_KEY =
|
|
31
|
-
private static readonly DD_PROXY_ADDRESS_KEY =
|
|
32
|
-
private static readonly DD_PROXY_PORT_KEY =
|
|
33
|
-
private static readonly DD_PROXY_USERNAME_KEY =
|
|
34
|
-
private static readonly DD_PROXY_PASSWORD_KEY =
|
|
35
|
-
|
|
36
|
-
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = "_dd.long_task.threshold"
|
|
37
|
-
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200
|
|
31
|
+
private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';
|
|
32
|
+
private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';
|
|
33
|
+
private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';
|
|
34
|
+
private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';
|
|
35
|
+
private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';
|
|
38
36
|
|
|
37
|
+
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =
|
|
38
|
+
'_dd.long_task.threshold';
|
|
39
|
+
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;
|
|
39
40
|
|
|
40
|
-
private static wasInitialized = false
|
|
41
|
+
private static wasInitialized = false;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
static initialize(
|
|
44
|
+
* Initializes the Datadog SDK.
|
|
45
|
+
* @param configuration the configuration for the SDK library
|
|
46
|
+
* @returns a Promise.
|
|
47
|
+
*/
|
|
48
|
+
static initialize(
|
|
49
|
+
configuration: DdSdkReactNativeConfiguration
|
|
50
|
+
): Promise<void> {
|
|
48
51
|
return new Promise<void>((resolve, reject) => {
|
|
49
52
|
if (DdSdkReactNative.wasInitialized) {
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
InternalLog.log(
|
|
54
|
+
"Can't initialize Datadog, SDK was already initialized",
|
|
55
|
+
SdkVerbosity.WARN
|
|
56
|
+
);
|
|
57
|
+
resolve();
|
|
58
|
+
return;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
configuration.additionalConfig[DdSdkReactNative.
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
InternalLog.verbosity = configuration.verbosity;
|
|
62
|
+
|
|
63
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =
|
|
64
|
+
'react-native';
|
|
65
|
+
configuration.additionalConfig[
|
|
66
|
+
DdSdkReactNative.DD_SDK_VERSION
|
|
67
|
+
] = sdkVersion;
|
|
68
|
+
configuration.additionalConfig[
|
|
69
|
+
DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY
|
|
70
|
+
] = configuration.nativeViewTracking;
|
|
71
|
+
if (configuration.verbosity) {
|
|
72
|
+
configuration.additionalConfig[
|
|
73
|
+
DdSdkReactNative.DD_SDK_VERBOSITY_KEY
|
|
74
|
+
] = configuration.verbosity;
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
if (configuration.proxyConfig) {
|
|
62
78
|
const additionalConfig = configuration.additionalConfig;
|
|
63
79
|
const proxyConfig = configuration.proxyConfig;
|
|
64
80
|
|
|
65
|
-
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
66
|
-
|
|
67
|
-
additionalConfig[DdSdkReactNative.
|
|
81
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =
|
|
82
|
+
proxyConfig.type;
|
|
83
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =
|
|
84
|
+
proxyConfig.address;
|
|
85
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =
|
|
86
|
+
proxyConfig.port;
|
|
68
87
|
if (proxyConfig.username && proxyConfig.password) {
|
|
69
|
-
if (proxyConfig.type
|
|
70
|
-
console.warn(
|
|
88
|
+
if (proxyConfig.type === ProxyType.SOCKS) {
|
|
89
|
+
console.warn(
|
|
90
|
+
"SOCKS proxy configuration doesn't support Basic authentication."
|
|
91
|
+
);
|
|
71
92
|
} else {
|
|
72
|
-
additionalConfig[
|
|
73
|
-
|
|
93
|
+
additionalConfig[
|
|
94
|
+
DdSdkReactNative.DD_PROXY_USERNAME_KEY
|
|
95
|
+
] = proxyConfig.username;
|
|
96
|
+
additionalConfig[
|
|
97
|
+
DdSdkReactNative.DD_PROXY_PASSWORD_KEY
|
|
98
|
+
] = proxyConfig.password;
|
|
74
99
|
}
|
|
75
100
|
}
|
|
76
101
|
}
|
|
77
102
|
|
|
78
103
|
if (configuration.serviceName) {
|
|
79
|
-
configuration.additionalConfig[
|
|
104
|
+
configuration.additionalConfig[
|
|
105
|
+
DdSdkReactNative.DD_SERVICE_NAME
|
|
106
|
+
] = configuration.serviceName;
|
|
80
107
|
}
|
|
81
108
|
|
|
82
|
-
configuration.additionalConfig[
|
|
83
|
-
|
|
109
|
+
configuration.additionalConfig[
|
|
110
|
+
DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY
|
|
111
|
+
] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
84
112
|
|
|
85
113
|
DdSdk.initialize(
|
|
86
114
|
new DdSdkConfiguration(
|
|
@@ -88,19 +116,28 @@ export class DdSdkReactNative {
|
|
|
88
116
|
configuration.env,
|
|
89
117
|
configuration.applicationId,
|
|
90
118
|
configuration.nativeCrashReportEnabled,
|
|
91
|
-
configuration.sampleRate
|
|
119
|
+
configuration.sampleRate === undefined
|
|
120
|
+
? configuration.sessionSamplingRate
|
|
121
|
+
: configuration.sampleRate,
|
|
92
122
|
configuration.site,
|
|
93
123
|
configuration.trackingConsent,
|
|
94
124
|
configuration.additionalConfig
|
|
95
125
|
)
|
|
96
|
-
).then(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
126
|
+
).then(
|
|
127
|
+
() => {
|
|
128
|
+
InternalLog.log(
|
|
129
|
+
'Datadog SDK was initialized',
|
|
130
|
+
SdkVerbosity.INFO
|
|
131
|
+
);
|
|
132
|
+
DdSdkReactNative.enableFeatures(configuration);
|
|
133
|
+
DdSdkReactNative.wasInitialized = true;
|
|
134
|
+
resolve();
|
|
135
|
+
},
|
|
136
|
+
rejection => {
|
|
137
|
+
reject(rejection);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
});
|
|
104
141
|
}
|
|
105
142
|
|
|
106
143
|
/**
|
|
@@ -110,7 +147,11 @@ export class DdSdkReactNative {
|
|
|
110
147
|
*/
|
|
111
148
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
112
149
|
static setAttributes(attributes: object): Promise<void> {
|
|
113
|
-
|
|
150
|
+
InternalLog.log(
|
|
151
|
+
`Setting attributes ${JSON.stringify(attributes)}`,
|
|
152
|
+
SdkVerbosity.DEBUG
|
|
153
|
+
);
|
|
154
|
+
return DdSdk.setAttributes(attributes);
|
|
114
155
|
}
|
|
115
156
|
|
|
116
157
|
/**
|
|
@@ -120,7 +161,11 @@ export class DdSdkReactNative {
|
|
|
120
161
|
*/
|
|
121
162
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
122
163
|
static setUser(user: object): Promise<void> {
|
|
123
|
-
|
|
164
|
+
InternalLog.log(
|
|
165
|
+
`Setting user ${JSON.stringify(user)}`,
|
|
166
|
+
SdkVerbosity.DEBUG
|
|
167
|
+
);
|
|
168
|
+
return DdSdk.setUser(user);
|
|
124
169
|
}
|
|
125
170
|
|
|
126
171
|
/**
|
|
@@ -129,20 +174,25 @@ export class DdSdkReactNative {
|
|
|
129
174
|
* @returns a Promise.
|
|
130
175
|
*/
|
|
131
176
|
static setTrackingConsent(consent: TrackingConsent): Promise<void> {
|
|
132
|
-
|
|
177
|
+
InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);
|
|
178
|
+
return DdSdk.setTrackingConsent(consent);
|
|
133
179
|
}
|
|
134
180
|
|
|
135
|
-
private static enableFeatures(
|
|
181
|
+
private static enableFeatures(
|
|
182
|
+
configuration: DdSdkReactNativeConfiguration
|
|
183
|
+
) {
|
|
136
184
|
if (configuration.trackInteractions) {
|
|
137
185
|
DdRumUserInteractionTracking.startTracking();
|
|
138
186
|
}
|
|
139
187
|
|
|
140
188
|
if (configuration.trackResources) {
|
|
141
|
-
DdRumResourceTracking.startTracking(
|
|
189
|
+
DdRumResourceTracking.startTracking(
|
|
190
|
+
configuration.resourceTracingSamplingRate
|
|
191
|
+
);
|
|
142
192
|
}
|
|
143
193
|
|
|
144
194
|
if (configuration.trackErrors) {
|
|
145
195
|
DdRumErrorTracking.startTracking();
|
|
146
196
|
}
|
|
147
197
|
}
|
|
148
|
-
}
|
|
198
|
+
}
|
|
@@ -4,25 +4,35 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { TrackingConsent } from './TrackingConsent'
|
|
8
|
-
import type { NativeSdkVerbosity } from './NativeSdkVerbosity'
|
|
9
7
|
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
8
|
+
import type { SdkVerbosity } from './SdkVerbosity';
|
|
9
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The SDK configuration class.
|
|
13
13
|
* It will be used to configure the SDK functionality at initialization.
|
|
14
14
|
*/
|
|
15
15
|
export class DdSdkReactNativeConfiguration {
|
|
16
|
-
|
|
17
16
|
public nativeCrashReportEnabled: boolean = false;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
public
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
public
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
|
+
*/
|
|
20
|
+
public sampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
|
+
*/
|
|
24
|
+
public sessionSamplingRate: number = 100.0;
|
|
25
|
+
/**
|
|
26
|
+
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
|
+
*/
|
|
28
|
+
public resourceTracingSamplingRate: number = 20.0;
|
|
29
|
+
public site: string = 'US';
|
|
30
|
+
public verbosity: SdkVerbosity | undefined = undefined;
|
|
31
|
+
public nativeViewTracking: boolean = false;
|
|
32
|
+
public proxyConfig?: ProxyConfiguration = undefined;
|
|
33
|
+
public serviceName?: string = undefined;
|
|
34
|
+
|
|
35
|
+
public additionalConfig: { [k: string]: any } = {};
|
|
26
36
|
|
|
27
37
|
constructor(
|
|
28
38
|
readonly clientToken: string,
|
|
@@ -32,7 +42,5 @@ export class DdSdkReactNativeConfiguration {
|
|
|
32
42
|
readonly trackResources: boolean = false,
|
|
33
43
|
readonly trackErrors: boolean = false,
|
|
34
44
|
readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED
|
|
35
|
-
) {
|
|
36
|
-
|
|
37
|
-
}
|
|
45
|
+
) {}
|
|
38
46
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { SdkVerbosity } from './SdkVerbosity';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* /!\ DO NOT USE THIS IN YOUR APP /!\\
|
|
11
|
+
*
|
|
12
|
+
* This logger is only for debugging the Datadog SDK.
|
|
13
|
+
*/
|
|
14
|
+
export class InternalLog {
|
|
15
|
+
private static levelMap = new Map<SdkVerbosity, number>([
|
|
16
|
+
[SdkVerbosity.DEBUG, 1],
|
|
17
|
+
[SdkVerbosity.INFO, 2],
|
|
18
|
+
[SdkVerbosity.WARN, 3],
|
|
19
|
+
[SdkVerbosity.ERROR, 4]
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
public static verbosity: SdkVerbosity | undefined = undefined;
|
|
23
|
+
|
|
24
|
+
public static log(message: string, verbosity: SdkVerbosity): void {
|
|
25
|
+
if (InternalLog.verbosity === undefined) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const requiredLevel = InternalLog.levelMap.get(verbosity);
|
|
29
|
+
const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
|
|
30
|
+
if (allowedLevel === undefined || requiredLevel === undefined) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const prefixedMessage = `DATADOG: ${message}`;
|
|
34
|
+
if (verbosity === SdkVerbosity.ERROR && requiredLevel >= allowedLevel) {
|
|
35
|
+
console.error(prefixedMessage);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (verbosity === SdkVerbosity.WARN && requiredLevel >= allowedLevel) {
|
|
39
|
+
console.warn(prefixedMessage);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (verbosity === SdkVerbosity.INFO && requiredLevel >= allowedLevel) {
|
|
43
|
+
console.info(prefixedMessage);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (verbosity === SdkVerbosity.DEBUG && requiredLevel >= allowedLevel) {
|
|
47
|
+
console.debug(prefixedMessage);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -25,13 +25,13 @@ class ProxyConfiguration {
|
|
|
25
25
|
* Password for Basic authentication scheme.
|
|
26
26
|
*/
|
|
27
27
|
readonly password?: string
|
|
28
|
-
) {
|
|
28
|
+
) {}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
enum ProxyType {
|
|
32
|
-
HTTP =
|
|
33
|
-
HTTPS =
|
|
34
|
-
SOCKS =
|
|
32
|
+
HTTP = 'http',
|
|
33
|
+
HTTPS = 'https',
|
|
34
|
+
SOCKS = 'socks'
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export { ProxyConfiguration, ProxyType }
|
|
37
|
+
export { ProxyConfiguration, ProxyType };
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Enum specifying possible
|
|
8
|
+
* Enum specifying possible log levels for DD SDK.
|
|
9
9
|
*/
|
|
10
|
-
export enum
|
|
11
|
-
DEBUG =
|
|
12
|
-
INFO =
|
|
13
|
-
WARN =
|
|
14
|
-
ERROR =
|
|
10
|
+
export enum SdkVerbosity {
|
|
11
|
+
DEBUG = 'debug',
|
|
12
|
+
INFO = 'info',
|
|
13
|
+
WARN = 'warn',
|
|
14
|
+
ERROR = 'error'
|
|
15
15
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* A Timestamp structure holding the
|
|
9
|
+
*/
|
|
10
|
+
export type Timestamp = {
|
|
11
|
+
// Result of Date API. Unix timestamp in ms.
|
|
12
|
+
unix: number;
|
|
13
|
+
// Result of performance.now API. Timestamp in ms (with microsecond precision)
|
|
14
|
+
// since JS context start.
|
|
15
|
+
react_native: number | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Simple class providing timestamps in milliseconds.
|
|
20
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
21
|
+
*/
|
|
22
|
+
export class TimeProvider {
|
|
23
|
+
private canUsePerformanceNow =
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
global.performance && typeof performance.now === 'function';
|
|
27
|
+
|
|
28
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
29
|
+
private baseOffset: number;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
const timestamp = this.getTimestamp();
|
|
33
|
+
if (timestamp.react_native == null) {
|
|
34
|
+
this.baseOffset = 0;
|
|
35
|
+
} else {
|
|
36
|
+
this.baseOffset = timestamp.unix - timestamp.react_native;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getTimestamp(): Timestamp {
|
|
41
|
+
return {
|
|
42
|
+
unix: Date.now(),
|
|
43
|
+
react_native: this.performanceNow()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
now(): number {
|
|
48
|
+
const timestamp = this.getTimestamp();
|
|
49
|
+
if (timestamp.react_native == null) {
|
|
50
|
+
return timestamp.unix;
|
|
51
|
+
} else {
|
|
52
|
+
return this.baseOffset + timestamp.react_native;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private performanceNow(): number | null {
|
|
57
|
+
if (this.canUsePerformanceNow) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
return performance.now();
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/Timer.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
react_native: number | null
|
|
7
|
-
}
|
|
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
|
+
*/
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import type { Timestamp } from './TimeProvider';
|
|
8
|
+
import { TimeProvider } from './TimeProvider';
|
|
9
|
+
|
|
10
|
+
const START_LABEL = '__start';
|
|
11
|
+
const STOP_LABEL = '__stop';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Simple timer which records time ticks. Shouldn't be re-used once stopped.
|
|
14
15
|
* All timestamps/durations returned are in milliseconds.
|
|
15
16
|
*/
|
|
16
17
|
export default class Timer {
|
|
17
|
-
|
|
18
|
+
private timeProvider: TimeProvider;
|
|
18
19
|
private times: Record<string, Timestamp> = {};
|
|
19
20
|
|
|
21
|
+
constructor(timeProvider: TimeProvider = new TimeProvider()) {
|
|
22
|
+
this.timeProvider = timeProvider;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
get startTime(): number {
|
|
21
|
-
return this.times[START_LABEL].unix
|
|
26
|
+
return this.times[START_LABEL].unix;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
get stopTime(): number {
|
|
25
|
-
return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL)
|
|
30
|
+
return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL);
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
start(): void {
|
|
@@ -30,14 +35,11 @@ export default class Timer {
|
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
stop(): void {
|
|
33
|
-
this.recordTick(STOP_LABEL)
|
|
38
|
+
this.recordTick(STOP_LABEL);
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
recordTick(label: string): void {
|
|
37
|
-
this.times[label] =
|
|
38
|
-
unix: Date.now(),
|
|
39
|
-
react_native: this.performanceNow()
|
|
40
|
-
}
|
|
42
|
+
this.times[label] = this.timeProvider.getTimestamp();
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
hasTickFor(label: string): boolean {
|
|
@@ -57,7 +59,7 @@ export default class Timer {
|
|
|
57
59
|
timeAt(label: string): number {
|
|
58
60
|
this.checkLabelExists(label);
|
|
59
61
|
|
|
60
|
-
return this.startTime + this.durationBetween(START_LABEL, label)
|
|
62
|
+
return this.startTime + this.durationBetween(START_LABEL, label);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
reset(): void {
|
|
@@ -71,26 +73,9 @@ export default class Timer {
|
|
|
71
73
|
return end.unix - start.unix;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
private performanceNow(): number | null {
|
|
76
|
-
if (this.canUsePerformanceNow()) {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
return performance.now();
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private canUsePerformanceNow(): boolean {
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
86
|
-
// @ts-ignore
|
|
87
|
-
return global.performance && typeof performance.now === 'function';
|
|
88
|
-
}
|
|
89
|
-
|
|
90
76
|
private checkLabelExists(label: string) {
|
|
91
77
|
if (!this.hasTickFor(label)) {
|
|
92
78
|
throw new Error(`Label ${label} is not registered`);
|
|
93
79
|
}
|
|
94
80
|
}
|
|
95
|
-
|
|
96
81
|
}
|
package/src/TrackingConsent.tsx
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export const InternalLog = {
|
|
8
|
+
log: jest.fn()
|
|
9
|
+
};
|