@datadog/mobile-react-native 2.8.1 → 2.9.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 (93) 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/DdSdk.mm +4 -1
  5. package/ios/Sources/SdkVersion.swift +1 -1
  6. package/lib/commonjs/metro/debugIdResolver.js +35 -0
  7. package/lib/commonjs/metro/debugIdResolver.js.map +1 -0
  8. package/lib/commonjs/metro/metro.d.js +2 -0
  9. package/lib/commonjs/metro/metro.d.js.map +1 -0
  10. package/lib/commonjs/metro/plugin/debugIdHelper.js +244 -0
  11. package/lib/commonjs/metro/plugin/debugIdHelper.js.map +1 -0
  12. package/lib/commonjs/metro/plugin/metroConfig.js +68 -0
  13. package/lib/commonjs/metro/plugin/metroConfig.js.map +1 -0
  14. package/lib/commonjs/metro/plugin/metroSerializer.js +143 -0
  15. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -0
  16. package/lib/commonjs/metro/plugin/types/expoTypes.js +6 -0
  17. package/lib/commonjs/metro/plugin/types/expoTypes.js.map +1 -0
  18. package/lib/commonjs/metro/plugin/types/metroTypes.js +6 -0
  19. package/lib/commonjs/metro/plugin/types/metroTypes.js.map +1 -0
  20. package/lib/commonjs/metro/plugin/utils.js +153 -0
  21. package/lib/commonjs/metro/plugin/utils.js.map +1 -0
  22. package/lib/commonjs/metro.js +19 -0
  23. package/lib/commonjs/metro.js.map +1 -0
  24. package/lib/commonjs/rum/DdRum.js +2 -1
  25. package/lib/commonjs/rum/DdRum.js.map +1 -1
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +1 -1
  27. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  28. package/lib/commonjs/utils/errorUtils.js +13 -1
  29. package/lib/commonjs/utils/errorUtils.js.map +1 -1
  30. package/lib/commonjs/version.js +1 -1
  31. package/lib/module/metro/debugIdResolver.js +30 -0
  32. package/lib/module/metro/debugIdResolver.js.map +1 -0
  33. package/lib/module/metro/metro.d.js +2 -0
  34. package/lib/module/metro/metro.d.js.map +1 -0
  35. package/lib/module/metro/plugin/debugIdHelper.js +225 -0
  36. package/lib/module/metro/plugin/debugIdHelper.js.map +1 -0
  37. package/lib/module/metro/plugin/metroConfig.js +61 -0
  38. package/lib/module/metro/plugin/metroConfig.js.map +1 -0
  39. package/lib/module/metro/plugin/metroSerializer.js +131 -0
  40. package/lib/module/metro/plugin/metroSerializer.js.map +1 -0
  41. package/lib/module/metro/plugin/types/expoTypes.js +2 -0
  42. package/lib/module/metro/plugin/types/expoTypes.js.map +1 -0
  43. package/lib/module/metro/plugin/types/metroTypes.js +2 -0
  44. package/lib/module/metro/plugin/types/metroTypes.js.map +1 -0
  45. package/lib/module/metro/plugin/utils.js +139 -0
  46. package/lib/module/metro/plugin/utils.js.map +1 -0
  47. package/lib/module/metro.js +8 -0
  48. package/lib/module/metro.js.map +1 -0
  49. package/lib/module/rum/DdRum.js +2 -1
  50. package/lib/module/rum/DdRum.js.map +1 -1
  51. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
  52. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  53. package/lib/module/utils/errorUtils.js +11 -0
  54. package/lib/module/utils/errorUtils.js.map +1 -1
  55. package/lib/module/version.js +1 -1
  56. package/lib/typescript/metro/debugIdResolver.d.ts +3 -0
  57. package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -0
  58. package/lib/typescript/metro/plugin/debugIdHelper.d.ts +99 -0
  59. package/lib/typescript/metro/plugin/debugIdHelper.d.ts.map +1 -0
  60. package/lib/typescript/metro/plugin/metroConfig.d.ts +35 -0
  61. package/lib/typescript/metro/plugin/metroConfig.d.ts.map +1 -0
  62. package/lib/typescript/metro/plugin/metroSerializer.d.ts +29 -0
  63. package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -0
  64. package/lib/typescript/metro/plugin/types/expoTypes.d.ts +31 -0
  65. package/lib/typescript/metro/plugin/types/expoTypes.d.ts.map +1 -0
  66. package/lib/typescript/metro/plugin/types/metroTypes.d.ts +33 -0
  67. package/lib/typescript/metro/plugin/types/metroTypes.d.ts.map +1 -0
  68. package/lib/typescript/metro/plugin/utils.d.ts +36 -0
  69. package/lib/typescript/metro/plugin/utils.d.ts.map +1 -0
  70. package/lib/typescript/metro.d.ts +6 -0
  71. package/lib/typescript/metro.d.ts.map +1 -0
  72. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  73. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
  74. package/lib/typescript/utils/errorUtils.d.ts +1 -0
  75. package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
  76. package/lib/typescript/version.d.ts +1 -1
  77. package/package.json +17 -3
  78. package/scripts/copy-debug-id.js +52 -0
  79. package/src/metro/__tests__/__utils__/serializerUtils.ts +100 -0
  80. package/src/metro/__tests__/metro.test.ts +382 -0
  81. package/src/metro/debugIdResolver.ts +36 -0
  82. package/src/metro/metro.d.ts +73 -0
  83. package/src/metro/plugin/debugIdHelper.ts +279 -0
  84. package/src/metro/plugin/metroConfig.ts +97 -0
  85. package/src/metro/plugin/metroSerializer.ts +173 -0
  86. package/src/metro/plugin/types/expoTypes.ts +64 -0
  87. package/src/metro/plugin/types/metroTypes.ts +94 -0
  88. package/src/metro/plugin/utils.ts +177 -0
  89. package/src/metro.ts +14 -0
  90. package/src/rum/DdRum.ts +2 -1
  91. package/src/rum/instrumentation/DdRumErrorTracking.tsx +8 -2
  92. package/src/utils/errorUtils.ts +13 -0
  93. package/src/version.ts +1 -1
@@ -0,0 +1,225 @@
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
+ * Portions of this code are adapted from Sentry's Metro configuration:
7
+ * https://github.com/getsentry/sentry-react-native/blob/17c0c2e8913030e4826d055284a735efad637312/packages/core/src/js/tools/sentryMetroSerializer.ts
8
+ */
9
+
10
+ import { createHash } from 'crypto';
11
+ // eslint-disable-next-line import/no-extraneous-dependencies
12
+ import countLines from 'metro/src/lib/countLines';
13
+ import { createCountingSet } from './utils';
14
+
15
+ /**
16
+ * Regex to match the Debug ID comment in the bundle.
17
+ */
18
+ const DEBUG_ID_BUNDLE_REGEX = /\/\/\s?([#@])\s?debugId=([\d\-a-zA-Z]*$)/m;
19
+
20
+ /**
21
+ * Path name for the Debug ID Metro Virtual Module.
22
+ */
23
+ export const DEBUG_ID_MODULE_PATH = '__datadog_debugid__';
24
+
25
+ /**
26
+ * The initial placeholder for the injected Debug ID in the virtual module, replaced
27
+ * later by the actual Debug ID.
28
+ */
29
+ export const DEBUG_ID_PLACEHOLDER = '__datadog_debug_id_placeholder__';
30
+
31
+ /**
32
+ * A comment that can be found at the end of the JS bundle, to specify the URL of the sourcemap.
33
+ * Ref: https://tc39.es/ecma426/#sec-linking-inline
34
+ */
35
+ export const SOURCE_MAP_COMMENT = '//# sourceMappingURL=';
36
+
37
+ /**
38
+ * The comment that will be appended at the end of the JS bundle, to specify the Debug ID.
39
+ * Ref: https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md
40
+ */
41
+ export const DEBUG_ID_COMMENT = '//# debugId=';
42
+
43
+ /**
44
+ * The Debug ID is injected in the virtual module as a plain string, using this prefix.
45
+ * It is later retrieved by searching it in the bundle, using the same prefix.
46
+ */
47
+ const DEBUG_ID_METADATA_PREFIX = 'datadog-debug-id-';
48
+
49
+ /**
50
+ * Creates a virtual module to embed a debug ID into the bundle.
51
+ * @param debugId - the debug ID to inject into the bundle, or a placeholder.
52
+ * @returns The Debug ID virtual module.
53
+ */
54
+ export const createDebugIdModule = debugId => {
55
+ let debugIdCode = createDebugIdSnippet(debugId);
56
+ return {
57
+ setSource: code => {
58
+ debugIdCode = code;
59
+ },
60
+ dependencies: new Map(),
61
+ getSource: () => Buffer.from(debugIdCode),
62
+ inverseDependencies: createCountingSet(),
63
+ path: DEBUG_ID_MODULE_PATH,
64
+ output: [{
65
+ type: 'js/script/virtual',
66
+ data: {
67
+ code: debugIdCode,
68
+ lineCount: countLines(debugIdCode),
69
+ map: []
70
+ }
71
+ }]
72
+ };
73
+ };
74
+
75
+ /**
76
+ * Injects the debug ID module into the list of pre-modules,
77
+ * ensuring that the prelude module (if present) stays at the top
78
+ * to correctly measure bundle startup time.
79
+ */
80
+ export const addDebugIdModule = (preModules, debugIdModule) => {
81
+ const result = [...preModules];
82
+ const hasPrelude = result.length > 0 && result[0]?.path === '__prelude__';
83
+ if (hasPrelude) {
84
+ result.splice(1, 0, debugIdModule);
85
+ } else {
86
+ result.unshift(debugIdModule);
87
+ }
88
+ return result;
89
+ };
90
+
91
+ /**
92
+ * Creates a minified JavaScript snippet that exposes the provided Debug ID
93
+ * on the global scope at runtime.
94
+ *
95
+ * @param debugId - The Debug ID to be injected into the global scope.
96
+ * @returns A minified JavaScript string that performs the injection.
97
+ */
98
+ export const createDebugIdSnippet = debugId => {
99
+ return `var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]="${debugId}",_datadogDebugIdMeta="${DEBUG_ID_METADATA_PREFIX}${debugId}")}catch(e){}`;
100
+ };
101
+
102
+ /**
103
+ * Extracts the Debug ID from a bundle source string by locating the pattern
104
+ * "{@link DEBUG_ID_METADATA_PREFIX}`[DEBUG-ID]`"
105
+ *
106
+ * @param code - The source code of the bundle to search within.
107
+ * @returns The extracted Debug ID, or `undefined` if not found.
108
+ */
109
+ export const getDebugIdFromBundleSource = code => {
110
+ const match = code.match(new RegExp(`${DEBUG_ID_METADATA_PREFIX}([0-9a-fA-F]{8}\\b-(?:[0-9a-fA-F]{4}\\b-){3}[0-9a-fA-F]{12})`));
111
+ return match ? match[1] : undefined;
112
+ };
113
+
114
+ /**
115
+ * Creates a unique Debug ID from the given bundle, by using the content of its modules.
116
+ * @param bundle The bundle to create the Debug ID from.
117
+ * @returns The computed Debug ID.
118
+ */
119
+ export const createDebugIdFromBundle = bundle => {
120
+ const hash = createHash('md5');
121
+ hash.update(bundle.pre);
122
+ for (const [, code] of bundle.modules) {
123
+ hash.update(code);
124
+ }
125
+ hash.update(bundle.post);
126
+ return createDebugIdFromString(hash.digest('hex'));
127
+ };
128
+
129
+ /**
130
+ * Creates a unique Debug ID from the given string.
131
+ * Ref: https://github.com/expo/expo/blob/94a124894a355ad6e24f4bac5144986380686157/packages/%40expo/metro-config/src/serializer/debugId.ts#L15
132
+ * @param str The string to create the Debug ID from.
133
+ * @returns The computed Debug ID.
134
+ */
135
+ export const createDebugIdFromString = str => {
136
+ const md5sum = createHash('md5');
137
+ md5sum.update(str);
138
+ const md5Hash = md5sum.digest('hex');
139
+
140
+ // Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)
141
+ // RFC 4122 section 4.4
142
+ const v4variant = ['8', '9', 'a', 'b'][md5Hash.substring(16, 17).charCodeAt(0) % 4];
143
+ return `${md5Hash.substring(0, 8)}-${md5Hash.substring(8, 12)}-4${md5Hash.substring(13, 16)}-${v4variant}${md5Hash.substring(17, 20)}-${md5Hash.substring(20)}`.toLowerCase();
144
+ };
145
+
146
+ /**
147
+ * Injects the given debug ID in the given code, and returns the modified code.
148
+ *
149
+ * It looks for a specific placeholder defined in {@link DEBUG_ID_PLACEHOLDER}, and replaces
150
+ * all its occurences with the given Debug ID.
151
+ * @param code The code to inject the Debug ID into.
152
+ * @param debugId The Debug ID to inject.
153
+ * @returns The modified code with the injected Debug ID.
154
+ */
155
+ export const injectDebugIdInCode = (code, debugId) => {
156
+ return code.replace(new RegExp(DEBUG_ID_PLACEHOLDER, 'g'), debugId);
157
+ };
158
+
159
+ /**
160
+ * Injects the given Debug ID in the given code (as a comment at the end of the file), and in the
161
+ * given sourcemap (as a top-level JSON property).
162
+ * @param debugId The Debug ID to inject.
163
+ * @param code The code to inject the Debug ID in.
164
+ * @param sourcemap The sourcemap to inject the Debug ID in.
165
+ * @returns The modified {@link MetroBundleWithMap} with the Debug ID
166
+ */
167
+ export const injectDebugIdInCodeAndSourceMap = (debugId, code, sourcemap) => {
168
+ let codeWithDebugId = code;
169
+ if (_isDebugIdInBundle(debugId, code)) {
170
+ codeWithDebugId = _replaceDebugIdInBundle(debugId, code);
171
+ } else {
172
+ codeWithDebugId = _insertDebugIdCommentInBundle(debugId, code);
173
+ }
174
+
175
+ // Insert the Debug ID as a top-level property of the sourcemap
176
+ const bundleMap = JSON.parse(sourcemap);
177
+ bundleMap['debugId'] = debugId;
178
+ return {
179
+ code: codeWithDebugId,
180
+ map: JSON.stringify(bundleMap)
181
+ };
182
+ };
183
+
184
+ /**
185
+ * [INTERNAL] Checks if the debug ID is in the bundle, and prints a warning if it does not match the given one.
186
+ */
187
+ export const _isDebugIdInBundle = (debugId, bundleCode) => {
188
+ const match = bundleCode.match(DEBUG_ID_BUNDLE_REGEX);
189
+ if (!match || match.length < 2) {
190
+ return false;
191
+ }
192
+ if (match[2] !== debugId) {
193
+ console.warn('[DATADOG METRO PLUGIN] The debug ID found in the file does not match the calculated debug ID.');
194
+ }
195
+ return true;
196
+ };
197
+
198
+ /**
199
+ * Checks if the virtual Debug ID module exists in the given modules.
200
+ * @param modules - The list of modules in which to look for the Debug ID.
201
+ * @returns `true` if the Debug ID module exists, `false` otherwise.
202
+ */
203
+ export const checkIfDebugIdModuleExists = modules => modules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) !== -1;
204
+
205
+ /**
206
+ * [INTERNAL] Replaces the existing Debug ID comment in the bundle with a new one, containing the given Debug ID.
207
+ */
208
+ export const _replaceDebugIdInBundle = (debugId, bundleCode) => {
209
+ return bundleCode.replace(DEBUG_ID_BUNDLE_REGEX, `${DEBUG_ID_COMMENT}${debugId}`);
210
+ };
211
+
212
+ /**
213
+ * [INTERNAL] Inserts the Debug ID comment in the bundle in the correct position.
214
+ */
215
+ export const _insertDebugIdCommentInBundle = (debugId, bundleCode) => {
216
+ const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;
217
+ const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);
218
+ if (indexOfSourceMapComment === -1) {
219
+ return `${bundleCode}\n${debugIdComment}`;
220
+ }
221
+ const before = bundleCode.substring(0, indexOfSourceMapComment);
222
+ const after = bundleCode.substring(indexOfSourceMapComment);
223
+ return `${before}${debugIdComment}\n${after}`;
224
+ };
225
+ //# sourceMappingURL=debugIdHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createHash","countLines","createCountingSet","DEBUG_ID_BUNDLE_REGEX","DEBUG_ID_MODULE_PATH","DEBUG_ID_PLACEHOLDER","SOURCE_MAP_COMMENT","DEBUG_ID_COMMENT","DEBUG_ID_METADATA_PREFIX","createDebugIdModule","debugId","debugIdCode","createDebugIdSnippet","setSource","code","dependencies","Map","getSource","Buffer","from","inverseDependencies","path","output","type","data","lineCount","map","addDebugIdModule","preModules","debugIdModule","result","hasPrelude","length","splice","unshift","getDebugIdFromBundleSource","match","RegExp","undefined","createDebugIdFromBundle","bundle","hash","update","pre","modules","post","createDebugIdFromString","digest","str","md5sum","md5Hash","v4variant","substring","charCodeAt","toLowerCase","injectDebugIdInCode","replace","injectDebugIdInCodeAndSourceMap","sourcemap","codeWithDebugId","_isDebugIdInBundle","_replaceDebugIdInBundle","_insertDebugIdCommentInBundle","bundleMap","JSON","parse","stringify","bundleCode","console","warn","checkIfDebugIdModuleExists","findIndex","module","debugIdComment","indexOfSourceMapComment","lastIndexOf","before","after"],"sourceRoot":"../../../../src","sources":["metro/plugin/debugIdHelper.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAQ,QAAQ;AACnC;AACA,OAAOC,UAAU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AC,EAAE;IAChC,OAAO,GAAGP,UAAU,KAAKM,cAAc,EAAE;EAC7C;EACA,MAAMG,MAAM,GAAGT,UAAU,CAACf,SAAS,CAAC,CAAC,EAAEsB,uBAAuB,CAAC;EAC/D,MAAMG,KAAK,GAAGV,UAAU,CAACf,SAAS,CAACsB,uBAAuB,CAAC;EAC3D,OAAO,GAAGE,MAAM,GAAGH,cAAc,KAAKI,KAAK,EAAE;AACjD,CAAC","ignoreList":[]}
@@ -0,0 +1,61 @@
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
+ import { createDatadogMetroSerializer, unstable_beforeAssetSerializationPlugin } from './metroSerializer';
8
+ import { getDefaultExpoConfig } from './utils';
9
+
10
+ /**
11
+ * Custom Datadog Metro Configuration.
12
+ */
13
+
14
+ /**
15
+ * Extends the Metro bundler configuration to integrate with Datadog.
16
+ *
17
+ * *Note: If a custom serializer is used and `config.useDebugId` is set to `true` (as it is by default),
18
+ * you must manually invoke `options.datadogBundleCallback` within the serializer.*
19
+ */
20
+ export function withDatadogMetroConfig(config) {
21
+ let newConfig = config;
22
+ if (config.useDebugId ?? true) {
23
+ newConfig = withDatadogDebugId(config);
24
+ }
25
+ return {
26
+ ...newConfig,
27
+ transformer: {
28
+ ...newConfig.transformer
29
+ }
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Extends the Expo configuration to integrate with Datadog.
35
+ * @param config
36
+ * @returns
37
+ */
38
+ export function getDatadogExpoConfig(projectRoot, options = {}) {
39
+ const plugins = options.unstable_beforeAssetSerializationPlugins ?? [];
40
+ const datadogOptions = {
41
+ ...options,
42
+ unstable_beforeAssetSerializationPlugins: [...plugins, unstable_beforeAssetSerializationPlugin]
43
+ };
44
+ return (options.getDefaultConfig ?? getDefaultExpoConfig)(projectRoot, datadogOptions);
45
+ }
46
+
47
+ /**
48
+ * Extends the Metro bundler configuration by enabling Debug ID injection.
49
+ * Ref: https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md
50
+ */
51
+ export function withDatadogDebugId(config) {
52
+ const customSerializer = createDatadogMetroSerializer(config.serializer?.customSerializer || undefined);
53
+ return {
54
+ ...config,
55
+ serializer: {
56
+ ...config.serializer,
57
+ customSerializer
58
+ }
59
+ };
60
+ }
61
+ //# sourceMappingURL=metroConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createDatadogMetroSerializer","unstable_beforeAssetSerializationPlugin","getDefaultExpoConfig","withDatadogMetroConfig","config","newConfig","useDebugId","withDatadogDebugId","transformer","getDatadogExpoConfig","projectRoot","options","plugins","unstable_beforeAssetSerializationPlugins","datadogOptions","getDefaultConfig","customSerializer","serializer","undefined"],"sourceRoot":"../../../../src","sources":["metro/plugin/metroConfig.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAGA,SACIA,4BAA4B,EAC5BC,uCAAuC,QACpC,mBAAmB;AAM1B,SAASC,oBAAoB,QAAQ,SAAS;;AAE9C;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CAClCC,MAA+C,EACpC;EACX,IAAIC,SAAS,GAAGD,MAAM;EAEtB,IAAIA,MAAM,CAACE,UAAU,IAAI,IAAI,EAAE;IAC3BD,SAAS,GAAGE,kBAAkB,CAACH,MAAM,CAAC;EAC1C;EAEA,OAAO;IACH,GAAGC,SAAS;IACZG,WAAW,EAAE;MACT,GAAGH,SAAS,CAACG;IACjB;EACJ,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAChCC,WAAmB,EACnBC,OAAwD,GAAG,CAAC,CAAC,EACzC;EACpB,MAAMC,OAAO,GAAGD,OAAO,CAACE,wCAAwC,IAAI,EAAE;EACtE,MAAMC,cAAoC,GAAG;IACzC,GAAGH,OAAO;IACVE,wCAAwC,EAAE,CACtC,GAAGD,OAAO,EACVX,uCAAuC;EAE/C,CAAC;EAED,OAAO,CAACU,OAAO,CAACI,gBAAgB,IAAIb,oBAAoB,EACpDQ,WAAW,EACXI,cACJ,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASP,kBAAkBA,CAACH,MAAmB,EAAe;EACjE,MAAMY,gBAAgB,GAAGhB,4BAA4B,CACjDI,MAAM,CAACa,UAAU,EAAED,gBAAgB,IAAIE,SAC3C,CAA2B;EAE3B,OAAO;IACH,GAAGd,MAAM;IACTa,UAAU,EAAE;MACR,GAAGb,MAAM,CAACa,UAAU;MACpBD;IACJ;EACJ,CAAC;AACL","ignoreList":[]}
@@ -0,0 +1,131 @@
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
+ * Portions of this code are adapted from Sentry's Metro configuration:
7
+ * https://github.com/getsentry/sentry-react-native/blob/17c0c2e8913030e4826d055284a735efad637312/packages/core/src/js/tools/sentryMetroSerializer.ts
8
+ */
9
+
10
+ // eslint-disable-next-line import/no-extraneous-dependencies
11
+ import baseJSBundle from 'metro/src/DeltaBundler/Serializers/baseJSBundle';
12
+ // eslint-disable-next-line import/no-extraneous-dependencies
13
+ import bundleToString from 'metro/src/lib/bundleToString';
14
+ import { DEBUG_ID_PLACEHOLDER, addDebugIdModule, checkIfDebugIdModuleExists, createDebugIdFromBundle, createDebugIdModule, getDebugIdFromBundleSource, injectDebugIdInCode, injectDebugIdInCodeAndSourceMap } from './debugIdHelper';
15
+ import { convertSerializerOutput as getMetroBundleWithMap, getSortedModules, metroSourceMapString } from './utils';
16
+
17
+ /**
18
+ * Creates a Metro serializer that adds a Debug ID module to the bundle.
19
+ * This module injects the Debug ID at runtime, making it globally accessible.
20
+ *
21
+ * @param customSerializer - Optional custom {@link MetroSerializer}. If provided, you are responsible
22
+ * for invoking `options.datadogBundleCallback` within it.
23
+ */
24
+ export const createDatadogMetroSerializer = customSerializer => {
25
+ const serializer = customSerializer || createDefaultMetroSerializer();
26
+ return async (entryPoint, preModules, graph, options) => {
27
+ // Skip for hot reload mode
28
+ if (graph.transformOptions.hot) {
29
+ return serializer(entryPoint, preModules, graph, options);
30
+ }
31
+
32
+ // Make sure we don't add the Debug ID module twice
33
+ if (checkIfDebugIdModuleExists(preModules)) {
34
+ return serializer(entryPoint, preModules, graph, options);
35
+ }
36
+
37
+ // Create a virtual module to inject the Debug ID in a globally accessible property
38
+ const debugIdModule = createDebugIdModule(DEBUG_ID_PLACEHOLDER);
39
+
40
+ // Set the datadogBundleCallback in the options, to be used later by the serializer
41
+ options.datadogBundleCallback = createDatadogBundleCallback(debugIdModule);
42
+
43
+ // Add the Debug ID virtual module to the pre-modules
44
+ const preModulesWithDebugId = addDebugIdModule(preModules, debugIdModule);
45
+
46
+ // Run serializer
47
+ const serializerOutput = serializer(entryPoint, preModulesWithDebugId, graph, options);
48
+
49
+ // Get serialized code and sourcemap
50
+ const {
51
+ code,
52
+ map
53
+ } = await getMetroBundleWithMap(serializerOutput);
54
+
55
+ // Retrieve the Debug ID, previously injected as a snippet of code in a virtual module by `datadogBundleCallback`.
56
+ const debugId = getDebugIdFromBundleSource(code);
57
+ if (!debugId) {
58
+ throw new Error('[DATADOG METRO PLUGIN] Debug ID was not found in the bundle. Call `options.datadogBundleCallback` if you are using a custom serializer.');
59
+ }
60
+
61
+ // Inject the Debug ID as a comment in the bundle, and as a top-level property in the sourcemap.
62
+ const result = injectDebugIdInCodeAndSourceMap(debugId, code, map);
63
+ return result;
64
+ };
65
+ };
66
+
67
+ /**
68
+ * Creates a Metro Bundle Serializer like metro does by default, while also calling the datadogBundleCallback.
69
+ * https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/Server.js#L272-L307
70
+ */
71
+ export const createDefaultMetroSerializer = () => {
72
+ return (entryPoint, preModules, graph, options) => {
73
+ // Default metro bundle
74
+ // https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js#L25
75
+ let bundle = baseJSBundle(entryPoint, preModules, graph, options);
76
+
77
+ // Modify the bundle through the datadogBundleCallback, if we are not in hot-reload mode
78
+ if (options.datadogBundleCallback && !graph.transformOptions.hot) {
79
+ bundle = options.datadogBundleCallback(bundle);
80
+ }
81
+
82
+ // Retrieves the processed code from the bundle
83
+ const {
84
+ code
85
+ } = bundleToString(bundle);
86
+
87
+ // If we are in hot-reload mode, we skip sourcemaps generation, and only return the code.
88
+ if (graph.transformOptions.hot) {
89
+ return code;
90
+ }
91
+
92
+ // Force generation of sourcemaps
93
+ const map = metroSourceMapString([...preModules, ...getSortedModules(graph, options)], {
94
+ processModuleFilter: options.processModuleFilter,
95
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList
96
+ });
97
+ return {
98
+ code,
99
+ map
100
+ };
101
+ };
102
+ };
103
+
104
+ /**
105
+ * Creates a callback used to transform the given bundle by injecting the Debug ID snippet.
106
+ * @param debugIdModule - The virtual Debug ID module
107
+ * @returns The bundle callback
108
+ */
109
+ export const createDatadogBundleCallback = debugIdModule => {
110
+ return bundle => {
111
+ const debugId = createDebugIdFromBundle(bundle);
112
+ const code = debugIdModule.getSource().toString();
113
+ debugIdModule.setSource(injectDebugIdInCode(code, debugId));
114
+ bundle.pre = injectDebugIdInCode(bundle.pre, debugId);
115
+ return bundle;
116
+ };
117
+ };
118
+
119
+ /**
120
+ * Adds Debug ID module for runtime injection, used for Expo.
121
+ */
122
+ export function unstable_beforeAssetSerializationPlugin({
123
+ premodules,
124
+ debugId
125
+ }) {
126
+ if (!debugId || checkIfDebugIdModuleExists(premodules)) {
127
+ return premodules;
128
+ }
129
+ return [...addDebugIdModule(premodules, createDebugIdModule(debugId))];
130
+ }
131
+ //# sourceMappingURL=metroSerializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["baseJSBundle","bundleToString","DEBUG_ID_PLACEHOLDER","addDebugIdModule","checkIfDebugIdModuleExists","createDebugIdFromBundle","createDebugIdModule","getDebugIdFromBundleSource","injectDebugIdInCode","injectDebugIdInCodeAndSourceMap","convertSerializerOutput","getMetroBundleWithMap","getSortedModules","metroSourceMapString","createDatadogMetroSerializer","customSerializer","serializer","createDefaultMetroSerializer","entryPoint","preModules","graph","options","transformOptions","hot","debugIdModule","datadogBundleCallback","createDatadogBundleCallback","preModulesWithDebugId","serializerOutput","code","map","debugId","Error","result","bundle","processModuleFilter","shouldAddToIgnoreList","getSource","toString","setSource","pre","unstable_beforeAssetSerializationPlugin","premodules"],"sourceRoot":"../../../../src","sources":["metro/plugin/metroSerializer.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAOA,YAAY,MAAM,iDAAiD;AAC1E;AACA,OAAOC,cAAc,MAAM,8BAA8B;AAEzD,SACIC,oBAAoB,EACpBC,gBAAgB,EAChBC,0BAA0B,EAC1BC,uBAAuB,EACvBC,mBAAmB,EACnBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,+BAA+B,QAC5B,iBAAiB;AAUxB,SACIC,uBAAuB,IAAIC,qBAAqB,EAChDC,gBAAgB,EAChBC,oBAAoB,QACjB,SAAS;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,4BAA4B,GACrCC,gBAAkC,IACT;EACzB,MAAMC,UAAU,GAAGD,gBAAgB,IAAIE,4BAA4B,CAAC,CAAC;EACrE,OAAO,OAAOC,UAAU,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,KAAK;IACrD;IACA,IAAID,KAAK,CAACE,gBAAgB,CAACC,GAAG,EAAE;MAC5B,OAAOP,UAAU,CAACE,UAAU,EAAEC,UAAU,EAAEC,KAAK,EAAEC,OAAO,CAAC;IAC7D;;IAEA;IACA,IAAIjB,0BAA0B,CAACe,UAAU,CAAC,EAAE;MACxC,OAAOH,UAA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Id,KAAK,CAACE,gBAAgB,CAACC,GAAG,EAAE;MAC5B,OAAOM,IAAI;IACf;;IAEA;IACA,MAAMC,GAAG,GAAGjB,oBAAoB,CAC5B,CAAC,GAAGM,UAAU,EAAE,GAAGP,gBAAgB,CAACQ,KAAK,EAAEC,OAAO,CAAC,CAAC,EACpD;MACIc,mBAAmB,EAAEd,OAAO,CAACc,mBAAmB;MAChDC,qBAAqB,EAAEf,OAAO,CAACe;IACnC,CACJ,CAAC;IAED,OAAO;MAAEP,IAAI;MAAEC;IAAI,CAAC;EACxB,CAAC;AACL,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMJ,2BAA2B,GACpCF,aAAmC,IAClC;EACD,OAAQU,MAAc,IAAK;IACvB,MAAMH,OAAO,GAAG1B,uBAAuB,CAAC6B,MAAM,CAAC;IAC/C,MAAML,IAAI,GAAGL,aAAa,CAACa,SAAS,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;IACjDd,aAAa,CAACe,SAAS,CAAC/B,mBAAmB,CAACqB,IAAI,EAAEE,OAAO,CAAC,CAAC;IAC3DG,MAAM,CAACM,GAAG,GAAGhC,mBAAmB,CAAC0B,MAAM,CAACM,GAAG,EAAET,OAAO,CAAC;IACrD,OAAOG,MAAM;EACjB,CAAC;AACL,CAAC;;AAED;AACA;AACA;AACA,OAAO,SAASO,uCAAuCA,CAAC;EACpDC,UAAU;EACVX;AAKJ,CAAC,EAAY;EACT,IAAI,CAACA,OAAO,IAAI3B,0BAA0B,CAACsC,UAAU,CAAC,EAAE;IACpD,OAAOA,UAAU;EACrB;EACA,OAAO,CAAC,GAAGvC,gBAAgB,CAACuC,UAAU,EAAEpC,mBAAmB,CAACyB,OAAO,CAAC,CAAC,CAAC;AAC1E","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=expoTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["metro/plugin/types/expoTypes.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=metroTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../../src","sources":["metro/plugin/types/metroTypes.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,139 @@
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
+
11
+ /**
12
+ * Lazy-init reference for {@link createCountingSet} resolved function.
13
+ */
14
+ let createCountingSetFunc;
15
+
16
+ /**
17
+ * Lazy-init reference for {@link metroSourceMapString} resolved function.
18
+ */
19
+ let sourceMapStringFunc;
20
+
21
+ /**
22
+ * Lazy-init reference for {@link getDefaultExpoConfig} resolved function.
23
+ */
24
+ let getDefaultExpoConfigFunc;
25
+
26
+ /**
27
+ * This function ensures that modules in source maps are sorted in the same
28
+ * order as in a plain JS bundle.
29
+ *
30
+ * https://github.com/facebook/metro/blob/76413561abb3757285e0cb0305f1f9f616fa2b6c/packages/metro/src/Server.js#L1086C1-L1095C7
31
+ */
32
+ export function getSortedModules(graph, {
33
+ createModuleId
34
+ }) {
35
+ const modules = [...graph.dependencies.values()];
36
+
37
+ // Assign IDs to modules in a consistent order
38
+ for (const module of modules) {
39
+ createModuleId(module.path);
40
+ }
41
+ // Sort by IDs
42
+ return modules.sort((a, b) => createModuleId(a.path) - createModuleId(b.path));
43
+ }
44
+
45
+ /**
46
+ * CountingSet was added in Metro 0.71.2 - a modified `Set` that only deletes items when the
47
+ * number of `delete(item)` calls matches the number of `add(item)` calls.
48
+ *
49
+ * https://github.com/facebook/metro/commit/fc29a1177f883144674cf85a813b58567f69d545
50
+ */
51
+ export const createCountingSet = () => {
52
+ if (createCountingSetFunc) {
53
+ return createCountingSetFunc();
54
+ }
55
+ try {
56
+ createCountingSetFunc = () => {
57
+ const {
58
+ default: MetroCountingSet
59
+ // eslint-disable-next-line global-require, import/no-extraneous-dependencies, @typescript-eslint/no-var-requires
60
+ } = require('metro/src/lib/CountingSet');
61
+ return new MetroCountingSet();
62
+ };
63
+ } catch (_) {
64
+ createCountingSetFunc = () => new Set();
65
+ }
66
+ return createCountingSetFunc();
67
+ };
68
+ /**
69
+ * In Metro versions prior to v0.80.10, `sourceMapString` was exported as a default export.
70
+ * Starting with v0.80.10, it became a named export.
71
+ *
72
+ * @returns The resolved `sourceMapString` function, of type {@link SourceMapString}
73
+ */
74
+ export const metroSourceMapString = (modules, options) => {
75
+ if (sourceMapStringFunc) {
76
+ return sourceMapStringFunc(modules, options);
77
+ }
78
+ if (typeof sourceMapString === 'function') {
79
+ sourceMapStringFunc = sourceMapString;
80
+ } else if (sourceMapString && typeof sourceMapString === 'object' && typeof sourceMapString['sourceMapString'] === 'function') {
81
+ sourceMapStringFunc = sourceMapString.sourceMapString;
82
+ }
83
+ if (!sourceMapStringFunc) {
84
+ throw new Error("[DATADOG METRO PLUGIN] Cannot find sourceMapString function in 'metro/src/DeltaBundler/Serializers/sourceMapString'");
85
+ }
86
+ return sourceMapStringFunc(modules, options);
87
+ };
88
+
89
+ /**
90
+ * Converts the serializer result of type {@link MetroSerializerOutput} to {@link MetroBundleWithMap}.
91
+ */
92
+ export const convertSerializerOutput = async output => {
93
+ const parse = obj => {
94
+ // Plain String
95
+ if (typeof obj === 'string') {
96
+ return {
97
+ code: obj,
98
+ map: '{}'
99
+ };
100
+ }
101
+
102
+ // Dictionary
103
+ if ('map' in obj) {
104
+ return {
105
+ code: obj.code,
106
+ map: obj.map
107
+ };
108
+ }
109
+ return undefined;
110
+ };
111
+ const value = parse(output);
112
+ if (!value) {
113
+ return parse(await output) ?? {
114
+ code: '',
115
+ map: '{}'
116
+ };
117
+ } else {
118
+ return value;
119
+ }
120
+ };
121
+
122
+ /**
123
+ * Gets the default Expo configuration options.
124
+ */
125
+ export const getDefaultExpoConfig = (projectRoot, options) => {
126
+ if (!getDefaultExpoConfigFunc) {
127
+ try {
128
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
129
+ const metroConfig = require('expo/metro-config');
130
+ getDefaultExpoConfigFunc = metroConfig.getDefaultConfig;
131
+ return metroConfig.getDefaultConfig(projectRoot, options);
132
+ } catch (e) {
133
+ throw new Error('Cannot load `expo/metro-config`. Make sure Expo is properly set up in your project.');
134
+ }
135
+ } else {
136
+ return getDefaultExpoConfigFunc(projectRoot, options);
137
+ }
138
+ };
139
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["sourceMapString","createCountingSetFunc","sourceMapStringFunc","getDefaultExpoConfigFunc","getSortedModules","graph","createModuleId","modules","dependencies","values","module","path","sort","a","b","createCountingSet","default","MetroCountingSet","require","_","Set","metroSourceMapString","options","Error","convertSerializerOutput","output","parse","obj","code","map","undefined","value","getDefaultExpoConfig","projectRoot","metroConfig","getDefaultConfig","e"],"sourceRoot":"../../../../src","sources":["metro/plugin/utils.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAOA,eAAe,MAAM,oDAAoD;AAChF;;AAWA;AACA;AACA;AACA,IAAIC,qBAA8D;;AAElE;AACA;AACA;AACA,IAAIC,mBAAgD;;AAEpD;AACA;AACA;AACA,IAAIC,wBAKW;;AAEf;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC5BC,KAAoB,EACpB;EAAEC;AAA6D,CAAC,EAClC;EAC9B,MAAMC,OAAO,GAAG,CAAC,GAAGF,KAAK,CAACG,YAAY,CAACC,MAAM,CAAC,CAAC,CAAC;;EAEhD;EACA,KAAK,MAAMC,MAAM,IAAIH,OAAO,EAAE;IAC1BD,cAAc,CAACI,MAAM,CA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,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAME,uBAAuB,GAAG,MACnCC,MAA6B,IACC;EAC9B,MAAMC,KAAK,GAAIC,GAA0B,IAAK;IAC1C;IACA,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;MACzB,OAAO;QAAEC,IAAI,EAAED,GAAG;QAAEE,GAAG,EAAE;MAAK,CAAC;IACnC;;IAEA;IACA,IAAI,KAAK,IAAIF,GAAG,EAAE;MACd,OAAO;QAAEC,IAAI,EAAED,GAAG,CAACC,IAAI;QAAEC,GAAG,EAAEF,GAAG,CAACE;MAAI,CAAC;IAC3C;IAEA,OAAOC,SAAS;EACpB,CAAC;EAED,MAAMC,KAAK,GAAGL,KAAK,CAACD,MAAM,CAAC;EAC3B,IAAI,CAACM,KAAK,EAAE;IACR,OAAOL,KAAK,CAAC,MAAMD,MAAM,CAAC,IAAI;MAAEG,IAAI,EAAE,EAAE;MAAEC,GAAG,EAAE;IAAK,CAAC;EACzD,CAAC,MAAM;IACH,OAAOE,KAAK;EAChB;AACJ,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAGA,CAChCC,WAAmB,EACnBX,OAA6B,KACN;EACvB,IAAI,CAACnB,wBAAwB,EAAE;IAC3B,IAAI;MACA;MACA,MAAM+B,WAAW,GAAGhB,OAAO,CAAC,mBAAmB,CAAC;MAChDf,wBAAwB,GAAG+B,WAAW,CAACC,gBAAgB;MACvD,OAAOD,WAAW,CAACC,gBAAgB,CAACF,WAAW,EAAEX,OAAO,CAAC;IAC7D,CAAC,CAAC,OAAOc,CAAC,EAAE;MACR,MAAM,IAAIb,KAAK,CACX,qFACJ,CAAC;IACL;EACJ,CAAC,MAAM;IACH,OAAOpB,wBAAwB,CAAC8B,WAAW,EAAEX,OAAO,CAAC;EACzD;AACJ,CAAC","ignoreList":[]}
@@ -0,0 +1,8 @@
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 { withDatadogMetroConfig, getDatadogExpoConfig } from './metro/plugin/metroConfig';
7
+ export { withDatadogMetroConfig, getDatadogExpoConfig };
8
+ //# sourceMappingURL=metro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["withDatadogMetroConfig","getDatadogExpoConfig"],"sourceRoot":"../../src","sources":["metro.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,SACIA,sBAAsB,EACtBC,oBAAoB,QACjB,4BAA4B;AAInC,SAASD,sBAAsB,EAAEC,oBAAoB","ignoreList":[]}
@@ -10,6 +10,7 @@ import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNative
10
10
  import { DdSdk } from '../sdk/DdSdk';
11
11
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
12
12
  import { validateContext } from '../utils/argsUtils';
13
+ import { getErrorContext } from '../utils/errorUtils';
13
14
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
14
15
  import { DdAttributes } from './DdAttributes';
15
16
  import { generateActionEventMapper } from './eventMappers/actionEventMapper';
@@ -101,7 +102,7 @@ class DdRumWrapper {
101
102
  message,
102
103
  source,
103
104
  stacktrace,
104
- context: validateContext(context),
105
+ context: getErrorContext(validateContext(context)),
105
106
  timestampMs,
106
107
  fingerprint: fingerprint ?? ''
107
108
  });