@datadog/mobile-react-native 3.1.0 → 3.1.2
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/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +20 -43
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +3 -3
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +18 -18
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +18 -125
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -3
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +3 -4
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -1
- package/android/src/test/resources/input/complete-configuration.json +10 -10
- package/ios/Sources/DdLogsImplementation.swift +13 -3
- package/ios/Sources/DdSdkConfiguration.swift +4 -4
- package/ios/Sources/DdSdkNativeInitialization.swift +2 -2
- package/ios/Sources/RNDdSdkConfiguration.swift +9 -8
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/InternalLog.js +9 -7
- package/lib/commonjs/InternalLog.js.map +1 -1
- package/lib/commonjs/logs/DdLogs.js +14 -44
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +25 -3
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -8
- package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/InternalLog.js +9 -6
- package/lib/module/InternalLog.js.map +1 -1
- package/lib/module/logs/DdLogs.js +15 -45
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +25 -3
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -7
- package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/InternalLog.d.ts +6 -4
- package/lib/typescript/InternalLog.d.ts.map +1 -1
- package/lib/typescript/logs/DdLogs.d.ts +0 -5
- package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +9 -0
- package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts.map +1 -1
- package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -5
- package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/InternalLog.tsx +14 -6
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +89 -0
- package/src/logs/DdLogs.ts +25 -58
- package/src/logs/__tests__/DdLogs.test.ts +2 -21
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +3 -3
- package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +25 -3
- package/src/sdk/DatadogProvider/Buffer/BufferSingleton.ts +16 -7
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +13 -0
- package/src/version.ts +1 -1
package/src/logs/DdLogs.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { DdAttributes } from '../DdAttributes';
|
|
8
|
-
import {
|
|
8
|
+
import { InternalLog } from '../InternalLog';
|
|
9
9
|
import { SdkVerbosity } from '../config/types/SdkVerbosity';
|
|
10
10
|
import { debugId } from '../metro/debugIdResolver';
|
|
11
11
|
import type { DdNativeLogsType } from '../nativeModulesTypes';
|
|
12
12
|
import { encodeAttributes } from '../sdk/AttributesEncoding/attributesEncoding';
|
|
13
|
+
import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
|
|
13
14
|
import type { ErrorSource, LogEventMapper } from '../types';
|
|
14
15
|
import { getGlobalInstance } from '../utils/singletonUtils';
|
|
15
16
|
|
|
@@ -23,7 +24,6 @@ import type {
|
|
|
23
24
|
} from './types';
|
|
24
25
|
|
|
25
26
|
const LOGS_MODULE = 'com.datadog.reactnative.logs';
|
|
26
|
-
const SDK_NOT_INITIALIZED_MESSAGE = 'DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT';
|
|
27
27
|
|
|
28
28
|
const generateEmptyPromise = () => new Promise<void>(resolve => resolve());
|
|
29
29
|
|
|
@@ -110,21 +110,6 @@ class DdLogsWrapper implements DdLogsType {
|
|
|
110
110
|
return this.log(args[0], args[1] ?? {}, 'error');
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
/**
|
|
114
|
-
* Since the InternalLog does not have a verbosity set yet in this case,
|
|
115
|
-
* we use console.warn to warn the user in dev mode.
|
|
116
|
-
*/
|
|
117
|
-
private printLogDroppedSdkNotInitialized = (
|
|
118
|
-
message: string,
|
|
119
|
-
status: 'debug' | 'info' | 'warn' | 'error'
|
|
120
|
-
) => {
|
|
121
|
-
if (__DEV__) {
|
|
122
|
-
console.warn(
|
|
123
|
-
`${DATADOG_MESSAGE_PREFIX} Dropping ${status} log as the SDK is not initialized yet: "${message}"`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
113
|
private printLogDroppedByMapper = (
|
|
129
114
|
message: string,
|
|
130
115
|
status: 'debug' | 'info' | 'warn' | 'error'
|
|
@@ -161,21 +146,12 @@ class DdLogsWrapper implements DdLogsType {
|
|
|
161
146
|
}
|
|
162
147
|
|
|
163
148
|
this.printLogTracked(event.message, status);
|
|
164
|
-
|
|
165
|
-
|
|
149
|
+
return bufferVoidNativeCall(() =>
|
|
150
|
+
this.nativeLogs[status](
|
|
166
151
|
event.message,
|
|
167
152
|
encodeAttributes(event.context)
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
171
|
-
// @ts-ignore
|
|
172
|
-
if (error.message === SDK_NOT_INITIALIZED_MESSAGE) {
|
|
173
|
-
this.printLogDroppedSdkNotInitialized(message, status);
|
|
174
|
-
return generateEmptyPromise();
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
153
|
+
)
|
|
154
|
+
);
|
|
179
155
|
};
|
|
180
156
|
|
|
181
157
|
private logWithError = async (
|
|
@@ -207,39 +183,30 @@ class DdLogsWrapper implements DdLogsType {
|
|
|
207
183
|
}
|
|
208
184
|
|
|
209
185
|
this.printLogTracked(mappedEvent.message, status);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
186
|
+
const encodedContext = encodeAttributes(mappedEvent.context);
|
|
187
|
+
const updatedContext = {
|
|
188
|
+
...encodedContext,
|
|
189
|
+
[DdAttributes.errorSourceType]: 'react-native'
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
if (fingerprint && fingerprint !== '') {
|
|
193
|
+
updatedContext[DdAttributes.errorFingerprint] = fingerprint;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const _debugId = debugId;
|
|
197
|
+
if (_debugId) {
|
|
198
|
+
updatedContext[DdAttributes.debugId] = _debugId;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return bufferVoidNativeCall(() =>
|
|
202
|
+
this.nativeLogs[`${status}WithError`](
|
|
227
203
|
mappedEvent.message,
|
|
228
204
|
(mappedEvent as NativeLogWithError).errorKind,
|
|
229
205
|
(mappedEvent as NativeLogWithError).errorMessage,
|
|
230
206
|
(mappedEvent as NativeLogWithError).stacktrace,
|
|
231
207
|
updatedContext
|
|
232
|
-
)
|
|
233
|
-
|
|
234
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
if (error.message === SDK_NOT_INITIALIZED_MESSAGE) {
|
|
237
|
-
this.printLogDroppedSdkNotInitialized(message, status);
|
|
238
|
-
return generateEmptyPromise();
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
208
|
+
)
|
|
209
|
+
);
|
|
243
210
|
};
|
|
244
211
|
|
|
245
212
|
registerLogEventMapper(logEventMapper: LogEventMapper) {
|
|
@@ -12,7 +12,7 @@ import { CoreConfiguration } from '../../config/features/CoreConfiguration';
|
|
|
12
12
|
import { LogsConfiguration } from '../../config/features/LogsConfiguration';
|
|
13
13
|
import { RumConfiguration } from '../../config/features/RumConfiguration';
|
|
14
14
|
import { SdkVerbosity } from '../../config/types';
|
|
15
|
-
import
|
|
15
|
+
import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
16
16
|
import { ErrorSource } from '../../types';
|
|
17
17
|
import type { LogEventMapper, LogEvent } from '../../types';
|
|
18
18
|
import { DdLogs } from '../DdLogs';
|
|
@@ -31,6 +31,7 @@ describe('DdLogs', () => {
|
|
|
31
31
|
beforeEach(() => {
|
|
32
32
|
jest.clearAllMocks();
|
|
33
33
|
DdLogs.unregisterLogEventMapper();
|
|
34
|
+
BufferSingleton.onInitialization();
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it('registers event mapper and maps logs', async () => {
|
|
@@ -477,26 +478,6 @@ describe('DdLogs', () => {
|
|
|
477
478
|
});
|
|
478
479
|
});
|
|
479
480
|
|
|
480
|
-
describe('when SDK is not initialized', () => {
|
|
481
|
-
beforeEach(() => {
|
|
482
|
-
jest.clearAllMocks();
|
|
483
|
-
DdLogs.unregisterLogEventMapper();
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
it('does not crash and warns user', async () => {
|
|
487
|
-
(NativeModules.DdLogs.info as jest.MockedFunction<
|
|
488
|
-
DdNativeLogsType['debug']
|
|
489
|
-
>).mockRejectedValueOnce(
|
|
490
|
-
new Error('DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT')
|
|
491
|
-
);
|
|
492
|
-
const consoleSpy = jest.spyOn(console, 'warn');
|
|
493
|
-
await DdLogs.info('original message', {});
|
|
494
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
495
|
-
'DATADOG: Dropping info log as the SDK is not initialized yet: "original message"'
|
|
496
|
-
);
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
|
|
500
481
|
describe('log context', () => {
|
|
501
482
|
beforeEach(() => {
|
|
502
483
|
jest.clearAllMocks();
|
|
@@ -94,12 +94,12 @@ class BabelInteractionTracking {
|
|
|
94
94
|
? handlerArgs.find(x => typeof x === 'number') || 0
|
|
95
95
|
: 0;
|
|
96
96
|
|
|
97
|
-
// Order:
|
|
97
|
+
// Order: actionName → actionNameAttribute → accessibilityLabel → content
|
|
98
98
|
const selectedContent =
|
|
99
|
-
tryContent() ||
|
|
100
99
|
actionName ||
|
|
101
100
|
Object.values(attrs)[0] ||
|
|
102
|
-
getAccessibilityLabel()
|
|
101
|
+
getAccessibilityLabel() ||
|
|
102
|
+
tryContent();
|
|
103
103
|
|
|
104
104
|
if (!selectedContent) {
|
|
105
105
|
return componentName;
|
|
@@ -48,14 +48,15 @@ export class DdEventsInterceptor implements EventsInterceptor {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
interceptOnPress(...args: any[]): void {
|
|
51
|
-
|
|
51
|
+
const event = this.resolveNativeEvent(args);
|
|
52
|
+
if (event) {
|
|
52
53
|
const currentTime = Date.now();
|
|
53
54
|
const timestampDifference = Math.abs(
|
|
54
55
|
Date.now() - this.debouncingStartedTimestamp
|
|
55
56
|
);
|
|
56
57
|
if (timestampDifference > DEBOUNCE_EVENT_THRESHOLD_IN_MS) {
|
|
57
|
-
const targetNode =
|
|
58
|
-
this.handleTargetEvent(targetNode,
|
|
58
|
+
const targetNode = event._targetInst;
|
|
59
|
+
this.handleTargetEvent(targetNode, event);
|
|
59
60
|
// we add an approximated 1 millisecond for the execution time of the `handleTargetEvent` function
|
|
60
61
|
this.debouncingStartedTimestamp =
|
|
61
62
|
currentTime + HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS;
|
|
@@ -68,6 +69,27 @@ export class DdEventsInterceptor implements EventsInterceptor {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Resolves the native GestureResponderEvent from the onPress arguments.
|
|
74
|
+
*
|
|
75
|
+
* Some third-party libraries (e.g. react-native-ui-lib) wrap the native
|
|
76
|
+
* event inside a props object: `onPress({...componentProps, event})`.
|
|
77
|
+
* This method checks for `_targetInst` on `args[0]` first (standard RN),
|
|
78
|
+
* then falls back to `args[0].event` for the wrapped pattern.
|
|
79
|
+
*/
|
|
80
|
+
private resolveNativeEvent(args: any[]): any | null {
|
|
81
|
+
if (args.length === 0 || !args[0]) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (args[0]._targetInst) {
|
|
85
|
+
return args[0];
|
|
86
|
+
}
|
|
87
|
+
if (args[0].event && args[0].event._targetInst) {
|
|
88
|
+
return args[0].event;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
private handleTargetEvent(targetNode: any, event: unknown) {
|
|
72
94
|
if (targetNode) {
|
|
73
95
|
const resolvedTargetName = this.resolveTargetName(targetNode);
|
|
@@ -4,23 +4,32 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { getGlobalInstance } from '../../../utils/singletonUtils';
|
|
8
|
+
|
|
7
9
|
import { BoundedBuffer } from './BoundedBuffer';
|
|
8
10
|
import type { DatadogBuffer } from './DatadogBuffer';
|
|
9
11
|
import { PassThroughBuffer } from './PassThroughBuffer';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const BUFFER_SINGLETON_MODULE = 'com.datadog.reactnative.buffer_singleton';
|
|
14
|
+
|
|
15
|
+
class _BufferSingleton {
|
|
16
|
+
private bufferInstance: DatadogBuffer = new BoundedBuffer();
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
getInstance = (): DatadogBuffer => {
|
|
15
19
|
return BufferSingleton.bufferInstance;
|
|
16
20
|
};
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
onInitialization = () => {
|
|
23
|
+
this.bufferInstance.drain();
|
|
24
|
+
this.bufferInstance = new PassThroughBuffer();
|
|
21
25
|
};
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
reset = () => {
|
|
24
28
|
BufferSingleton.bufferInstance = new BoundedBuffer();
|
|
25
29
|
};
|
|
26
30
|
}
|
|
31
|
+
|
|
32
|
+
export const BufferSingleton = getGlobalInstance(
|
|
33
|
+
BUFFER_SINGLETON_MODULE,
|
|
34
|
+
() => new _BufferSingleton()
|
|
35
|
+
);
|
|
@@ -8,6 +8,7 @@ import { version as reactNativeVersion } from 'react-native/package.json';
|
|
|
8
8
|
import { NativeModules } from 'react-native';
|
|
9
9
|
|
|
10
10
|
import { InitializationMode } from '../../../config/types';
|
|
11
|
+
import { DdLogs } from '../../../logs/DdLogs';
|
|
11
12
|
import { DdRum } from '../../../rum/DdRum';
|
|
12
13
|
import { PropagatorType, RumActionType } from '../../../rum/types';
|
|
13
14
|
import { DdTrace } from '../../../trace/DdTrace';
|
|
@@ -128,6 +129,10 @@ describe('DatadogProvider', () => {
|
|
|
128
129
|
|
|
129
130
|
it('keeps events in the buffer then executes the buffer once initialization is done', async () => {
|
|
130
131
|
// Given
|
|
132
|
+
await DdLogs.info('fake_info_log');
|
|
133
|
+
await DdLogs.debug('fake_debug_log');
|
|
134
|
+
await DdLogs.warn('fake_wanr_log');
|
|
135
|
+
await DdLogs.error('fake_error_log');
|
|
131
136
|
NativeModules.DdTrace.startSpan.mockReturnValueOnce('good_span_id');
|
|
132
137
|
(nowMock as any).mockReturnValue('good_timestamp');
|
|
133
138
|
await DdRum.addAction(RumActionType.TAP, 'fakeAction');
|
|
@@ -138,6 +143,10 @@ describe('DatadogProvider', () => {
|
|
|
138
143
|
(nowMock as any).mockReturnValue('bad_timestamp');
|
|
139
144
|
|
|
140
145
|
// Then
|
|
146
|
+
expect(NativeModules.DdLogs.info).not.toHaveBeenCalled();
|
|
147
|
+
expect(NativeModules.DdLogs.debug).not.toHaveBeenCalled();
|
|
148
|
+
expect(NativeModules.DdLogs.warn).not.toHaveBeenCalled();
|
|
149
|
+
expect(NativeModules.DdLogs.error).not.toHaveBeenCalled();
|
|
141
150
|
expect(NativeModules.DdRum.addAction).not.toHaveBeenCalled();
|
|
142
151
|
expect(NativeModules.DdTrace.startSpan).not.toHaveBeenCalled();
|
|
143
152
|
expect(NativeModules.DdTrace.finishSpan).not.toHaveBeenCalled();
|
|
@@ -148,6 +157,10 @@ describe('DatadogProvider', () => {
|
|
|
148
157
|
|
|
149
158
|
// Then
|
|
150
159
|
expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
|
|
160
|
+
expect(NativeModules.DdLogs.info).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(NativeModules.DdLogs.debug).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(NativeModules.DdLogs.warn).toHaveBeenCalledTimes(1);
|
|
163
|
+
expect(NativeModules.DdLogs.error).toHaveBeenCalledTimes(1);
|
|
151
164
|
expect(NativeModules.DdRum.addAction).toHaveBeenCalledTimes(1);
|
|
152
165
|
expect(NativeModules.DdTrace.startSpan).toHaveBeenCalledTimes(1);
|
|
153
166
|
expect(NativeModules.DdTrace.startSpan).toHaveBeenLastCalledWith(
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '3.1.
|
|
2
|
+
export const version = '3.1.2';
|