@datadog/mobile-react-native 2.8.2 → 2.9.1

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 (92) hide show
  1. package/android/build.gradle +15 -4
  2. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  3. package/datadog-sourcemaps.gradle +101 -3
  4. package/ios/Sources/SdkVersion.swift +1 -1
  5. package/lib/commonjs/metro/debugIdResolver.js +39 -0
  6. package/lib/commonjs/metro/debugIdResolver.js.map +1 -0
  7. package/lib/commonjs/metro/metro.d.js +2 -0
  8. package/lib/commonjs/metro/metro.d.js.map +1 -0
  9. package/lib/commonjs/metro/plugin/debugIdHelper.js +244 -0
  10. package/lib/commonjs/metro/plugin/debugIdHelper.js.map +1 -0
  11. package/lib/commonjs/metro/plugin/metroConfig.js +68 -0
  12. package/lib/commonjs/metro/plugin/metroConfig.js.map +1 -0
  13. package/lib/commonjs/metro/plugin/metroSerializer.js +143 -0
  14. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -0
  15. package/lib/commonjs/metro/plugin/types/expoTypes.js +6 -0
  16. package/lib/commonjs/metro/plugin/types/expoTypes.js.map +1 -0
  17. package/lib/commonjs/metro/plugin/types/metroTypes.js +6 -0
  18. package/lib/commonjs/metro/plugin/types/metroTypes.js.map +1 -0
  19. package/lib/commonjs/metro/plugin/utils.js +153 -0
  20. package/lib/commonjs/metro/plugin/utils.js.map +1 -0
  21. package/lib/commonjs/metro.js +19 -0
  22. package/lib/commonjs/metro.js.map +1 -0
  23. package/lib/commonjs/rum/DdRum.js +2 -1
  24. package/lib/commonjs/rum/DdRum.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +1 -1
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  27. package/lib/commonjs/utils/errorUtils.js +13 -1
  28. package/lib/commonjs/utils/errorUtils.js.map +1 -1
  29. package/lib/commonjs/version.js +1 -1
  30. package/lib/module/metro/debugIdResolver.js +34 -0
  31. package/lib/module/metro/debugIdResolver.js.map +1 -0
  32. package/lib/module/metro/metro.d.js +2 -0
  33. package/lib/module/metro/metro.d.js.map +1 -0
  34. package/lib/module/metro/plugin/debugIdHelper.js +225 -0
  35. package/lib/module/metro/plugin/debugIdHelper.js.map +1 -0
  36. package/lib/module/metro/plugin/metroConfig.js +61 -0
  37. package/lib/module/metro/plugin/metroConfig.js.map +1 -0
  38. package/lib/module/metro/plugin/metroSerializer.js +131 -0
  39. package/lib/module/metro/plugin/metroSerializer.js.map +1 -0
  40. package/lib/module/metro/plugin/types/expoTypes.js +2 -0
  41. package/lib/module/metro/plugin/types/expoTypes.js.map +1 -0
  42. package/lib/module/metro/plugin/types/metroTypes.js +2 -0
  43. package/lib/module/metro/plugin/types/metroTypes.js.map +1 -0
  44. package/lib/module/metro/plugin/utils.js +139 -0
  45. package/lib/module/metro/plugin/utils.js.map +1 -0
  46. package/lib/module/metro.js +8 -0
  47. package/lib/module/metro.js.map +1 -0
  48. package/lib/module/rum/DdRum.js +2 -1
  49. package/lib/module/rum/DdRum.js.map +1 -1
  50. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
  51. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  52. package/lib/module/utils/errorUtils.js +11 -0
  53. package/lib/module/utils/errorUtils.js.map +1 -1
  54. package/lib/module/version.js +1 -1
  55. package/lib/typescript/metro/debugIdResolver.d.ts +3 -0
  56. package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -0
  57. package/lib/typescript/metro/plugin/debugIdHelper.d.ts +99 -0
  58. package/lib/typescript/metro/plugin/debugIdHelper.d.ts.map +1 -0
  59. package/lib/typescript/metro/plugin/metroConfig.d.ts +35 -0
  60. package/lib/typescript/metro/plugin/metroConfig.d.ts.map +1 -0
  61. package/lib/typescript/metro/plugin/metroSerializer.d.ts +29 -0
  62. package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -0
  63. package/lib/typescript/metro/plugin/types/expoTypes.d.ts +31 -0
  64. package/lib/typescript/metro/plugin/types/expoTypes.d.ts.map +1 -0
  65. package/lib/typescript/metro/plugin/types/metroTypes.d.ts +33 -0
  66. package/lib/typescript/metro/plugin/types/metroTypes.d.ts.map +1 -0
  67. package/lib/typescript/metro/plugin/utils.d.ts +36 -0
  68. package/lib/typescript/metro/plugin/utils.d.ts.map +1 -0
  69. package/lib/typescript/metro.d.ts +6 -0
  70. package/lib/typescript/metro.d.ts.map +1 -0
  71. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  72. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
  73. package/lib/typescript/utils/errorUtils.d.ts +1 -0
  74. package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
  75. package/lib/typescript/version.d.ts +1 -1
  76. package/package.json +21 -3
  77. package/scripts/copy-debug-id.js +48 -0
  78. package/src/metro/__tests__/__utils__/serializerUtils.ts +100 -0
  79. package/src/metro/__tests__/metro.test.ts +382 -0
  80. package/src/metro/debugIdResolver.ts +40 -0
  81. package/src/metro/metro.d.ts +73 -0
  82. package/src/metro/plugin/debugIdHelper.ts +279 -0
  83. package/src/metro/plugin/metroConfig.ts +97 -0
  84. package/src/metro/plugin/metroSerializer.ts +173 -0
  85. package/src/metro/plugin/types/expoTypes.ts +64 -0
  86. package/src/metro/plugin/types/metroTypes.ts +94 -0
  87. package/src/metro/plugin/utils.ts +177 -0
  88. package/src/metro.ts +14 -0
  89. package/src/rum/DdRum.ts +2 -1
  90. package/src/rum/instrumentation/DdRumErrorTracking.tsx +8 -2
  91. package/src/utils/errorUtils.ts +13 -0
  92. package/src/version.ts +1 -1
@@ -0,0 +1,94 @@
1
+ // MIT License
2
+
3
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+
12
+ // The above copyright notice and this permission notice shall be included in all
13
+ // copies or substantial portions of the Software.
14
+
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ // SOFTWARE.
22
+
23
+ // eslint-disable-next-line import/no-extraneous-dependencies
24
+ import type {
25
+ Module,
26
+ ReadOnlyGraph,
27
+ SerializerOptions,
28
+ MixedOutput,
29
+ MetroConfig
30
+ } from 'metro';
31
+
32
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro-config/types/configTypes.d.ts#L128
33
+ export type MetroSerializerOutput =
34
+ | string
35
+ | MetroBundleWithMap
36
+ | Promise<string | MetroBundleWithMap>;
37
+
38
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro-config/types/configTypes.d.ts#L122
39
+ export type MetroSerializer = (
40
+ entryPoint: string,
41
+ preModules: ReadonlyArray<Module>,
42
+ graph: ReadOnlyGraph,
43
+ options: SerializerOptions
44
+ ) => MetroSerializerOutput;
45
+
46
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/getAppendScripts.js#L61
47
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/getPrependedScripts.js#L107
48
+ export type MetroVirtualModuleOutput = {
49
+ type: 'js/script/virtual';
50
+ data: {
51
+ code: string;
52
+ lineCount: number;
53
+ map: [];
54
+ };
55
+ };
56
+
57
+ // https://github.com/facebook/metro/blob/v0.80.10/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js#L22
58
+ export type SourceMapString = (
59
+ modules: Module<MixedOutput>[],
60
+ options: {
61
+ excludeSource?: boolean;
62
+ processModuleFilter?: (module: Module<MixedOutput>) => boolean;
63
+ shouldAddToIgnoreList?: (module: Module<MixedOutput>) => boolean;
64
+ }
65
+ ) => string;
66
+
67
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro-runtime/src/modules/types.flow.js#L16
68
+ export type Bundle = {
69
+ modules: Array<[id: number, code: string]>;
70
+ post: string;
71
+ pre: string;
72
+ };
73
+
74
+ /*
75
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
76
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
77
+ * Copyright 2016-Present Datadog, Inc.
78
+ */
79
+ export type MetroBundleWithMap = { code: string; map: string };
80
+
81
+ export type DatadogMetroSerializer = (
82
+ entryPoint: string,
83
+ preModules: ReadonlyArray<Module>,
84
+ graph: ReadOnlyGraph,
85
+ options: SerializerOptions & {
86
+ datadogBundleCallback?: (bundle: Bundle) => Bundle;
87
+ }
88
+ ) => Promise<string | MetroBundleWithMap>;
89
+
90
+ export type DatadogDebugIdModule = Module<MetroVirtualModuleOutput> & {
91
+ setSource: (code: string) => void;
92
+ };
93
+
94
+ export type { MixedOutput, MetroConfig, Module, ReadOnlyGraph };
@@ -0,0 +1,177 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+ import sourceMapString from 'metro/src/DeltaBundler/Serializers/sourceMapString';
9
+ // eslint-disable-next-line import/no-extraneous-dependencies
10
+ import type CountingSet from 'metro/src/lib/CountingSet';
11
+ import type { ReadOnlyGraph, Module, MixedOutput } from 'metro';
12
+
13
+ import type { DefaultConfigOptions } from './types/expoTypes';
14
+ import type {
15
+ MetroSerializerOutput,
16
+ MetroBundleWithMap,
17
+ SourceMapString
18
+ } from './types/metroTypes';
19
+
20
+ /**
21
+ * Lazy-init reference for {@link createCountingSet} resolved function.
22
+ */
23
+ let createCountingSetFunc: (() => CountingSet<string>) | undefined;
24
+
25
+ /**
26
+ * Lazy-init reference for {@link metroSourceMapString} resolved function.
27
+ */
28
+ let sourceMapStringFunc: SourceMapString | undefined;
29
+
30
+ /**
31
+ * Lazy-init reference for {@link getDefaultExpoConfig} resolved function.
32
+ */
33
+ let getDefaultExpoConfigFunc:
34
+ | ((
35
+ projectRoot: string,
36
+ options: DefaultConfigOptions
37
+ ) => DefaultConfigOptions)
38
+ | undefined;
39
+
40
+ /**
41
+ * This function ensures that modules in source maps are sorted in the same
42
+ * order as in a plain JS bundle.
43
+ *
44
+ * https://github.com/facebook/metro/blob/76413561abb3757285e0cb0305f1f9f616fa2b6c/packages/metro/src/Server.js#L1086C1-L1095C7
45
+ */
46
+ export function getSortedModules(
47
+ graph: ReadOnlyGraph,
48
+ { createModuleId }: { createModuleId: (file: string) => number }
49
+ ): readonly Module<MixedOutput>[] {
50
+ const modules = [...graph.dependencies.values()];
51
+
52
+ // Assign IDs to modules in a consistent order
53
+ for (const module of modules) {
54
+ createModuleId(module.path);
55
+ }
56
+ // Sort by IDs
57
+ return modules.sort(
58
+ (a: Module<MixedOutput>, b: Module<MixedOutput>) =>
59
+ createModuleId(a.path) - createModuleId(b.path)
60
+ );
61
+ }
62
+
63
+ /**
64
+ * CountingSet was added in Metro 0.71.2 - a modified `Set` that only deletes items when the
65
+ * number of `delete(item)` calls matches the number of `add(item)` calls.
66
+ *
67
+ * https://github.com/facebook/metro/commit/fc29a1177f883144674cf85a813b58567f69d545
68
+ */
69
+ export const createCountingSet = () => {
70
+ if (createCountingSetFunc) {
71
+ return createCountingSetFunc();
72
+ }
73
+
74
+ try {
75
+ createCountingSetFunc = () => {
76
+ const {
77
+ default: MetroCountingSet
78
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies, @typescript-eslint/no-var-requires
79
+ } = require('metro/src/lib/CountingSet');
80
+ return new MetroCountingSet();
81
+ };
82
+ } catch (_) {
83
+ createCountingSetFunc = () =>
84
+ (new Set() as unknown) as CountingSet<string>;
85
+ }
86
+
87
+ return createCountingSetFunc();
88
+ };
89
+ /**
90
+ * In Metro versions prior to v0.80.10, `sourceMapString` was exported as a default export.
91
+ * Starting with v0.80.10, it became a named export.
92
+ *
93
+ * @returns The resolved `sourceMapString` function, of type {@link SourceMapString}
94
+ */
95
+ export const metroSourceMapString: SourceMapString = (
96
+ modules: Module<MixedOutput>[],
97
+ options: {
98
+ excludeSource?: boolean;
99
+ processModuleFilter?: (module: Module<MixedOutput>) => boolean;
100
+ shouldAddToIgnoreList?: (module: Module<MixedOutput>) => boolean;
101
+ }
102
+ ): string => {
103
+ if (sourceMapStringFunc) {
104
+ return sourceMapStringFunc(modules, options);
105
+ }
106
+
107
+ if (typeof sourceMapString === 'function') {
108
+ sourceMapStringFunc = sourceMapString;
109
+ } else if (
110
+ sourceMapString &&
111
+ typeof sourceMapString === 'object' &&
112
+ typeof sourceMapString['sourceMapString'] === 'function'
113
+ ) {
114
+ sourceMapStringFunc = (sourceMapString as {
115
+ sourceMapString: SourceMapString;
116
+ }).sourceMapString;
117
+ }
118
+
119
+ if (!sourceMapStringFunc) {
120
+ throw new Error(
121
+ "[DATADOG METRO PLUGIN] Cannot find sourceMapString function in 'metro/src/DeltaBundler/Serializers/sourceMapString'"
122
+ );
123
+ }
124
+
125
+ return sourceMapStringFunc(modules, options);
126
+ };
127
+
128
+ /**
129
+ * Converts the serializer result of type {@link MetroSerializerOutput} to {@link MetroBundleWithMap}.
130
+ */
131
+ export const convertSerializerOutput = async (
132
+ output: MetroSerializerOutput
133
+ ): Promise<MetroBundleWithMap> => {
134
+ const parse = (obj: MetroSerializerOutput) => {
135
+ // Plain String
136
+ if (typeof obj === 'string') {
137
+ return { code: obj, map: '{}' };
138
+ }
139
+
140
+ // Dictionary
141
+ if ('map' in obj) {
142
+ return { code: obj.code, map: obj.map };
143
+ }
144
+
145
+ return undefined;
146
+ };
147
+
148
+ const value = parse(output);
149
+ if (!value) {
150
+ return parse(await output) ?? { code: '', map: '{}' };
151
+ } else {
152
+ return value;
153
+ }
154
+ };
155
+
156
+ /**
157
+ * Gets the default Expo configuration options.
158
+ */
159
+ export const getDefaultExpoConfig = (
160
+ projectRoot: string,
161
+ options: DefaultConfigOptions
162
+ ): DefaultConfigOptions => {
163
+ if (!getDefaultExpoConfigFunc) {
164
+ try {
165
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
166
+ const metroConfig = require('expo/metro-config');
167
+ getDefaultExpoConfigFunc = metroConfig.getDefaultConfig;
168
+ return metroConfig.getDefaultConfig(projectRoot, options);
169
+ } catch (e) {
170
+ throw new Error(
171
+ 'Cannot load `expo/metro-config`. Make sure Expo is properly set up in your project.'
172
+ );
173
+ }
174
+ } else {
175
+ return getDefaultExpoConfigFunc(projectRoot, options);
176
+ }
177
+ };
package/src/metro.ts ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+ import {
7
+ withDatadogMetroConfig,
8
+ getDatadogExpoConfig
9
+ } from './metro/plugin/metroConfig';
10
+ import type { DatadogMetroConfigOptions } from './metro/plugin/metroConfig';
11
+ import type { DatadogExpoConfigOptions } from './metro/plugin/types/expoTypes';
12
+
13
+ export { withDatadogMetroConfig, getDatadogExpoConfig };
14
+ export type { DatadogMetroConfigOptions, DatadogExpoConfigOptions };
package/src/rum/DdRum.ts CHANGED
@@ -12,6 +12,7 @@ import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNative
12
12
  import { DdSdk } from '../sdk/DdSdk';
13
13
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
14
14
  import { validateContext } from '../utils/argsUtils';
15
+ import { getErrorContext } from '../utils/errorUtils';
15
16
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
16
17
  import type { TimeProvider } from '../utils/time-provider/TimeProvider';
17
18
 
@@ -249,7 +250,7 @@ class DdRumWrapper implements DdRumType {
249
250
  message,
250
251
  source,
251
252
  stacktrace,
252
- context: validateContext(context),
253
+ context: getErrorContext(validateContext(context)),
253
254
  timestampMs,
254
255
  fingerprint: fingerprint ?? ''
255
256
  });
@@ -14,7 +14,8 @@ import {
14
14
  getErrorStackTrace,
15
15
  EMPTY_STACK_TRACE,
16
16
  getErrorName,
17
- DEFAULT_ERROR_NAME
17
+ DEFAULT_ERROR_NAME,
18
+ getErrorContext
18
19
  } from '../../utils/errorUtils';
19
20
  import { executeWithDelay } from '../../utils/jsUtils';
20
21
  import { DdRum } from '../DdRum';
@@ -145,7 +146,12 @@ export class DdRumErrorTracking {
145
146
  context: object = {}
146
147
  ): Promise<[void, void]> => {
147
148
  return Promise.all([
148
- DdRum.addError(message, source, stacktrace, context),
149
+ DdRum.addError(
150
+ message,
151
+ source,
152
+ stacktrace,
153
+ getErrorContext(context)
154
+ ),
149
155
  DdLogs.error(
150
156
  message,
151
157
  errorName,
@@ -4,6 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import { debugId } from '../metro/debugIdResolver';
8
+
7
9
  export const EMPTY_MESSAGE = 'Unknown Error';
8
10
  export const EMPTY_STACK_TRACE = '';
9
11
  export const DEFAULT_ERROR_NAME = 'Error';
@@ -71,3 +73,14 @@ export const getErrorName = (error: unknown): string => {
71
73
  }
72
74
  return DEFAULT_ERROR_NAME;
73
75
  };
76
+
77
+ export const getErrorContext = (originalContext: any): Record<string, any> => {
78
+ const _debugId = debugId;
79
+ if (!_debugId) {
80
+ return originalContext;
81
+ }
82
+ return {
83
+ ...originalContext,
84
+ '_dd.debug_id': _debugId
85
+ };
86
+ };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.8.2';
2
+ export const version = '2.9.1';