@datadog/mobile-react-native 1.3.1 → 1.4.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 (82) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +36 -2
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +14 -0
  3. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +145 -5
  4. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
  5. package/ios/Sources/DdSdk.swift +2 -2
  6. package/ios/Sources/RNDdSdkConfiguration.swift +42 -0
  7. package/lib/commonjs/DdSdkReactNative.js +2 -2
  8. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  9. package/lib/commonjs/DdSdkReactNativeConfiguration.js +26 -1
  10. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  11. package/lib/commonjs/index.js +12 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +1 -1
  14. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +59 -41
  16. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +136 -0
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +39 -6
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +12 -21
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  26. package/lib/commonjs/rum/types.js +19 -1
  27. package/lib/commonjs/rum/types.js.map +1 -1
  28. package/lib/commonjs/version.js +1 -1
  29. package/lib/commonjs/version.js.map +1 -1
  30. package/lib/module/DdSdkReactNative.js +3 -3
  31. package/lib/module/DdSdkReactNative.js.map +1 -1
  32. package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
  33. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  34. package/lib/module/index.js +3 -3
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +2 -2
  37. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  38. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +57 -35
  39. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  40. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +115 -0
  41. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  42. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +37 -3
  43. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  44. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  45. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  46. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  47. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +10 -15
  48. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  49. package/lib/module/rum/types.js +16 -0
  50. package/lib/module/rum/types.js.map +1 -1
  51. package/lib/module/version.js +1 -1
  52. package/lib/module/version.js.map +1 -1
  53. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +11 -3
  54. package/lib/typescript/index.d.ts +3 -3
  55. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  56. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
  57. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
  58. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
  59. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
  60. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -5
  61. package/lib/typescript/rum/types.d.ts +17 -0
  62. package/lib/typescript/version.d.ts +1 -1
  63. package/package.json +2 -2
  64. package/src/DdSdkReactNative.tsx +8 -4
  65. package/src/DdSdkReactNativeConfiguration.tsx +36 -3
  66. package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
  67. package/src/index.tsx +6 -3
  68. package/src/rum/__tests__/DdRum.test.ts +17 -1
  69. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
  70. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +13 -2
  71. package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +64 -24
  72. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +19 -7
  73. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +82 -40
  74. package/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.ts +141 -0
  75. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +43 -7
  76. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +8 -1
  77. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +4 -4
  78. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
  79. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +251 -73
  80. package/src/rum/types.ts +19 -0
  81. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -1
  82. package/src/version.ts +1 -1
@@ -1,3 +1,3 @@
1
1
  // generated by genversion
2
- export const version = '1.3.1';
2
+ export const version = '1.4.0';
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.3.1';\n"]}
1
+ {"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.4.0';\n"]}
@@ -5,12 +5,20 @@ import type { LogEventMapper } from './logs/types';
5
5
  import type { ActionEventMapper } from './rum/eventMappers/actionEventMapper';
6
6
  import type { ErrorEventMapper } from './rum/eventMappers/errorEventMapper';
7
7
  import type { ResourceEventMapper } from './rum/eventMappers/resourceEventMapper';
8
+ import type { FirstPartyHost } from './rum/types';
8
9
  export declare enum VitalsUpdateFrequency {
9
10
  FREQUENT = "FREQUENT",
10
11
  AVERAGE = "AVERAGE",
11
12
  RARE = "RARE",
12
13
  NEVER = "NEVER"
13
14
  }
15
+ export declare type FirstPartyHostsConfiguration = (FirstPartyHost | LegacyFirstPartyHost)[];
16
+ export declare type LegacyFirstPartyHost = string;
17
+ /**
18
+ * Defaults legacy first party hosts format to Datadog first party hosts to keep
19
+ * retro-compatibility before OTel support was introduced.
20
+ */
21
+ export declare const formatFirstPartyHosts: (firstPartyHosts: FirstPartyHostsConfiguration) => FirstPartyHost[];
14
22
  /**
15
23
  * The SDK configuration class.
16
24
  * It will be used to configure the SDK functionality at initialization.
@@ -63,7 +71,7 @@ export declare class DdSdkReactNativeConfiguration {
63
71
  *
64
72
  * Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
65
73
  */
66
- firstPartyHosts: string[];
74
+ firstPartyHosts: FirstPartyHostsConfiguration;
67
75
  /**
68
76
  * Overrides the reported version of the app.
69
77
  * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
@@ -134,7 +142,7 @@ export declare class DdSdkReactNativeConfiguration {
134
142
  export declare type AutoInstrumentationConfiguration = {
135
143
  readonly trackInteractions: boolean;
136
144
  readonly trackResources: boolean;
137
- readonly firstPartyHosts?: string[];
145
+ readonly firstPartyHosts?: FirstPartyHostsConfiguration;
138
146
  readonly resourceTracingSamplingRate?: number;
139
147
  readonly trackErrors: boolean;
140
148
  readonly logEventMapper?: LogEventMapper | null;
@@ -148,7 +156,7 @@ export declare type AutoInstrumentationConfiguration = {
148
156
  export declare type AutoInstrumentationParameters = {
149
157
  readonly trackInteractions: boolean;
150
158
  readonly trackResources: boolean;
151
- readonly firstPartyHosts: string[];
159
+ readonly firstPartyHosts: FirstPartyHostsConfiguration;
152
160
  readonly resourceTracingSamplingRate: number;
153
161
  readonly trackErrors: boolean;
154
162
  readonly logEventMapper: LogEventMapper | null;
@@ -1,4 +1,4 @@
1
- import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode } from './DdSdkReactNativeConfiguration';
1
+ import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode, VitalsUpdateFrequency } from './DdSdkReactNativeConfiguration';
2
2
  import { DdSdkReactNative } from './DdSdkReactNative';
3
3
  import { InternalLog } from './InternalLog';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
@@ -7,6 +7,6 @@ import { TrackingConsent } from './TrackingConsent';
7
7
  import { DdTrace } from './foundation';
8
8
  import { DdLogs } from './logs/DdLogs';
9
9
  import { DdRum } from './rum/DdRum';
10
- import { RumActionType, ErrorSource } from './rum/types';
10
+ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
11
11
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
12
- export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
12
+ export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity, VitalsUpdateFrequency, PropagatorType };
@@ -1,3 +1,4 @@
1
+ import type { FirstPartyHost } from '../../types';
1
2
  /**
2
3
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
3
4
  */
@@ -9,7 +10,7 @@ export declare class DdRumResourceTracking {
9
10
  */
10
11
  static startTracking({ tracingSamplingRate, firstPartyHosts }: {
11
12
  tracingSamplingRate: number;
12
- firstPartyHosts: string[];
13
+ firstPartyHosts: FirstPartyHost[];
13
14
  }): void;
14
15
  static stopTracking(): void;
15
16
  }
@@ -1,19 +1,45 @@
1
+ import type { PropagatorType } from '../../../types';
1
2
  import type { Hostname } from './firstPartyHosts';
3
+ import type { RegexMap } from './interfaces/RequestProxy';
2
4
  export declare type DdRumResourceTracingAttributes = {
3
5
  tracingStrategy: 'KEEP';
4
- traceId: string;
5
- spanId: string;
6
- samplingPriorityHeader: '1';
6
+ traceId: TraceId;
7
+ spanId: SpanId;
8
+ samplingPriorityHeader: '1' | '0';
7
9
  rulePsr: number;
10
+ propagatorTypes: PropagatorType[];
8
11
  } | {
9
12
  tracingStrategy: 'DISCARD';
10
13
  traceId?: void;
11
14
  spanId?: void;
12
15
  samplingPriorityHeader: '0';
13
16
  };
14
- export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
17
+ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegexMap, tracingSamplingRate }: {
15
18
  hostname: Hostname | null;
16
- firstPartyHostsRegex: RegExp;
19
+ firstPartyHostsRegexMap: RegexMap;
17
20
  tracingSamplingRate: number;
18
21
  }) => DdRumResourceTracingAttributes;
19
- export declare function generateTraceId(): string;
22
+ /**
23
+ * Using branded types will ensure we don't accidentally use
24
+ * traceId for spanId when generating headers.
25
+ */
26
+ export declare type TraceId = TraceIdentifier & {
27
+ _brand: 'traceId';
28
+ };
29
+ export declare type SpanId = TraceIdentifier & {
30
+ _brand: 'spanId';
31
+ };
32
+ export declare class TraceIdentifier {
33
+ private low;
34
+ private high;
35
+ constructor();
36
+ toString: (radix: number) => string;
37
+ /**
38
+ * This function pads the trace with `0`.
39
+ * It should not be used with a `length` lower than the trace, as we return the full trace in this case.
40
+ * @param radix radix for the trace
41
+ * @param length minimum length
42
+ * @returns padded string
43
+ */
44
+ toPaddedString: (radix: number, length: number) => string;
45
+ }
@@ -0,0 +1,21 @@
1
+ import type { DdRumResourceTracingAttributes } from './distributedTracing';
2
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
3
+ /**
4
+ * Datadog headers
5
+ */
6
+ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
7
+ export declare const ORIGIN_RUM = "rum";
8
+ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
9
+ export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
10
+ /**
11
+ * OTel headers
12
+ */
13
+ export declare const TRACECONTEXT_HEADER_KEY = "traceparent";
14
+ export declare const B3_HEADER_KEY = "b3";
15
+ export declare const B3_MULTI_TRACE_ID_HEADER_KEY = "X-B3-TraceId";
16
+ export declare const B3_MULTI_SPAN_ID_HEADER_KEY = "X-B3-SpanId";
17
+ export declare const B3_MULTI_SAMPLED_HEADER_KEY = "X-B3-Sampled";
18
+ export declare const getTracingHeaders: (tracingAttributes: DdRumResourceTracingAttributes) => {
19
+ header: string;
20
+ value: string;
21
+ }[];
@@ -1,6 +1,8 @@
1
+ import type { FirstPartyHost, PropagatorType } from '../../../types';
2
+ import type { RegexMap } from './interfaces/RequestProxy';
1
3
  export declare type Hostname = {
2
4
  _type: 'Hostname';
3
5
  } & string;
4
6
  export declare const NO_MATCH_REGEX: RegExp;
5
- export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
6
- export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
7
+ export declare const firstPartyHostsRegexMapBuilder: (firstPartyHosts: FirstPartyHost[]) => RegexMap;
8
+ export declare const getPropagatorsForHost: (hostname: Hostname, firstPartyHostsRegexMap: RegexMap) => PropagatorType[] | null;
@@ -1,7 +1,12 @@
1
+ import type { PropagatorType } from '../../../../types';
1
2
  export interface RequestProxyOptions {
2
3
  tracingSamplingRate: number;
3
- firstPartyHostsRegex: RegExp;
4
+ firstPartyHostsRegexMap: RegexMap;
4
5
  }
6
+ export declare type RegexMap = {
7
+ regex: RegExp;
8
+ propagatorType: PropagatorType;
9
+ }[];
5
10
  export declare abstract class RequestProxy {
6
11
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
12
  abstract onTrackingStop: () => void;
@@ -1,11 +1,6 @@
1
1
  import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
2
2
  import { RequestProxy } from '../domain/interfaces/RequestProxy';
3
3
  import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
4
- export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
5
- export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
6
- export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
7
- export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
8
- export declare const ORIGIN_RUM = "rum";
9
4
  interface XHRProxyProviders {
10
5
  xhrType: typeof XMLHttpRequest;
11
6
  resourceReporter: ResourceReporter;
@@ -108,3 +108,20 @@ export declare enum ErrorSource {
108
108
  WEBVIEW = "WEBVIEW",
109
109
  CUSTOM = "CUSTOM"
110
110
  }
111
+ /**
112
+ * Type of instrumentation on the host.
113
+ * - DATADOG: Datadog’s propagator (`x-datadog-*`)
114
+ * - TRACECONTEXT: W3C Trace Context (`traceparent`)
115
+ * - B3: B3 single header (`b3`)
116
+ * - B3MULTI: B3 multiple headers (`X-B3-*`)
117
+ */
118
+ export declare enum PropagatorType {
119
+ DATADOG = "datadog",
120
+ TRACECONTEXT = "tracecontext",
121
+ B3 = "b3",
122
+ B3MULTI = "b3multi"
123
+ }
124
+ export declare type FirstPartyHost = {
125
+ match: string;
126
+ propagatorTypes: PropagatorType[];
127
+ };
@@ -1 +1 @@
1
- export declare const version = "1.3.1";
1
+ export declare const version = "1.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-native",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "c70d62caff28da6111c8e526de4dfbb82bb9bf2d"
80
+ "gitHead": "cc9c7937cecfd48720ec46852c24965f4a00bab4"
81
81
  }
@@ -10,7 +10,8 @@ import {
10
10
  DdSdkReactNativeConfiguration,
11
11
  buildConfigurationFromPartialConfiguration,
12
12
  addDefaultValuesToAutoInstrumentationConfiguration,
13
- InitializationMode
13
+ InitializationMode,
14
+ formatFirstPartyHosts
14
15
  } from './DdSdkReactNativeConfiguration';
15
16
  import type {
16
17
  AutoInstrumentationParameters,
@@ -301,8 +302,9 @@ export class DdSdkReactNative {
301
302
  ] = `-${configuration.versionSuffix}`;
302
303
  }
303
304
 
304
- configuration.additionalConfig['_dd.first_party_hosts'] =
305
- configuration.firstPartyHosts;
305
+ configuration.additionalConfig[
306
+ '_dd.first_party_hosts'
307
+ ] = formatFirstPartyHosts(configuration.firstPartyHosts);
306
308
  };
307
309
 
308
310
  private static enableFeatures(
@@ -322,7 +324,9 @@ export class DdSdkReactNative {
322
324
  if (configuration.trackResources) {
323
325
  DdRumResourceTracking.startTracking({
324
326
  tracingSamplingRate: configuration.resourceTracingSamplingRate,
325
- firstPartyHosts: configuration.firstPartyHosts
327
+ firstPartyHosts: formatFirstPartyHosts(
328
+ configuration.firstPartyHosts
329
+ )
326
330
  });
327
331
  }
328
332
 
@@ -11,6 +11,8 @@ import type { LogEventMapper } from './logs/types';
11
11
  import type { ActionEventMapper } from './rum/eventMappers/actionEventMapper';
12
12
  import type { ErrorEventMapper } from './rum/eventMappers/errorEventMapper';
13
13
  import type { ResourceEventMapper } from './rum/eventMappers/resourceEventMapper';
14
+ import type { FirstPartyHost } from './rum/types';
15
+ import { PropagatorType } from './rum/types';
14
16
 
15
17
  export enum VitalsUpdateFrequency {
16
18
  FREQUENT = 'FREQUENT',
@@ -19,6 +21,37 @@ export enum VitalsUpdateFrequency {
19
21
  NEVER = 'NEVER'
20
22
  }
21
23
 
24
+ export type FirstPartyHostsConfiguration = (
25
+ | FirstPartyHost
26
+ | LegacyFirstPartyHost
27
+ )[];
28
+
29
+ export type LegacyFirstPartyHost = string;
30
+
31
+ const isLegacyFirstPartyHost = (
32
+ firstPartyHost: FirstPartyHost | LegacyFirstPartyHost
33
+ ): firstPartyHost is LegacyFirstPartyHost => {
34
+ return typeof firstPartyHost === 'string';
35
+ };
36
+
37
+ /**
38
+ * Defaults legacy first party hosts format to Datadog first party hosts to keep
39
+ * retro-compatibility before OTel support was introduced.
40
+ */
41
+ export const formatFirstPartyHosts = (
42
+ firstPartyHosts: FirstPartyHostsConfiguration
43
+ ): FirstPartyHost[] => {
44
+ return firstPartyHosts.map(host => {
45
+ if (isLegacyFirstPartyHost(host)) {
46
+ return {
47
+ match: host,
48
+ propagatorTypes: [PropagatorType.DATADOG]
49
+ };
50
+ }
51
+ return host;
52
+ });
53
+ };
54
+
22
55
  const DEFAULTS = {
23
56
  nativeCrashReportEnabled: false,
24
57
  sessionSamplingRate: 100.0,
@@ -87,7 +120,7 @@ export class DdSdkReactNativeConfiguration {
87
120
  *
88
121
  * Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
89
122
  */
90
- public firstPartyHosts: string[] = DEFAULTS.getFirstPartyHosts();
123
+ public firstPartyHosts: FirstPartyHostsConfiguration = DEFAULTS.getFirstPartyHosts();
91
124
  /**
92
125
  * Overrides the reported version of the app.
93
126
  * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
@@ -182,7 +215,7 @@ export class DdSdkReactNativeConfiguration {
182
215
  export type AutoInstrumentationConfiguration = {
183
216
  readonly trackInteractions: boolean;
184
217
  readonly trackResources: boolean;
185
- readonly firstPartyHosts?: string[];
218
+ readonly firstPartyHosts?: FirstPartyHostsConfiguration;
186
219
  readonly resourceTracingSamplingRate?: number;
187
220
  readonly trackErrors: boolean;
188
221
  readonly logEventMapper?: LogEventMapper | null;
@@ -197,7 +230,7 @@ export type AutoInstrumentationConfiguration = {
197
230
  export type AutoInstrumentationParameters = {
198
231
  readonly trackInteractions: boolean;
199
232
  readonly trackResources: boolean;
200
- readonly firstPartyHosts: string[];
233
+ readonly firstPartyHosts: FirstPartyHostsConfiguration;
201
234
  readonly resourceTracingSamplingRate: number;
202
235
  readonly trackErrors: boolean;
203
236
  readonly logEventMapper: LogEventMapper | null;
@@ -17,7 +17,7 @@ import { DdRum } from '../rum/DdRum';
17
17
  import { DdRumErrorTracking } from '../rum/instrumentation/DdRumErrorTracking';
18
18
  import { DdRumUserInteractionTracking } from '../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
19
19
  import { DdRumResourceTracking } from '../rum/instrumentation/resourceTracking/DdRumResourceTracking';
20
- import { ErrorSource, RumActionType } from '../rum/types';
20
+ import { ErrorSource, PropagatorType, RumActionType } from '../rum/types';
21
21
  import { AttributesSingleton } from '../sdk/AttributesSingleton/AttributesSingleton';
22
22
  import { UserInfoSingleton } from '../sdk/UserInfoSingleton/UserInfoSingleton';
23
23
  import type { DdSdkConfiguration } from '../types';
@@ -488,7 +488,13 @@ describe('DdSdkReactNative', () => {
488
488
  true
489
489
  );
490
490
  configuration.resourceTracingSamplingRate = 42;
491
- configuration.firstPartyHosts = ['api.example.com'];
491
+ configuration.firstPartyHosts = [
492
+ 'api.example.com',
493
+ {
494
+ match: 'something.fr',
495
+ propagatorTypes: [PropagatorType.DATADOG]
496
+ }
497
+ ];
492
498
 
493
499
  NativeModules.DdSdk.initialize.mockResolvedValue(null);
494
500
 
@@ -507,14 +513,20 @@ describe('DdSdkReactNative', () => {
507
513
  '_dd.sdk_version': sdkVersion,
508
514
  '_dd.native_view_tracking': false,
509
515
  '_dd.native_interaction_tracking': false,
510
- '_dd.first_party_hosts': ['api.example.com']
516
+ '_dd.first_party_hosts': [
517
+ { match: 'api.example.com', propagatorTypes: ['datadog'] },
518
+ { match: 'something.fr', propagatorTypes: ['datadog'] }
519
+ ]
511
520
  });
512
521
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledTimes(
513
522
  1
514
523
  );
515
524
  expect(DdRumResourceTracking.startTracking).toHaveBeenCalledWith({
516
525
  tracingSamplingRate: 42,
517
- firstPartyHosts: ['api.example.com']
526
+ firstPartyHosts: [
527
+ { match: 'api.example.com', propagatorTypes: ['datadog'] },
528
+ { match: 'something.fr', propagatorTypes: ['datadog'] }
529
+ ]
518
530
  });
519
531
  });
520
532
 
package/src/index.tsx CHANGED
@@ -7,7 +7,8 @@
7
7
  import {
8
8
  DatadogProviderConfiguration,
9
9
  DdSdkReactNativeConfiguration,
10
- InitializationMode
10
+ InitializationMode,
11
+ VitalsUpdateFrequency
11
12
  } from './DdSdkReactNativeConfiguration';
12
13
  import { DdSdkReactNative } from './DdSdkReactNative';
13
14
  import { InternalLog } from './InternalLog';
@@ -17,7 +18,7 @@ import { TrackingConsent } from './TrackingConsent';
17
18
  import { DdTrace } from './foundation';
18
19
  import { DdLogs } from './logs/DdLogs';
19
20
  import { DdRum } from './rum/DdRum';
20
- import { RumActionType, ErrorSource } from './rum/types';
21
+ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
21
22
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
22
23
 
23
24
  export {
@@ -35,5 +36,7 @@ export {
35
36
  ProxyConfiguration,
36
37
  ProxyType,
37
38
  TrackingConsent,
38
- SdkVerbosity
39
+ SdkVerbosity,
40
+ VitalsUpdateFrequency,
41
+ PropagatorType
39
42
  };
@@ -13,7 +13,7 @@ import { DdRum } from '../DdRum';
13
13
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
14
14
  import type { ErrorEventMapper } from '../eventMappers/errorEventMapper';
15
15
  import type { ResourceEventMapper } from '../eventMappers/resourceEventMapper';
16
- import { ErrorSource, RumActionType } from '../types';
16
+ import { ErrorSource, PropagatorType, RumActionType } from '../types';
17
17
 
18
18
  jest.mock('../../TimeProvider', () => {
19
19
  return {
@@ -383,4 +383,20 @@ describe('DdRum', () => {
383
383
  );
384
384
  });
385
385
  });
386
+
387
+ describe('PropagatorTypes', () => {
388
+ it('matches with the native name of propagators', () => {
389
+ /**
390
+ * If you break this test by changing the value of the enum,
391
+ * be sure to update the native implementation of
392
+ * - ReadableArray.asTracingHeaderTypes (Android)
393
+ * - asTracingHeaderType (iOS)
394
+ * so that it uses the new values
395
+ */
396
+ expect(PropagatorType.DATADOG).toBe('datadog');
397
+ expect(PropagatorType.B3).toBe('b3');
398
+ expect(PropagatorType.B3MULTI).toBe('b3multi');
399
+ expect(PropagatorType.TRACECONTEXT).toBe('tracecontext');
400
+ });
401
+ });
386
402
  });
@@ -6,8 +6,9 @@
6
6
 
7
7
  import { InternalLog } from '../../../InternalLog';
8
8
  import { SdkVerbosity } from '../../../SdkVerbosity';
9
+ import type { FirstPartyHost } from '../../types';
9
10
 
10
- import { firstPartyHostsRegexBuilder } from './domain/firstPartyHosts';
11
+ import { firstPartyHostsRegexMapBuilder } from './domain/firstPartyHosts';
11
12
  import type { RequestProxy } from './domain/interfaces/RequestProxy';
12
13
  import { ResourceReporter } from './implementation/DatadogRumResource/ResourceReporter';
13
14
  import { filterDevResource } from './implementation/DatadogRumResource/internalDevResourceBlocklist';
@@ -28,7 +29,7 @@ export class DdRumResourceTracking {
28
29
  firstPartyHosts
29
30
  }: {
30
31
  tracingSamplingRate: number;
31
- firstPartyHosts: string[];
32
+ firstPartyHosts: FirstPartyHost[];
32
33
  }): void {
33
34
  // extra safety to avoid proxying the XHR class twice
34
35
  if (DdRumResourceTracking.isTracking) {
@@ -45,7 +46,9 @@ export class DdRumResourceTracking {
45
46
  });
46
47
  this.requestProxy.onTrackingStart({
47
48
  tracingSamplingRate,
48
- firstPartyHostsRegex: firstPartyHostsRegexBuilder(firstPartyHosts)
49
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder(
50
+ firstPartyHosts
51
+ )
49
52
  });
50
53
 
51
54
  InternalLog.log(
@@ -7,6 +7,7 @@
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
9
  import { BufferSingleton } from '../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
+ import { PropagatorType } from '../../../types';
10
11
  import { DdRumResourceTracking } from '../DdRumResourceTracking';
11
12
 
12
13
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
@@ -41,7 +42,12 @@ describe('DdRumResourceTracking', () => {
41
42
  global.XMLHttpRequest = XMLHttpRequestMock;
42
43
  DdRumResourceTracking.startTracking({
43
44
  tracingSamplingRate: 100,
44
- firstPartyHosts: ['example.com']
45
+ firstPartyHosts: [
46
+ {
47
+ match: 'example.com',
48
+ propagatorTypes: [PropagatorType.DATADOG]
49
+ }
50
+ ]
45
51
  });
46
52
 
47
53
  // WHEN
@@ -68,7 +74,12 @@ describe('DdRumResourceTracking', () => {
68
74
  global.XMLHttpRequest = XMLHttpRequestMock;
69
75
  DdRumResourceTracking.startTracking({
70
76
  tracingSamplingRate: 100,
71
- firstPartyHosts: ['example.com']
77
+ firstPartyHosts: [
78
+ {
79
+ match: 'example.com',
80
+ propagatorTypes: [PropagatorType.DATADOG]
81
+ }
82
+ ]
72
83
  });
73
84
 
74
85
  // WHEN
@@ -1,31 +1,71 @@
1
- import { generateTraceId } from '../distributedTracing';
1
+ import { TraceIdentifier } from '../distributedTracing';
2
2
 
3
- it('M return an unique identifier W toString', async () => {
4
- // GIVEN
5
- const generatedIds = new Set<string>();
6
- const iterations = 100;
7
- let counter = iterations;
3
+ describe('TraceIdentifier', () => {
4
+ it('M return an unique identifier W toString', async () => {
5
+ // GIVEN
6
+ const generatedIds = new Set<string>();
7
+ const iterations = 100;
8
+ let counter = iterations;
8
9
 
9
- // WHEN
10
- while (counter-- > 0) {
11
- generatedIds.add(generateTraceId());
12
- }
10
+ // WHEN
11
+ while (counter-- > 0) {
12
+ generatedIds.add(new TraceIdentifier().toString(10));
13
+ }
13
14
 
14
- // THEN
15
- expect(generatedIds.size).toBe(iterations);
16
- });
15
+ // THEN
16
+ expect(generatedIds.size).toBe(iterations);
17
+ });
17
18
 
18
- it('M return an 64 bits positive integer W toString', async () => {
19
- let iterations = 100;
20
- while (iterations-- > 0) {
21
- // GIVEN
22
- const id = generateTraceId();
19
+ it('M return an 64 bits positive integer W toString', async () => {
20
+ let iterations = 100;
21
+ while (iterations-- > 0) {
22
+ // GIVEN
23
+ const id = new TraceIdentifier().toString(10);
23
24
 
24
- // THEN
25
- expect(id).toMatch(/[1-9]{1,19}/);
26
- // should be less than the max 64 bits integer
27
- if (id.length === 19) {
28
- expect(id < '9223372036854775807').toBeTruthy();
25
+ // THEN
26
+ expect(id).toMatch(/[1-9]{1,19}/);
27
+ // should be less than the max 64 bits integer
28
+ if (id.length === 19) {
29
+ expect(id < '9223372036854775807').toBeTruthy();
30
+ }
31
+ }
32
+ });
33
+
34
+ it('M return an 64 bits positive hex W toString(16)', async () => {
35
+ let iterations = 100;
36
+ while (iterations-- > 0) {
37
+ // GIVEN
38
+ const trace = new TraceIdentifier();
39
+ const id = trace.toString(16);
40
+ const paddedId = trace.toPaddedString(16, 16);
41
+
42
+ // THEN
43
+ expect(id).toMatch(/[1-9a-f]{1,16}/);
44
+ expect(paddedId).toMatch(/[0-9a-f]{16}/);
45
+ }
46
+ });
47
+
48
+ it('M return an 64 bits positive padded hex W toPaddedString(16, 32)', async () => {
49
+ let iterations = 100;
50
+ while (iterations-- > 0) {
51
+ // GIVEN
52
+ const id = new TraceIdentifier().toPaddedString(16, 32);
53
+
54
+ // THEN
55
+ expect(id).not.toMatch(/[0]{32}/);
56
+ expect(id).toMatch(/[0]{16}[0-9a-f]{16}/);
57
+ }
58
+ });
59
+
60
+ it('M return original string hex W toPaddedString(16, 10)', async () => {
61
+ let iterations = 100;
62
+ while (iterations-- > 0) {
63
+ // GIVEN
64
+ const id = new TraceIdentifier().toPaddedString(16, 10);
65
+
66
+ // THEN
67
+ expect(id).not.toMatch(/[0]{10}/);
68
+ expect(id).toMatch(/[0-9a-f]{10}/);
29
69
  }
30
- }
70
+ });
31
71
  });