@datadog/mobile-react-native 3.10.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 (68) hide show
  1. package/DatadogSDKReactNative.podspec +7 -7
  2. package/android/build.gradle +9 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +10 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  5. package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  6. package/android/src/oldarchCommon/kotlin/com/datadog/reactnative/DdRum.kt +10 -0
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +9 -0
  8. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -3
  9. package/ios/Sources/DdRum.mm +13 -1
  10. package/ios/Sources/DdRumImplementation.swift +6 -0
  11. package/ios/Sources/SdkVersion.swift +1 -1
  12. package/jest/mock.js +3 -0
  13. package/lib/commonjs/rum/DdRum.js +4 -0
  14. package/lib/commonjs/rum/DdRum.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +2 -2
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +1 -1
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +7 -1
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  21. package/lib/commonjs/rum/types.js.map +1 -1
  22. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js +1 -0
  23. package/lib/commonjs/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  24. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +1 -0
  25. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  26. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  27. package/lib/commonjs/version.js +1 -1
  28. package/lib/module/rum/DdRum.js +4 -0
  29. package/lib/module/rum/DdRum.js.map +1 -1
  30. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +3 -3
  31. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  32. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +2 -2
  33. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  34. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +5 -0
  35. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  36. package/lib/module/rum/types.js.map +1 -1
  37. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js +2 -1
  38. package/lib/module/sdk/AccountInfoSingleton/AccountInfoSingleton.js.map +1 -1
  39. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +2 -1
  40. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
  41. package/lib/module/specs/NativeDdRum.js.map +1 -1
  42. package/lib/module/version.js +1 -1
  43. package/lib/typescript/rum/DdRum.d.ts +1 -0
  44. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  45. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  46. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  47. package/lib/typescript/rum/types.d.ts +6 -0
  48. package/lib/typescript/rum/types.d.ts.map +1 -1
  49. package/lib/typescript/sdk/AccountInfoSingleton/AccountInfoSingleton.d.ts.map +1 -1
  50. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
  51. package/lib/typescript/specs/NativeDdRum.d.ts +6 -0
  52. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  53. package/lib/typescript/version.d.ts +1 -1
  54. package/package.json +2 -2
  55. package/src/rum/DdRum.ts +10 -0
  56. package/src/rum/__tests__/DdRum.test.ts +10 -0
  57. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +3 -3
  58. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +29 -0
  59. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +2 -2
  60. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +40 -0
  61. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +9 -0
  62. package/src/rum/types.ts +7 -0
  63. package/src/sdk/AccountInfoSingleton/AccountInfoSingleton.ts +2 -1
  64. package/src/sdk/AccountInfoSingleton/__tests__/AccountInfoSingleton.test.ts +59 -0
  65. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +2 -1
  66. package/src/sdk/UserInfoSingleton/__tests__/UserInfoSingleton.test.ts +55 -0
  67. package/src/specs/NativeDdRum.ts +7 -0
  68. package/src/version.ts +1 -1
@@ -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
  });
@@ -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
 
@@ -4,11 +4,49 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import {
8
+ clearCachedAccountId,
9
+ clearCachedSessionId,
10
+ clearCachedUserId,
11
+ getCachedUserId
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 { UserInfoSingleton } from '../UserInfoSingleton';
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('UserInfoSingleton', () => {
10
45
  beforeEach(() => {
11
46
  UserInfoSingleton.reset();
47
+ clearCachedSessionId();
48
+ clearCachedUserId();
49
+ clearCachedAccountId();
12
50
  });
13
51
 
14
52
  it('returns undefined by default', () => {
@@ -63,4 +101,21 @@ describe('UserInfoSingleton', () => {
63
101
 
64
102
  expect(a).toBe(b);
65
103
  });
104
+
105
+ it('clears the cached user id used by RequestContext baggage after clearUserInfo', () => {
106
+ const userId = 'previous-user';
107
+ UserInfoSingleton.getInstance().setUserInfo({
108
+ id: userId,
109
+ extraInfo: {}
110
+ });
111
+
112
+ expect(getCachedUserId()).toBe(userId);
113
+ expect(getBaggageHeader()).toBe(`user.id=${userId}`);
114
+
115
+ UserInfoSingleton.getInstance().clearUserInfo();
116
+
117
+ expect(UserInfoSingleton.getInstance().getUserInfo()).toBeUndefined();
118
+ expect(getCachedUserId()).toBeUndefined();
119
+ expect(getBaggageHeader() ?? '').not.toContain(`user.id=${userId}`);
120
+ });
66
121
  });
@@ -170,6 +170,13 @@ export interface Spec extends TurboModule {
170
170
  */
171
171
  addViewLoadingTime(overwrite: boolean): Promise<void>;
172
172
 
173
+ /**
174
+ * This method can be used to mark the moment in time when the UI of the app is considered fully displayed.
175
+ * The duration between the application launch and this moment of time will be shown as TTFD (time to full display)
176
+ * in the RUM session explorer. Only the first call to this method will have any effect for a given RUM session.
177
+ */
178
+ reportAppFullyDisplayed(): Promise<void>;
179
+
173
180
  /**
174
181
  * Stops the current RUM Session.
175
182
  */
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '3.10.0';
2
+ export const version = '3.11.0';