@datadog/mobile-react-native 3.9.0 → 3.11.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.
Files changed (144) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +9 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +6 -3
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +10 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +16 -8
  6. package/android/src/main/kotlin/com/datadog/reactnative/FrameRateProvider.kt +11 -6
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  9. package/android/src/oldarchCommon/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  10. package/android/src/test/kotlin/com/datadog/reactnative/DdFlagsImplementationTest.kt +19 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +9 -0
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +131 -0
  13. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -3
  14. package/datadog-configuration.schema.json +11 -0
  15. package/ios/Sources/DdRum.mm +13 -1
  16. package/ios/Sources/DdRumImplementation.swift +6 -0
  17. package/ios/Sources/DdSdkConfiguration.swift +13 -0
  18. package/ios/Sources/DdSdkImplementation.swift +4 -3
  19. package/ios/Sources/DdSdkNativeInitialization.swift +26 -8
  20. package/ios/Sources/JSRefreshRateListener.swift +6 -2
  21. package/ios/Sources/RNDdSdkConfiguration.swift +9 -0
  22. package/ios/Sources/SdkVersion.swift +1 -1
  23. package/jest/mock.js +3 -0
  24. package/lib/commonjs/DdSdkReactNative.js +1 -1
  25. package/lib/commonjs/config/FileBasedConfiguration.js +3 -1
  26. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  27. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +3 -0
  28. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  29. package/lib/commonjs/config/features/RumConfiguration.js +8 -0
  30. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  31. package/lib/commonjs/flags/FlagsClient.js +81 -8
  32. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  33. package/lib/commonjs/flags/configuration/precomputed.js +2 -3
  34. package/lib/commonjs/flags/configuration/precomputed.js.map +1 -1
  35. package/lib/commonjs/flags/internal.js.map +1 -1
  36. package/lib/commonjs/rum/DdRum.js +4 -0
  37. package/lib/commonjs/rum/DdRum.js.map +1 -1
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +2 -2
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +1 -1
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +7 -1
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  44. package/lib/commonjs/rum/types.js.map +1 -1
  45. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js +1 -0
  46. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  47. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +1 -0
  48. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  49. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  50. package/lib/commonjs/version.js +1 -1
  51. package/lib/commonjs/version.js.map +1 -1
  52. package/lib/module/DdSdkReactNative.js +1 -1
  53. package/lib/module/config/FileBasedConfiguration.js +3 -1
  54. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  55. package/lib/module/config/async/AutoInstrumentationConfiguration.js +3 -0
  56. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  57. package/lib/module/config/features/RumConfiguration.js +8 -0
  58. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  59. package/lib/module/flags/FlagsClient.js +81 -8
  60. package/lib/module/flags/FlagsClient.js.map +1 -1
  61. package/lib/module/flags/configuration/precomputed.js +2 -3
  62. package/lib/module/flags/configuration/precomputed.js.map +1 -1
  63. package/lib/module/flags/internal.js.map +1 -1
  64. package/lib/module/rum/DdRum.js +4 -0
  65. package/lib/module/rum/DdRum.js.map +1 -1
  66. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +3 -3
  67. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  68. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
  69. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  70. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +5 -0
  71. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  72. package/lib/module/rum/types.js.map +1 -1
  73. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js +2 -1
  74. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  75. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +2 -1
  76. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  77. package/lib/module/specs/NativeDdRum.js.map +1 -1
  78. package/lib/module/version.js +1 -1
  79. package/lib/module/version.js.map +1 -1
  80. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  81. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
  82. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  83. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +4 -0
  84. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  85. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +2 -0
  86. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  87. package/lib/typescript/config/features/RumConfiguration.d.ts +4 -0
  88. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  89. package/lib/typescript/config/features/RumConfiguration.type.d.ts +21 -0
  90. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  91. package/lib/typescript/config/features/RumConfigurationNative.d.ts +2 -0
  92. package/lib/typescript/config/features/RumConfigurationNative.d.ts.map +1 -1
  93. package/lib/typescript/flags/FlagsClient.d.ts +38 -1
  94. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  95. package/lib/typescript/flags/internal.d.ts +1 -0
  96. package/lib/typescript/flags/internal.d.ts.map +1 -1
  97. package/lib/typescript/flags/types.d.ts +1 -1
  98. package/lib/typescript/flags/types.d.ts.map +1 -1
  99. package/lib/typescript/rum/DdRum.d.ts +1 -0
  100. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  101. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  102. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  103. package/lib/typescript/rum/types.d.ts +6 -0
  104. package/lib/typescript/rum/types.d.ts.map +1 -1
  105. package/lib/typescript/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -1
  106. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
  107. package/lib/typescript/specs/NativeDdRum.d.ts +6 -0
  108. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  109. package/lib/typescript/version.d.ts +1 -1
  110. package/lib/typescript/version.d.ts.map +1 -1
  111. package/package.json +2 -2
  112. package/src/DdSdkReactNative.tsx +1 -1
  113. package/src/__tests__/DdSdkReactNative.test.tsx +133 -0
  114. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +12 -0
  115. package/src/config/FileBasedConfiguration.ts +6 -1
  116. package/src/config/FileBasedConfiguration.type.ts +2 -0
  117. package/src/config/__tests__/FileBasedConfiguration.test.ts +79 -0
  118. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +2 -0
  119. package/src/config/async/AutoInstrumentationConfiguration.ts +9 -0
  120. package/src/config/async/PartialInitializationConfiguration.ts +2 -0
  121. package/src/config/features/RumConfiguration.ts +10 -0
  122. package/src/config/features/RumConfiguration.type.ts +23 -0
  123. package/src/config/features/RumConfigurationNative.ts +2 -0
  124. package/src/flags/FlagsClient.ts +128 -19
  125. package/src/flags/__tests__/FlagsClient.test.ts +167 -0
  126. package/src/flags/configuration/precomputed.ts +2 -3
  127. package/src/flags/internal.ts +2 -0
  128. package/src/flags/types.ts +2 -0
  129. package/src/rum/DdRum.ts +10 -0
  130. package/src/rum/__tests__/DdRum.test.ts +10 -0
  131. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +104 -1
  132. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +3 -3
  133. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +29 -0
  134. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
  135. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +40 -0
  136. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +9 -0
  137. package/src/rum/types.ts +7 -0
  138. package/src/sdk/AccountInfoSingleton/AccountInfoSingleton.ts +2 -1
  139. package/src/sdk/AccountInfoSingleton/__tests__/AccountInfoSingleton.test.ts +59 -0
  140. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +165 -0
  141. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +2 -1
  142. package/src/sdk/UserInfoSingleton/__tests__/UserInfoSingleton.test.ts +55 -0
  143. package/src/specs/NativeDdRum.ts +7 -0
  144. package/src/version.ts +1 -1
@@ -19,6 +19,8 @@ export interface FlagCacheEntry {
19
19
  reason: string;
20
20
  doLog: boolean;
21
21
  extraLogging: Record<string, unknown>;
22
+ // Native Android carries split serial IDs as strings across the React Native bridge.
23
+ serialId?: string;
22
24
  }
23
25
 
24
26
  export const processEvaluationContext = (
@@ -167,6 +167,8 @@ export interface EvaluationContext {
167
167
  */
168
168
  type FlagErrorCode =
169
169
  | 'PROVIDER_NOT_READY'
170
+ | 'PROVIDER_FATAL'
171
+ | 'TARGETING_KEY_MISSING'
170
172
  | 'FLAG_NOT_FOUND'
171
173
  | 'PARSE_ERROR'
172
174
  | 'TYPE_MISMATCH'
package/src/rum/DdRum.ts CHANGED
@@ -427,6 +427,16 @@ class DdRumWrapper implements DdRumType {
427
427
  );
428
428
  };
429
429
 
430
+ reportAppFullyDisplayed = (): Promise<void> => {
431
+ InternalLog.log(
432
+ 'Reporting App Fully Displayed (TTFD)',
433
+ SdkVerbosity.DEBUG
434
+ );
435
+ return bufferVoidNativeCall(() =>
436
+ this.nativeRum.reportAppFullyDisplayed()
437
+ );
438
+ };
439
+
430
440
  stopSession = (): Promise<void> => {
431
441
  InternalLog.log('Stopping RUM Session', SdkVerbosity.DEBUG);
432
442
  clearCachedSessionId();
@@ -1884,6 +1884,16 @@ describe('DdRum', () => {
1884
1884
  });
1885
1885
  });
1886
1886
 
1887
+ describe('DdRum.reportAppFullyDisplayed', () => {
1888
+ it('calls the native API', async () => {
1889
+ await DdRum.reportAppFullyDisplayed();
1890
+
1891
+ expect(
1892
+ NativeModules.DdRum.reportAppFullyDisplayed
1893
+ ).toHaveBeenCalledTimes(1);
1894
+ });
1895
+ });
1896
+
1887
1897
  describe('PropagatorTypes', () => {
1888
1898
  it('matches with the native name of propagators', () => {
1889
1899
  /**
@@ -69,7 +69,10 @@ describe('DdBabelInteractionTracking.wrapRumAction', () => {
69
69
 
70
70
  it('should forward the first handler argument as actionContext to DdRum.addAction', () => {
71
71
  const mockAddAction = jest.fn().mockResolvedValue(undefined);
72
- DdBabelInteractionTracking.config = { trackInteractions: true };
72
+ DdBabelInteractionTracking.config = {
73
+ trackInteractions: true,
74
+ useAccessibilityLabel: true
75
+ };
73
76
  DdBabelInteractionTracking.attachRumInstance({
74
77
  addAction: mockAddAction
75
78
  } as any);
@@ -94,4 +97,104 @@ describe('DdBabelInteractionTracking.wrapRumAction', () => {
94
97
  event
95
98
  );
96
99
  });
100
+
101
+ describe('action naming precedence', () => {
102
+ const mockAddAction = jest.fn().mockResolvedValue(undefined);
103
+ const originalConfig = DdBabelInteractionTracking.config;
104
+
105
+ beforeEach(() => {
106
+ mockAddAction.mockClear();
107
+ DdBabelInteractionTracking.attachRumInstance({
108
+ addAction: mockAddAction
109
+ } as any);
110
+ });
111
+
112
+ afterEach(() => {
113
+ DdBabelInteractionTracking.config = originalConfig;
114
+ });
115
+
116
+ describe.each([true, false])(
117
+ 'useAccessibilityLabel=%s',
118
+ useAccessibilityLabel => {
119
+ it.each([
120
+ {
121
+ source:
122
+ 'dd-action-name over custom attribute, accessibility label and content',
123
+ attributes: {
124
+ 'dd-action-name': ['Explicit'],
125
+ customName: ['Custom'],
126
+ accessibilityLabel: ['Accessible']
127
+ },
128
+ content: ['Content'],
129
+ expected: 'Pressable ("Explicit")'
130
+ },
131
+ {
132
+ source:
133
+ 'custom attribute over accessibility label and content',
134
+ attributes: {
135
+ customName: ['Custom'],
136
+ accessibilityLabel: ['Accessible']
137
+ },
138
+ content: ['Content'],
139
+ expected: 'Pressable ("Custom")'
140
+ },
141
+ {
142
+ source:
143
+ 'accessibility label or content according to configuration',
144
+ attributes: { accessibilityLabel: ['Accessible'] },
145
+ content: ['Content'],
146
+ expected: useAccessibilityLabel
147
+ ? 'Pressable ("Accessible")'
148
+ : 'Pressable ("Content")'
149
+ },
150
+ {
151
+ source:
152
+ 'accessibility label or component name when there is no content',
153
+ attributes: { accessibilityLabel: ['Edit'] },
154
+ content: [],
155
+ expected: useAccessibilityLabel
156
+ ? 'Pressable ("Edit")'
157
+ : 'Pressable'
158
+ },
159
+ {
160
+ source: 'content when there are no naming attributes',
161
+ attributes: {},
162
+ content: ['Content'],
163
+ expected: 'Pressable ("Content")'
164
+ },
165
+ {
166
+ source:
167
+ 'component name when there are no naming attributes or content',
168
+ attributes: {},
169
+ content: [],
170
+ expected: 'Pressable'
171
+ }
172
+ ])('uses $source', ({ attributes, content, expected }) => {
173
+ DdBabelInteractionTracking.config = {
174
+ trackInteractions: true,
175
+ useAccessibilityLabel
176
+ };
177
+ const wrapped = DdBabelInteractionTracking.wrapRumAction(
178
+ jest.fn(),
179
+ RumActionType.TAP,
180
+ {
181
+ options: {
182
+ useContent: true,
183
+ useNamePrefix: true
184
+ },
185
+ handlerArgs: [],
186
+ componentName: 'Pressable',
187
+ getContent: () => content,
188
+ ...attributes
189
+ } as any
190
+ );
191
+
192
+ wrapped();
193
+
194
+ expect(mockAddAction).toHaveBeenCalledTimes(1);
195
+ expect(mockAddAction.mock.calls[0][1]).toBe(expected);
196
+ });
197
+ }
198
+ );
199
+ });
97
200
  });
@@ -10,7 +10,7 @@ import { extractGraphQLErrors } from '../../graphql/graphqlUtils';
10
10
  import { getErrorData } from '../XHRProxy/xhrUtils';
11
11
  import { callOriginalFetch } from '../common/FetchProxyState';
12
12
  import type { RequestContext } from '../common/RequestContext';
13
- import { createRequestContext } from '../common/RequestContext';
13
+ import { createRequestContext, getResourceKey } from '../common/RequestContext';
14
14
  import { ResourceReporter } from '../common/ResourceReporter';
15
15
  import { filterDevResource } from '../common/internalDevResourceBlocklist';
16
16
  import {
@@ -259,7 +259,7 @@ const reportFetch = async ({
259
259
  }
260
260
 
261
261
  resourceReporter.reportResource({
262
- key: `${context.timer.startTime}/${context.method}`,
262
+ key: getResourceKey(context),
263
263
  request: {
264
264
  method: context.method,
265
265
  url: context.url,
@@ -287,7 +287,7 @@ const reportFetchFailure = ({
287
287
  resourceReporter: ResourceReporter;
288
288
  }) => {
289
289
  resourceReporter.reportResource({
290
- key: `${context.timer.startTime}/${context.method}`,
290
+ key: getResourceKey(context),
291
291
  request: {
292
292
  method: context.method,
293
293
  url: context.url,
@@ -157,6 +157,35 @@ describe('FetchProxy', () => {
157
157
  expect(outgoingHeaders.get(PARENT_ID_HEADER_KEY)).not.toBeNull();
158
158
  });
159
159
 
160
+ it('reports distinct keys for same-method requests started in the same millisecond', async () => {
161
+ const now = Date.now();
162
+ const dateNowSpy = jest.spyOn(Date, 'now').mockReturnValue(now);
163
+ const originalFetch = jest
164
+ .fn()
165
+ .mockResolvedValue(createResponse()) as jest.MockedFunction<
166
+ typeof fetch
167
+ >;
168
+ const reportResource = jest.fn();
169
+ const { fetchGlobal, proxy } = createProxy({
170
+ originalFetch,
171
+ reportResource
172
+ });
173
+ proxy.onTrackingStart(getOptions());
174
+
175
+ await Promise.all([
176
+ fetchGlobal.fetch('https://api.example.com/users'),
177
+ fetchGlobal.fetch('https://api.example.com/settings')
178
+ ]);
179
+ dateNowSpy.mockRestore();
180
+
181
+ expect(reportResource).toHaveBeenCalledTimes(2);
182
+ const [first, second] = reportResource.mock.calls.map(
183
+ call => call[0] as RUMResource
184
+ );
185
+ expect(first.timings.startTime).toBe(second.timings.startTime);
186
+ expect(first.key).not.toBe(second.key);
187
+ });
188
+
160
189
  it('extracts GraphQL metadata and removes its internal header', async () => {
161
190
  const originalFetch = jest
162
191
  .fn()
@@ -9,7 +9,7 @@ import { SdkVerbosity } from '../../../../../config/types';
9
9
  import { extractGraphQLErrors } from '../../graphql/graphqlUtils';
10
10
  import { isRunningWithinFetchProxy } from '../common/FetchProxyState';
11
11
  import type { RequestContext } from '../common/RequestContext';
12
- import { createRequestContext } from '../common/RequestContext';
12
+ import { createRequestContext, getResourceKey } from '../common/RequestContext';
13
13
  import { ResourceReporter } from '../common/ResourceReporter';
14
14
  import { filterDevResource } from '../common/internalDevResourceBlocklist';
15
15
  import {
@@ -189,7 +189,7 @@ const reportXhr = async (
189
189
  return;
190
190
  }
191
191
 
192
- const key = `${context.timer.startTime}/${context.method}`;
192
+ const key = getResourceKey(context);
193
193
 
194
194
  context.timer.stop();
195
195
 
@@ -145,6 +145,46 @@ describe('XHRProxy', () => {
145
145
  expect(xhr.originalOnReadyStateChangeCalled).toBe(true);
146
146
  });
147
147
 
148
+ it('reports distinct resources for same-method XHR requests started in the same millisecond', async () => {
149
+ // GIVEN
150
+ const now = Date.now();
151
+ (Date.now as jest.MockedFunction<
152
+ typeof Date.now
153
+ >).mockImplementation(() => now);
154
+ xhrProxy.onTrackingStart({
155
+ tracingSamplingRate: 100,
156
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([])
157
+ });
158
+
159
+ // WHEN
160
+ const xhr1 = new XMLHttpRequestMock();
161
+ const xhr2 = new XMLHttpRequestMock();
162
+ xhr1.open('GET', 'https://api.example.com/v2/user');
163
+ xhr2.open('GET', 'https://api.example.com/v2/settings');
164
+ xhr1.send();
165
+ xhr2.send();
166
+ xhr1.notifyResponseArrived();
167
+ xhr2.notifyResponseArrived();
168
+ xhr1.complete(200, 'ok');
169
+ xhr2.complete(200, 'ok');
170
+ await flushPromises();
171
+
172
+ // THEN
173
+ expect(DdNativeRum.startResource.mock.calls.length).toBe(2);
174
+ expect(DdNativeRum.startResource.mock.calls[0][4]).toBe(
175
+ DdNativeRum.startResource.mock.calls[1][4]
176
+ );
177
+ expect(DdNativeRum.startResource.mock.calls[0][0]).not.toBe(
178
+ DdNativeRum.startResource.mock.calls[1][0]
179
+ );
180
+ expect(DdNativeRum.stopResource.mock.calls.length).toBe(2);
181
+ expect(
182
+ DdNativeRum.stopResource.mock.calls.map(call => call[0]).sort()
183
+ ).toEqual(
184
+ DdNativeRum.startResource.mock.calls.map(call => call[0]).sort()
185
+ );
186
+ });
187
+
148
188
  it('intercepts failing XHR request when startTracking() + XHR.open() + XHR.send()', async () => {
149
189
  // GIVEN
150
190
  const method = 'GET';
@@ -17,6 +17,7 @@ import type { RequestProxyOptions } from '../interfaces/RequestProxy';
17
17
  import type { DdRumResourceGraphqlAttributes } from '../interfaces/RumResource';
18
18
 
19
19
  export interface RequestContext {
20
+ resourceId: number;
20
21
  graphql: DdRumResourceGraphqlAttributes & {
21
22
  trackErrors?: boolean;
22
23
  };
@@ -27,6 +28,10 @@ export interface RequestContext {
27
28
  baggageHeaderEntries: Set<string>;
28
29
  }
29
30
 
31
+ // Disambiguates resources sharing the same start millisecond and method,
32
+ // which would otherwise collide on the native side.
33
+ let resourceSequence = 0;
34
+
30
35
  export const createRequestContext = ({
31
36
  method,
32
37
  url,
@@ -37,6 +42,7 @@ export const createRequestContext = ({
37
42
  options: RequestProxyOptions;
38
43
  }): RequestContext => {
39
44
  return {
45
+ resourceId: ++resourceSequence,
40
46
  method,
41
47
  url,
42
48
  timer: new Timer(),
@@ -52,3 +58,6 @@ export const createRequestContext = ({
52
58
  baggageHeaderEntries: new Set<string>()
53
59
  };
54
60
  };
61
+
62
+ export const getResourceKey = (context: RequestContext): string =>
63
+ `${context.timer.startTime}/${context.method}/${context.resourceId}`;
package/src/rum/types.ts CHANGED
@@ -181,6 +181,13 @@ export type DdRumType = {
181
181
  */
182
182
  addViewLoadingTime(overwrite: boolean): Promise<void>;
183
183
 
184
+ /**
185
+ * This method can be used to mark the moment in time when the UI of the app is considered fully displayed.
186
+ * The duration between the application launch and this moment of time will be shown as TTFD (time to full display)
187
+ * in the RUM session explorer. Only the first call to this method will have any effect for a given RUM session.
188
+ */
189
+ reportAppFullyDisplayed(): Promise<void>;
190
+
184
191
  /**
185
192
  * Stops the current RUM Session.
186
193
  */
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { setCachedAccountId } from '../../rum/helper';
7
+ import { clearCachedAccountId, setCachedAccountId } from '../../rum/helper';
8
8
 
9
9
  import type { AccountInfo } from './types';
10
10
 
@@ -33,6 +33,7 @@ class AccountInfoProvider {
33
33
 
34
34
  clearAccountInfo = () => {
35
35
  this.accountInfo = undefined;
36
+ clearCachedAccountId();
36
37
  };
37
38
  }
38
39
 
@@ -4,11 +4,49 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import {
8
+ clearCachedAccountId,
9
+ clearCachedSessionId,
10
+ clearCachedUserId,
11
+ getCachedAccountId
12
+ } from '../../../rum/helper';
13
+ import { firstPartyHostsRegexMapBuilder } from '../../../rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts';
14
+ import { DATADOG_BAGGAGE_HEADER } from '../../../rum/instrumentation/resourceTracking/headers';
15
+ import { createRequestContext } from '../../../rum/instrumentation/resourceTracking/requestProxy/common/RequestContext';
16
+ import { getInstrumentationHeaders } from '../../../rum/instrumentation/resourceTracking/requestProxy/common/requestHeaders';
17
+ import { PropagatorType } from '../../../rum/types';
7
18
  import { AccountInfoSingleton } from '../AccountInfoSingleton';
8
19
 
20
+ const firstPartyRequestOptions = {
21
+ tracingSamplingRate: 100,
22
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([
23
+ {
24
+ match: 'api.example.com',
25
+ propagatorTypes: [
26
+ PropagatorType.DATADOG,
27
+ PropagatorType.TRACECONTEXT
28
+ ]
29
+ }
30
+ ])
31
+ };
32
+
33
+ const getBaggageHeader = (): string | undefined => {
34
+ const context = createRequestContext({
35
+ method: 'GET',
36
+ url: 'https://api.example.com/v1/resource',
37
+ options: firstPartyRequestOptions
38
+ });
39
+ return getInstrumentationHeaders(context).find(
40
+ header => header.header === DATADOG_BAGGAGE_HEADER
41
+ )?.value;
42
+ };
43
+
9
44
  describe('AccountInfoSingleton', () => {
10
45
  beforeEach(() => {
11
46
  AccountInfoSingleton.reset();
47
+ clearCachedSessionId();
48
+ clearCachedUserId();
49
+ clearCachedAccountId();
12
50
  });
13
51
 
14
52
  it('returns undefined by default', () => {
@@ -87,4 +125,25 @@ describe('AccountInfoSingleton', () => {
87
125
 
88
126
  expect(a).toBe(b);
89
127
  });
128
+
129
+ it('clears the cached account id used by RequestContext baggage after clearAccountInfo', () => {
130
+ const accountId = 'previous-account';
131
+ AccountInfoSingleton.getInstance().setAccountInfo({
132
+ id: accountId,
133
+ extraInfo: {}
134
+ });
135
+
136
+ expect(getCachedAccountId()).toBe(accountId);
137
+ expect(getBaggageHeader()).toBe(`account.id=${accountId}`);
138
+
139
+ AccountInfoSingleton.getInstance().clearAccountInfo();
140
+
141
+ expect(
142
+ AccountInfoSingleton.getInstance().getAccountInfo()
143
+ ).toBeUndefined();
144
+ expect(getCachedAccountId()).toBeUndefined();
145
+ expect(getBaggageHeader() ?? '').not.toContain(
146
+ `account.id=${accountId}`
147
+ );
148
+ });
90
149
  });
@@ -96,6 +96,8 @@ describe('DatadogProvider', () => {
96
96
  "longTaskThresholdMs": 0,
97
97
  "nativeCrashReportEnabled": false,
98
98
  "nativeInteractionTracking": false,
99
+ "nativeIosResourceTracking": undefined,
100
+ "nativeIosResourceTrackingDisallowList": undefined,
99
101
  "nativeLongTaskThresholdMs": 200,
100
102
  "nativeViewTracking": false,
101
103
  "resourceEventMapper": null,
@@ -178,6 +180,169 @@ describe('DatadogProvider', () => {
178
180
  });
179
181
  });
180
182
 
183
+ describe('nativeIosResourceTracking', () => {
184
+ it('sends nativeIosResourceTracking undefined to native by default', async () => {
185
+ renderWithProvider();
186
+ await flushPromises();
187
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
188
+ const receivedConfiguration =
189
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
190
+ expect(receivedConfiguration.rumConfiguration).toBeDefined();
191
+ expect(
192
+ receivedConfiguration.rumConfiguration.nativeIosResourceTracking
193
+ ).toBeUndefined();
194
+ });
195
+
196
+ it.each([true, false])(
197
+ 'sends nativeIosResourceTracking %s to native when set',
198
+ async value => {
199
+ const configuration = getDefaultConfiguration();
200
+ const rumConfiguration = configuration.rumConfiguration;
201
+ if (rumConfiguration) {
202
+ rumConfiguration.nativeIosResourceTracking = value;
203
+ }
204
+ renderWithProvider({ configuration });
205
+ await flushPromises();
206
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
207
+ const receivedConfiguration =
208
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
209
+ expect(
210
+ receivedConfiguration.rumConfiguration
211
+ .nativeIosResourceTracking
212
+ ).toBe(value);
213
+ }
214
+ );
215
+
216
+ it.each([
217
+ [undefined, undefined, undefined],
218
+ [true, undefined, true],
219
+ [false, undefined, false],
220
+ [undefined, true, true],
221
+ [undefined, false, false]
222
+ ])(
223
+ 'partial initialization: features %s, initialize %s => native %s',
224
+ async (featuresValue, initializeValue, expected) => {
225
+ renderWithProvider({
226
+ configuration: {
227
+ rumConfiguration: {
228
+ trackErrors: false,
229
+ trackResources: false,
230
+ trackInteractions: false,
231
+ ...(featuresValue !== undefined && {
232
+ nativeIosResourceTracking: featuresValue
233
+ })
234
+ },
235
+ traceConfiguration: {},
236
+ logsConfiguration: {}
237
+ }
238
+ });
239
+ await flushPromises();
240
+ expect(NativeModules.DdSdk.initialize).not.toHaveBeenCalled();
241
+
242
+ await DatadogProvider.initialize({
243
+ clientToken: 'fake-client-token',
244
+ env: 'fake-env',
245
+ rumConfiguration: {
246
+ applicationId: 'fake-application-id',
247
+ ...(initializeValue !== undefined && {
248
+ nativeIosResourceTracking: initializeValue
249
+ })
250
+ }
251
+ });
252
+ await flushPromises();
253
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
254
+ const receivedConfiguration =
255
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
256
+ expect(
257
+ receivedConfiguration.rumConfiguration
258
+ .nativeIosResourceTracking
259
+ ).toBe(expected);
260
+ }
261
+ );
262
+ });
263
+
264
+ describe('nativeIosResourceTrackingDisallowList', () => {
265
+ const disallowList = [
266
+ 'https://3p.example.com/*',
267
+ 'https://cdn.example.com/a'
268
+ ];
269
+
270
+ it('sends nativeIosResourceTrackingDisallowList undefined to native by default', async () => {
271
+ renderWithProvider();
272
+ await flushPromises();
273
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
274
+ const receivedConfiguration =
275
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
276
+ expect(receivedConfiguration.rumConfiguration).toBeDefined();
277
+ expect(
278
+ receivedConfiguration.rumConfiguration
279
+ .nativeIosResourceTrackingDisallowList
280
+ ).toBeUndefined();
281
+ });
282
+
283
+ it('sends nativeIosResourceTrackingDisallowList to native when set', async () => {
284
+ const configuration = getDefaultConfiguration();
285
+ const rumConfiguration = configuration.rumConfiguration;
286
+ if (rumConfiguration) {
287
+ rumConfiguration.nativeIosResourceTrackingDisallowList = disallowList;
288
+ }
289
+ renderWithProvider({ configuration });
290
+ await flushPromises();
291
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
292
+ const receivedConfiguration =
293
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
294
+ expect(
295
+ receivedConfiguration.rumConfiguration
296
+ .nativeIosResourceTrackingDisallowList
297
+ ).toEqual(disallowList);
298
+ });
299
+
300
+ it.each([
301
+ ['unset', 'unset', undefined],
302
+ ['list', 'unset', disallowList],
303
+ ['unset', 'list', disallowList]
304
+ ])(
305
+ 'partial initialization: features %s, initialize %s => native %p',
306
+ async (featuresValue, initializeValue, expected) => {
307
+ renderWithProvider({
308
+ configuration: {
309
+ rumConfiguration: {
310
+ trackErrors: false,
311
+ trackResources: false,
312
+ trackInteractions: false,
313
+ ...(featuresValue === 'list' && {
314
+ nativeIosResourceTrackingDisallowList: disallowList
315
+ })
316
+ },
317
+ traceConfiguration: {},
318
+ logsConfiguration: {}
319
+ }
320
+ });
321
+ await flushPromises();
322
+ expect(NativeModules.DdSdk.initialize).not.toHaveBeenCalled();
323
+
324
+ await DatadogProvider.initialize({
325
+ clientToken: 'fake-client-token',
326
+ env: 'fake-env',
327
+ rumConfiguration: {
328
+ applicationId: 'fake-application-id',
329
+ ...(initializeValue === 'list' && {
330
+ nativeIosResourceTrackingDisallowList: disallowList
331
+ })
332
+ }
333
+ });
334
+ await flushPromises();
335
+ expect(NativeModules.DdSdk.initialize).toHaveBeenCalledTimes(1);
336
+ const receivedConfiguration =
337
+ NativeModules.DdSdk.initialize.mock.calls[0][0];
338
+ expect(
339
+ receivedConfiguration.rumConfiguration
340
+ .nativeIosResourceTrackingDisallowList
341
+ ).toEqual(expected);
342
+ }
343
+ );
344
+ });
345
+
181
346
  describe('onInitialization callback', () => {
182
347
  it('runs after initialization when SYNC initialization', async () => {
183
348
  const onInitialization = jest.fn();
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { setCachedUserId } from '../../rum/helper';
7
+ import { clearCachedUserId, setCachedUserId } from '../../rum/helper';
8
8
 
9
9
  import type { UserInfo } from './types';
10
10
 
@@ -35,6 +35,7 @@ class UserInfoProvider {
35
35
 
36
36
  clearUserInfo = () => {
37
37
  this.userInfo = undefined;
38
+ clearCachedUserId();
38
39
  };
39
40
  }
40
41