@datadog/mobile-react-native 1.2.0-beta1 → 1.2.0-beta2
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 -2
- package/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +7 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +118 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +23 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +29 -1
- package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +377 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +21 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
- package/datadog-sourcemaps.gradle +85 -28
- package/ios/Sources/Attributes.swift +0 -4
- package/ios/Sources/DdSdk.swift +99 -13
- package/ios/Sources/DdSdkConfiguration.swift +34 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +23 -1
- package/lib/commonjs/DdSdkReactNative.js +24 -25
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +66 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +12 -3
- package/lib/commonjs/errorUtils.js.map +1 -1
- package/lib/commonjs/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/types.js +5 -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 +23 -24
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +64 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +12 -3
- package/lib/module/errorUtils.js.map +1 -1
- package/lib/module/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- package/lib/module/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/types.js +5 -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 +0 -7
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +51 -0
- package/lib/typescript/errorUtils.d.ts +8 -0
- package/lib/typescript/longTasksUtils.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/types.d.ts +15 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/scripts/replace-react-require.js +78 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +9 -1
- package/src/DdSdkReactNative.tsx +31 -34
- package/src/DdSdkReactNativeConfiguration.tsx +66 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +56 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +15 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/errorUtils.ts +11 -3
- package/src/longTasksUtils.ts +30 -0
- package/src/rum/instrumentation/getJsxRuntime.ts +11 -11
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +9 -47
- package/src/types.tsx +10 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 100ms is the lower bound for a noticeable long task event.
|
|
3
|
+
*/
|
|
4
|
+
const MIN_LONG_TASK_THRESHOLD_MS = 100;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 5000ms is considered an Application Not Responding (ANR) event.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_LONG_TASK_THRESHOLD_MS = 5000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Makes sure the long task threshold value is above 100 and below 5000.
|
|
13
|
+
* Also makes sure it is a number, passing `0` if it is `false`, as the React Native
|
|
14
|
+
* bridge cannot handle values with dual types.
|
|
15
|
+
*/
|
|
16
|
+
export const adaptLongTaskThreshold = (
|
|
17
|
+
longTaskThreshold: number | false
|
|
18
|
+
): number => {
|
|
19
|
+
if (!longTaskThreshold) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
if (longTaskThreshold < MIN_LONG_TASK_THRESHOLD_MS) {
|
|
23
|
+
return MIN_LONG_TASK_THRESHOLD_MS;
|
|
24
|
+
}
|
|
25
|
+
if (longTaskThreshold > MAX_LONG_TASK_THRESHOLD_MS) {
|
|
26
|
+
return MAX_LONG_TASK_THRESHOLD_MS;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return longTaskThreshold;
|
|
30
|
+
};
|
|
@@ -7,26 +7,26 @@
|
|
|
7
7
|
export const getJsxRuntime = () => {
|
|
8
8
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
9
9
|
const [major, minor] = require('react/package.json').version.split('.');
|
|
10
|
-
// We need to check on the version of React before
|
|
10
|
+
// We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
11
11
|
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
12
12
|
// See: https://github.com/facebook/metro/issues/836
|
|
13
13
|
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
14
14
|
throw new Error('React version does not support new jsx transform');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
|
-
const jsxRuntime = require(
|
|
17
|
+
// /!\/!\/!\/!\/!\/!\
|
|
18
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
19
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
20
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
21
|
+
// disable all further imports.
|
|
22
|
+
// /!\/!\/!\/!\/!\/!\
|
|
23
|
+
//
|
|
24
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
26
26
|
if (!jsxRuntime.jsx) {
|
|
27
27
|
throw new Error('React jsx runtime does not export new jsx transform');
|
|
28
28
|
}
|
|
29
|
-
return jsxRuntime
|
|
29
|
+
return jsxRuntime;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -13,6 +13,7 @@ export type DdRumResourceTracingAttributes =
|
|
|
13
13
|
traceId: string;
|
|
14
14
|
spanId: string;
|
|
15
15
|
samplingPriorityHeader: '1';
|
|
16
|
+
rulePsr: number;
|
|
16
17
|
}
|
|
17
18
|
| {
|
|
18
19
|
tracingStrategy: 'DISCARD';
|
|
@@ -52,7 +53,8 @@ const generateTracingAttributesWithSampling = (
|
|
|
52
53
|
traceId: generateTraceId(),
|
|
53
54
|
spanId: generateTraceId(),
|
|
54
55
|
samplingPriorityHeader: '1',
|
|
55
|
-
tracingStrategy: 'KEEP'
|
|
56
|
+
tracingStrategy: 'KEEP',
|
|
57
|
+
rulePsr: tracingSamplingRate / 100
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
return DISCARDED_TRACE_ATTRIBUTES;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type { ResourceKind } from '
|
|
7
|
+
import type { ResourceKind } from '../../../../../../src/types';
|
|
8
8
|
import type { DdRumResourceTracingAttributes } from '../distributedTracing';
|
|
9
9
|
|
|
10
10
|
export interface RUMResource {
|
|
@@ -419,7 +419,7 @@ describe('XHRPr', () => {
|
|
|
419
419
|
});
|
|
420
420
|
|
|
421
421
|
describe('DdRum.startResource calls', () => {
|
|
422
|
-
it('adds the span id as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
422
|
+
it('adds the span id, trace id and rule_psr as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
423
423
|
// GIVEN
|
|
424
424
|
const method = 'GET';
|
|
425
425
|
const url = 'https://api.example.com/v2/user';
|
|
@@ -442,58 +442,18 @@ describe('XHRPr', () => {
|
|
|
442
442
|
const spanId = DdRum.startResource.mock.calls[0][3]['_dd.span_id'];
|
|
443
443
|
expect(spanId).toBeDefined();
|
|
444
444
|
expect(spanId).toMatch(/[1-9].+/);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it('adds the trace id as resource attributes when startTracking() + XHR.open() + XHR.send()', async () => {
|
|
448
|
-
// GIVEN
|
|
449
|
-
const method = 'GET';
|
|
450
|
-
const url = 'https://api.example.com/v2/user';
|
|
451
|
-
xhrProxy.onTrackingStart({
|
|
452
|
-
tracingSamplingRate: 100,
|
|
453
|
-
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
454
|
-
'api.example.com'
|
|
455
|
-
])
|
|
456
|
-
});
|
|
457
445
|
|
|
458
|
-
// WHEN
|
|
459
|
-
const xhr = new XMLHttpRequestMock();
|
|
460
|
-
xhr.open(method, url);
|
|
461
|
-
xhr.send();
|
|
462
|
-
xhr.notifyResponseArrived();
|
|
463
|
-
xhr.complete(200, 'ok');
|
|
464
|
-
await flushPromises();
|
|
465
|
-
|
|
466
|
-
// THEN
|
|
467
446
|
const traceId =
|
|
468
447
|
DdRum.startResource.mock.calls[0][3]['_dd.trace_id'];
|
|
469
448
|
expect(traceId).toBeDefined();
|
|
470
449
|
expect(traceId).toMatch(/[1-9].+/);
|
|
471
|
-
});
|
|
472
450
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const url = 'https://api.example.com/v2/user';
|
|
477
|
-
xhrProxy.onTrackingStart({
|
|
478
|
-
tracingSamplingRate: 100,
|
|
479
|
-
firstPartyHostsRegex: firstPartyHostsRegexBuilder([
|
|
480
|
-
'api.example.com'
|
|
481
|
-
])
|
|
482
|
-
});
|
|
451
|
+
const rulePsr =
|
|
452
|
+
DdRum.startResource.mock.calls[0][3]['_dd.rule_psr'];
|
|
453
|
+
expect(rulePsr).toBe(1);
|
|
483
454
|
|
|
484
|
-
//
|
|
485
|
-
|
|
486
|
-
xhr.open(method, url);
|
|
487
|
-
xhr.send();
|
|
488
|
-
xhr.notifyResponseArrived();
|
|
489
|
-
xhr.complete(200, 'ok');
|
|
490
|
-
await flushPromises();
|
|
491
|
-
|
|
492
|
-
// THEN
|
|
493
|
-
const traceId =
|
|
494
|
-
DdRum.startResource.mock.calls[0][3]['_dd.trace_id'];
|
|
495
|
-
const spanId = DdRum.startResource.mock.calls[0][3]['_dd.span_id'];
|
|
496
|
-
expect(traceId !== spanId).toBeTruthy();
|
|
455
|
+
// Check traceId and spanId are different
|
|
456
|
+
expect(traceId).not.toBe(spanId);
|
|
497
457
|
});
|
|
498
458
|
|
|
499
459
|
it('does not generate spanId and traceId when tracing is disabled', async () => {
|
|
@@ -523,10 +483,12 @@ describe('XHRPr', () => {
|
|
|
523
483
|
expect.anything(),
|
|
524
484
|
expect.objectContaining({
|
|
525
485
|
'_dd.trace_id': expect.any(String),
|
|
526
|
-
'_dd.span_id': expect.any(String)
|
|
486
|
+
'_dd.span_id': expect.any(String),
|
|
487
|
+
'_dd.rule_psr': expect.any(Number)
|
|
527
488
|
}),
|
|
528
489
|
expect.anything()
|
|
529
490
|
);
|
|
491
|
+
expect(DdRum.startResource.mock.calls[0][3]).toStrictEqual({});
|
|
530
492
|
});
|
|
531
493
|
});
|
|
532
494
|
|
package/src/types.tsx
CHANGED
|
@@ -13,11 +13,20 @@ export class DdSdkConfiguration {
|
|
|
13
13
|
readonly env: string,
|
|
14
14
|
readonly applicationId: string,
|
|
15
15
|
readonly nativeCrashReportEnabled: boolean,
|
|
16
|
+
readonly nativeLongTaskThresholdMs: number,
|
|
17
|
+
readonly longTaskThresholdMs: number,
|
|
16
18
|
readonly sampleRate: number,
|
|
17
19
|
readonly site: string,
|
|
18
20
|
readonly trackingConsent: string,
|
|
19
21
|
readonly additionalConfig: object,
|
|
20
|
-
readonly telemetrySampleRate: number
|
|
22
|
+
readonly telemetrySampleRate: number,
|
|
23
|
+
readonly vitalsUpdateFrequency: string,
|
|
24
|
+
readonly configurationForTelemetry: {
|
|
25
|
+
initializationType: string;
|
|
26
|
+
trackErrors: boolean;
|
|
27
|
+
trackInteractions: boolean;
|
|
28
|
+
trackNetworkRequests: boolean;
|
|
29
|
+
}
|
|
21
30
|
) {}
|
|
22
31
|
}
|
|
23
32
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.2.0-
|
|
2
|
+
export const version = '1.2.0-beta2';
|