@datadog/webpack-plugin 2.3.3-dev-2 → 2.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.
package/dist/src/index.js CHANGED
@@ -28,16 +28,16 @@ const logPriority = {
28
28
  const getLoggerFactory = (build, logLevel = "warn") => (name) => {
29
29
  const log = (text, type = "debug") => {
30
30
  let color = chalk.dim;
31
- let logFn2 = console.log;
31
+ let logFn = console.log;
32
32
  if (type === "error") {
33
33
  color = chalk.red;
34
- logFn2 = console.error;
34
+ logFn = console.error;
35
35
  } else if (type === "warn") {
36
36
  color = chalk.yellow;
37
- logFn2 = console.warn;
37
+ logFn = console.warn;
38
38
  } else if (type === "info") {
39
39
  color = chalk.cyan;
40
- logFn2 = console.log;
40
+ logFn = console.log;
41
41
  }
42
42
  const prefix = `[${type}|${name}]`;
43
43
  const content = typeof text === "string" ? text : JSON.stringify(text, null, 2);
@@ -49,17 +49,19 @@ const getLoggerFactory = (build, logLevel = "warn") => (name) => {
49
49
  build.warnings.push(content);
50
50
  }
51
51
  if (logPriority[type] >= logPriority[logLevel]) {
52
- logFn2(`${color(prefix)} ${content}`);
52
+ logFn(`${color(prefix)} ${content}`);
53
53
  }
54
54
  };
55
- const logFn = (text, type = "debug") => {
56
- log(text, type);
55
+ return {
56
+ getLogger: (subName) => {
57
+ const logger = getLoggerFactory(build, logLevel);
58
+ return logger(`${name}:${subName}`);
59
+ },
60
+ error: (text) => log(text, "error"),
61
+ warn: (text) => log(text, "warn"),
62
+ info: (text) => log(text, "info"),
63
+ debug: (text) => log(text, "debug")
57
64
  };
58
- logFn.error = (text) => log(text, "error");
59
- logFn.warn = (text) => log(text, "warn");
60
- logFn.info = (text) => log(text, "info");
61
- logFn.debug = (text) => log(text, "debug");
62
- return logFn;
63
65
  };
64
66
  const getContext = ({
65
67
  options,
@@ -90,7 +92,6 @@ const getContext = ({
90
92
  inject: (item) => {
91
93
  injections.push(item);
92
94
  },
93
- getLogger: getLoggerFactory(build, options.logLevel),
94
95
  start: Date.now(),
95
96
  version
96
97
  };
@@ -105,9 +106,6 @@ const validateOptions$2 = (options = {}) => {
105
106
  };
106
107
  };
107
108
 
108
- const CONFIG_KEY$1 = "rum";
109
- const PLUGIN_NAME$4 = "datadog-rum-plugin";
110
-
111
109
  const decomposePath = (options, context, sourcemapFilePath) => {
112
110
  if (path.extname(sourcemapFilePath) !== ".map") {
113
111
  throw new Error(`The file ${chalk.green.bold(sourcemapFilePath)} is not a sourcemap.`);
@@ -430,7 +428,7 @@ const upload = async (payloads, options, context, log) => {
430
428
  "."
431
429
  )
432
430
  };
433
- log(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
431
+ log.debug(`Queuing ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
434
432
  addPromises.push(
435
433
  queue.add(async () => {
436
434
  try {
@@ -444,10 +442,10 @@ const upload = async (payloads, options, context, log) => {
444
442
  ${error.message}
445
443
  Retrying ${attempt}/${NB_RETRIES}`;
446
444
  warnings.push(warningMessage);
447
- log(warningMessage, "warn");
445
+ log.warn(warningMessage);
448
446
  }
449
447
  });
450
- log(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
448
+ log.debug(`Sent ${green(metadata.sourcemap)} | ${green(metadata.file)}`);
451
449
  } catch (e) {
452
450
  errors.push({ metadata, error: e });
453
451
  if (options.bailOnError === true) {
@@ -479,13 +477,13 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
479
477
  const errors = payloads.map((payload) => payload.errors).flat();
480
478
  const warnings = payloads.map((payload) => payload.warnings).flat();
481
479
  if (warnings.length > 0) {
482
- log(`Warnings while preparing payloads:
483
- - ${warnings.join("\n - ")}`, "warn");
480
+ log.warn(`Warnings while preparing payloads:
481
+ - ${warnings.join("\n - ")}`);
484
482
  }
485
483
  if (errors.length > 0) {
486
484
  const errorMsg = `Failed to prepare payloads, aborting upload :
487
485
  - ${errors.join("\n - ")}`;
488
- log(errorMsg, "error");
486
+ log.error(errorMsg);
489
487
  if (options.bailOnError === true) {
490
488
  throw new Error(errorMsg);
491
489
  }
@@ -497,9 +495,8 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
497
495
  context,
498
496
  log
499
497
  );
500
- log(
501
- `Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}.`,
502
- "info"
498
+ log.info(
499
+ `Done uploading ${green(sourcemaps.length.toString())} sourcemaps in ${green(formatDuration(Date.now() - start))}.`
503
500
  );
504
501
  if (uploadErrors.length > 0) {
505
502
  const listOfErrors = ` - ${uploadErrors.map(({ metadata: fileMetadata, error }) => {
@@ -510,14 +507,14 @@ const sendSourcemaps = async (sourcemaps, options, context, log) => {
510
507
  }).join("\n - ")}`;
511
508
  const errorMsg = `Failed to upload some sourcemaps:
512
509
  ${listOfErrors}`;
513
- log(errorMsg, "error");
510
+ log.error(errorMsg);
514
511
  if (options.bailOnError === true) {
515
512
  throw new Error(errorMsg);
516
513
  }
517
514
  }
518
515
  if (uploadWarnings.length > 0) {
519
- log(`Warnings while uploading sourcemaps:
520
- - ${warnings.join("\n - ")}`, "warn");
516
+ log.warn(`Warnings while uploading sourcemaps:
517
+ - ${warnings.join("\n - ")}`);
521
518
  }
522
519
  };
523
520
 
@@ -529,19 +526,22 @@ const uploadSourcemaps = async (options, context, log) => {
529
526
  Uploading ${green(sourcemaps.length.toString())} sourcemaps with configuration:
530
527
  ${configurationString}
531
528
  `;
532
- log(summary, "info");
529
+ log.info(summary);
533
530
  await sendSourcemaps(sourcemaps, options.sourcemaps, context, log);
534
531
  };
535
532
 
533
+ const CONFIG_KEY$1 = "rum";
534
+ const PLUGIN_NAME$5 = "datadog-rum-plugin";
535
+
536
536
  const defaultIntakeUrl = `https://sourcemap-intake.${process.env.DATADOG_SITE || "datadoghq.com"}/api/v2/srcmap`;
537
537
  const validateOptions$1 = (config, log) => {
538
538
  const errors = [];
539
539
  const sourcemapsResults = validateSourcemapsOptions(config);
540
540
  errors.push(...sourcemapsResults.errors);
541
541
  if (errors.length) {
542
- log(`
543
- - ${errors.join("\n - ")}`, "error");
544
- throw new Error(`Invalid configuration for ${PLUGIN_NAME$4}.`);
542
+ log.error(`
543
+ - ${errors.join("\n - ")}`);
544
+ throw new Error(`Invalid configuration for ${PLUGIN_NAME$5}.`);
545
545
  }
546
546
  const toReturn = {
547
547
  ...config[CONFIG_KEY$1],
@@ -599,8 +599,7 @@ const validateSourcemapsOptions = (config) => {
599
599
  return toReturn;
600
600
  };
601
601
 
602
- const getPlugins$2 = (opts, context) => {
603
- const log = context.getLogger(PLUGIN_NAME$4);
602
+ const getPlugins$1 = (opts, context, log) => {
604
603
  const rumOptions = validateOptions$1(opts, log);
605
604
  return [
606
605
  {
@@ -619,7 +618,7 @@ const getPlugins$2 = (opts, context) => {
619
618
  };
620
619
 
621
620
  const CONFIG_KEY = "telemetry";
622
- const PLUGIN_NAME$3 = `datadog-telemetry-plugin`;
621
+ const PLUGIN_NAME$4 = `datadog-telemetry-plugin`;
623
622
 
624
623
  const filterTreeMetrics = (metric) => (
625
624
  // Remove tree metrics because way too verbose
@@ -735,9 +734,8 @@ const getValueContext = (args) => {
735
734
  }));
736
735
  };
737
736
 
738
- const getPlugins$1 = (plugins) => {
739
- const metrics = [];
740
- metrics.push({
737
+ const addPluginMetrics = (plugins, metrics) => {
738
+ metrics.add({
741
739
  metric: "plugins.count",
742
740
  type: "count",
743
741
  value: plugins.size,
@@ -754,67 +752,54 @@ const getPlugins$1 = (plugins) => {
754
752
  hookDuration += duration;
755
753
  pluginDuration += duration;
756
754
  }
757
- metrics.push(
758
- {
759
- metric: "plugins.hooks.duration",
760
- type: "duration",
761
- value: hookDuration,
762
- tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
763
- },
764
- {
765
- metric: "plugins.hooks.increment",
766
- type: "count",
767
- value: hook.values.length,
768
- tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
769
- }
770
- );
771
- }
772
- metrics.push(
773
- {
774
- metric: "plugins.duration",
755
+ metrics.add({
756
+ metric: "plugins.hooks.duration",
775
757
  type: "duration",
776
- value: pluginDuration,
777
- tags: [`pluginName:${plugin.name}`]
778
- },
779
- {
780
- metric: "plugins.increment",
758
+ value: hookDuration,
759
+ tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
760
+ }).add({
761
+ metric: "plugins.hooks.increment",
781
762
  type: "count",
782
- value: pluginCount,
783
- tags: [`pluginName:${plugin.name}`]
784
- }
785
- );
763
+ value: hook.values.length,
764
+ tags: [`pluginName:${plugin.name}`, `hookName:${hook.name}`]
765
+ });
766
+ }
767
+ metrics.add({
768
+ metric: "plugins.duration",
769
+ type: "duration",
770
+ value: pluginDuration,
771
+ tags: [`pluginName:${plugin.name}`]
772
+ }).add({
773
+ metric: "plugins.increment",
774
+ type: "count",
775
+ value: pluginCount,
776
+ tags: [`pluginName:${plugin.name}`]
777
+ });
786
778
  }
787
- return metrics;
788
779
  };
789
- const getLoaders = (loaders) => {
790
- const metrics = [];
791
- metrics.push({
780
+ const addLoaderMetrics = (loaders, metrics) => {
781
+ metrics.add({
792
782
  metric: "loaders.count",
793
783
  type: "count",
794
784
  value: loaders.size,
795
785
  tags: []
796
786
  });
797
787
  for (const loader of loaders.values()) {
798
- metrics.push(
799
- {
800
- metric: "loaders.duration",
801
- type: "duration",
802
- value: loader.duration,
803
- tags: [`loaderName:${loader.name}`]
804
- },
805
- {
806
- metric: "loaders.increment",
807
- type: "count",
808
- value: loader.increment,
809
- tags: [`loaderName:${loader.name}`]
810
- }
811
- );
788
+ metrics.add({
789
+ metric: "loaders.duration",
790
+ type: "duration",
791
+ value: loader.duration,
792
+ tags: [`loaderName:${loader.name}`]
793
+ }).add({
794
+ metric: "loaders.increment",
795
+ type: "count",
796
+ value: loader.increment,
797
+ tags: [`loaderName:${loader.name}`]
798
+ });
812
799
  }
813
- return metrics;
814
800
  };
815
801
 
816
- const getUniversalMetrics = (globalContext) => {
817
- const metrics = [];
802
+ const addUniversalMetrics = (globalContext, metrics) => {
818
803
  const inputs = globalContext.build.inputs || [];
819
804
  const outputs = globalContext.build.outputs || [];
820
805
  const entries = globalContext.build.entries || [];
@@ -847,40 +832,34 @@ const getUniversalMetrics = (globalContext) => {
847
832
  assetsPerInput.get(input.filepath).push(output.name);
848
833
  }
849
834
  }
850
- metrics.push(
851
- {
852
- metric: "assets.count",
853
- type: "count",
854
- value: outputs.length,
855
- tags: []
856
- },
857
- {
858
- metric: "entries.count",
859
- type: "count",
860
- value: entries.length,
861
- tags: []
862
- },
863
- {
864
- metric: "errors.count",
865
- type: "count",
866
- value: nbErrors,
867
- tags: []
868
- },
869
- {
870
- metric: "modules.count",
871
- type: "count",
872
- value: inputs.length,
873
- tags: []
874
- },
875
- {
876
- metric: "warnings.count",
877
- type: "count",
878
- value: nbWarnings,
879
- tags: []
880
- }
881
- );
835
+ metrics.add({
836
+ metric: "assets.count",
837
+ type: "count",
838
+ value: outputs.length,
839
+ tags: []
840
+ }).add({
841
+ metric: "entries.count",
842
+ type: "count",
843
+ value: entries.length,
844
+ tags: []
845
+ }).add({
846
+ metric: "errors.count",
847
+ type: "count",
848
+ value: nbErrors,
849
+ tags: []
850
+ }).add({
851
+ metric: "modules.count",
852
+ type: "count",
853
+ value: inputs.length,
854
+ tags: []
855
+ }).add({
856
+ metric: "warnings.count",
857
+ type: "count",
858
+ value: nbWarnings,
859
+ tags: []
860
+ });
882
861
  if (duration) {
883
- metrics.push({
862
+ metrics.add({
884
863
  metric: "compilation.duration",
885
864
  type: "duration",
886
865
  value: duration,
@@ -899,26 +878,22 @@ const getUniversalMetrics = (globalContext) => {
899
878
  ...assetsPerInput.get(input.filepath).map((assetName) => `assetName:${assetName}`)
900
879
  );
901
880
  }
902
- metrics.push(
903
- {
904
- metric: "modules.size",
905
- type: "size",
906
- value: input.size,
907
- tags
908
- },
909
- {
910
- metric: "modules.dependencies",
911
- type: "count",
912
- value: input.dependencies.size,
913
- tags
914
- },
915
- {
916
- metric: "modules.dependents",
917
- type: "count",
918
- value: input.dependents.size,
919
- tags
920
- }
921
- );
881
+ metrics.add({
882
+ metric: "modules.size",
883
+ type: "size",
884
+ value: input.size,
885
+ tags
886
+ }).add({
887
+ metric: "modules.dependencies",
888
+ type: "count",
889
+ value: input.dependencies.size,
890
+ tags
891
+ }).add({
892
+ metric: "modules.dependents",
893
+ type: "count",
894
+ value: input.dependents.size,
895
+ tags
896
+ });
922
897
  }
923
898
  for (const output of outputs) {
924
899
  const tags = [`assetName:${output.name}`, `assetType:${output.type}`];
@@ -928,72 +903,69 @@ const getUniversalMetrics = (globalContext) => {
928
903
  ...entriesPerAsset.get(cleanAssetName).map((entryName) => `entryName:${entryName}`)
929
904
  );
930
905
  }
931
- metrics.push(
932
- {
933
- metric: "assets.size",
934
- type: "size",
935
- value: output.size,
936
- tags
937
- },
938
- {
939
- metric: "assets.modules.count",
940
- type: "count",
941
- value: output.inputs.length,
942
- tags
943
- }
944
- );
906
+ metrics.add({
907
+ metric: "assets.size",
908
+ type: "size",
909
+ value: output.size,
910
+ tags
911
+ }).add({
912
+ metric: "assets.modules.count",
913
+ type: "count",
914
+ value: output.inputs.length,
915
+ tags
916
+ });
945
917
  }
946
918
  for (const entry of entries) {
947
919
  const tags = [`entryName:${entry.name}`];
948
- metrics.push(
949
- {
950
- metric: "entries.size",
951
- type: "size",
952
- value: entry.size,
953
- tags
954
- },
955
- {
956
- metric: "entries.modules.count",
957
- type: "count",
958
- value: entry.inputs.length,
959
- tags
960
- },
961
- {
962
- metric: "entries.assets.count",
963
- type: "count",
964
- value: entry.outputs.length,
965
- tags
966
- }
967
- );
920
+ metrics.add({
921
+ metric: "entries.size",
922
+ type: "size",
923
+ value: entry.size,
924
+ tags
925
+ }).add({
926
+ metric: "entries.modules.count",
927
+ type: "count",
928
+ value: entry.inputs.length,
929
+ tags
930
+ }).add({
931
+ metric: "entries.assets.count",
932
+ type: "count",
933
+ value: entry.outputs.length,
934
+ tags
935
+ });
968
936
  }
969
937
  return metrics;
970
938
  };
971
- const getMetrics = (globalContext, optionsDD, report) => {
972
- const metrics = [];
939
+ const addMetrics = (globalContext, optionsDD, metricsToSend, report) => {
940
+ const metrics = /* @__PURE__ */ new Set();
973
941
  if (report) {
974
942
  const { timings } = report;
975
943
  if (timings) {
976
944
  if (timings.tapables) {
977
- metrics.push(...getPlugins$1(timings.tapables));
945
+ addPluginMetrics(timings.tapables, metrics);
978
946
  }
979
947
  if (timings.loaders) {
980
- metrics.push(...getLoaders(timings.loaders));
948
+ addLoaderMetrics(timings.loaders, metrics);
981
949
  }
982
950
  }
983
951
  }
984
- metrics.push(...getUniversalMetrics(globalContext));
985
- const metricsToSend = metrics.map((m) => {
986
- let metric = m;
952
+ addUniversalMetrics(globalContext, metrics);
953
+ for (const metric of metrics) {
987
954
  if (optionsDD.filters?.length) {
955
+ let filteredMetric = metric;
988
956
  for (const filter of optionsDD.filters) {
989
- if (metric) {
990
- metric = filter(metric);
957
+ if (!filteredMetric) {
958
+ break;
991
959
  }
960
+ filteredMetric = filter(metric);
992
961
  }
962
+ if (filteredMetric) {
963
+ metricsToSend.add(getMetric(filteredMetric, optionsDD));
964
+ }
965
+ } else {
966
+ metricsToSend.add(getMetric(metric, optionsDD));
993
967
  }
994
- return metric ? getMetric(metric, optionsDD) : null;
995
- }).filter((m) => m !== null);
996
- return metricsToSend;
968
+ }
997
969
  };
998
970
 
999
971
  const outputFiles = async (data, outputOptions, log, cwd) => {
@@ -1027,37 +999,35 @@ const outputFiles = async (data, outputOptions, log, cwd) => {
1027
999
  }
1028
1000
  };
1029
1001
  }
1030
- if (metrics && files.metrics) {
1031
- filesToWrite.metrics = { content: metrics };
1002
+ if (files.metrics) {
1003
+ filesToWrite.metrics = { content: Array.from(metrics) };
1032
1004
  }
1033
1005
  const proms = Object.entries(filesToWrite).map(async ([filename, file]) => {
1034
1006
  const start = Date.now();
1035
- log(`Start writing ${filename}.json.`);
1007
+ log.debug(`Start writing ${filename}.json.`);
1036
1008
  try {
1037
1009
  await outputJson(path.join(outputPath, `${filename}.json`), file.content);
1038
- log(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
1010
+ log.debug(`Wrote ${filename}.json in ${formatDuration(Date.now() - start)}`);
1039
1011
  } catch (e) {
1040
- log(
1041
- `Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}`,
1042
- "error"
1012
+ log.error(
1013
+ `Failed to write ${filename}.json in ${formatDuration(Date.now() - start)}`
1043
1014
  );
1044
1015
  errors[filename] = e;
1045
1016
  }
1046
1017
  });
1047
1018
  await Promise.all(proms);
1048
- log(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
1019
+ log.debug(`Wrote files in ${formatDuration(Date.now() - startWriting)}.`);
1049
1020
  const fileErrored = Object.keys(errors);
1050
1021
  if (fileErrored.length) {
1051
- log(
1022
+ log.error(
1052
1023
  `Couldn't write files.
1053
1024
  ${fileErrored.map(
1054
1025
  (file) => ` - ${file}: ${errors[file].toString()}`
1055
- )}`,
1056
- "error"
1026
+ )}`
1057
1027
  );
1058
1028
  }
1059
1029
  } catch (e) {
1060
- log(`Couldn't write files. ${e}`, "error");
1030
+ log.error(`Couldn't write files. ${e}`);
1061
1031
  }
1062
1032
  };
1063
1033
 
@@ -1448,32 +1418,43 @@ const outputTexts = (globalContext, log, report) => {
1448
1418
  valuesToPrint.push(...getAssetsValues(globalContext));
1449
1419
  valuesToPrint.push(...getGeneralValues(globalContext));
1450
1420
  const outputString = renderValues(valuesToPrint);
1451
- log(outputString, "info");
1421
+ log.info(outputString);
1452
1422
  };
1453
1423
 
1454
1424
  const sendMetrics = (metrics, auth, log) => {
1455
1425
  const startSending = Date.now();
1456
1426
  if (!auth.apiKey) {
1457
- log(`Won't send metrics to Datadog: missing API Key.`, "warn");
1427
+ log.warn(`Won't send metrics to Datadog: missing API Key.`);
1458
1428
  return;
1459
1429
  }
1460
- if (!metrics || metrics.length === 0) {
1461
- log(`No metrics to send.`, "warn");
1430
+ if (!metrics.size) {
1431
+ log.warn(`No metrics to send.`);
1462
1432
  return;
1463
1433
  }
1464
- const metricsNames = [...new Set(metrics.map((m) => m.metric))].sort().map((name) => `${name} - ${metrics.filter((m) => m.metric === name).length}`);
1465
- log(`
1466
- Sending ${metrics.length} metrics.
1434
+ const metricIterations = /* @__PURE__ */ new Map();
1435
+ for (const metric of metrics) {
1436
+ if (!metricIterations.has(metric.metric)) {
1437
+ metricIterations.set(metric.metric, 0);
1438
+ }
1439
+ metricIterations.set(metric.metric, metricIterations.get(metric.metric) + 1);
1440
+ }
1441
+ const metricsNames = Array.from(metricIterations.entries()).map(
1442
+ ([name, count]) => `${name} - ${count}`
1443
+ );
1444
+ log.debug(`
1445
+ Sending ${metrics.size} metrics.
1467
1446
  Metrics:
1468
1447
  - ${metricsNames.join("\n - ")}`);
1469
1448
  return doRequest({
1470
1449
  method: "POST",
1471
1450
  url: `${auth.endPoint}/api/v1/series?api_key=${auth.apiKey}`,
1472
- getData: () => ({ data: JSON.stringify({ series: metrics }) })
1451
+ getData: () => ({
1452
+ data: JSON.stringify({ series: Array.from(metrics) })
1453
+ })
1473
1454
  }).then(() => {
1474
- log(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
1455
+ log.debug(`Sent metrics in ${formatDuration(Date.now() - startSending)}.`);
1475
1456
  }).catch((e) => {
1476
- log(`Error sending metrics ${e}`, "error");
1457
+ log.error(`Error sending metrics ${e}`);
1477
1458
  });
1478
1459
  };
1479
1460
 
@@ -1489,7 +1470,7 @@ const wrapPlugins = (build, context) => {
1489
1470
  };
1490
1471
  });
1491
1472
  for (const plugin of plugins) {
1492
- if (plugin.name.includes(PLUGIN_NAME$3)) {
1473
+ if (plugin.name.includes(PLUGIN_NAME$4)) {
1493
1474
  continue;
1494
1475
  }
1495
1476
  const oldSetup = plugin.setup;
@@ -1567,7 +1548,7 @@ const getEsbuildPlugin$1 = (bundlerContext, globalContext, logger) => {
1567
1548
  wrapPlugins(build, globalContext.cwd);
1568
1549
  build.onEnd(async (result) => {
1569
1550
  if (!result.metafile) {
1570
- logger("Missing metafile, can't proceed with modules data.", "warn");
1551
+ logger.warn("Missing metafile, can't proceed with modules data.");
1571
1552
  return;
1572
1553
  }
1573
1554
  const { plugins, modules } = getResults();
@@ -1792,7 +1773,7 @@ class Tapables {
1792
1773
  if (hook._fakeHook) {
1793
1774
  return;
1794
1775
  }
1795
- if (tapableName.includes(PLUGIN_NAME$3)) {
1776
+ if (tapableName.includes(PLUGIN_NAME$4)) {
1796
1777
  return;
1797
1778
  }
1798
1779
  if (!this.hooks[tapableName]) {
@@ -1833,10 +1814,10 @@ class Tapables {
1833
1814
  }
1834
1815
  }
1835
1816
 
1836
- const getWebpackPlugin$1 = (bundlerContext, globalContext) => {
1817
+ const getWebpackPlugin = (bundlerContext, globalContext) => {
1837
1818
  return async (compiler) => {
1838
1819
  globalContext.build.start = Date.now();
1839
- const HOOK_OPTIONS = { name: PLUGIN_NAME$3 };
1820
+ const HOOK_OPTIONS = { name: PLUGIN_NAME$4 };
1840
1821
  const tapables = new Tapables(globalContext.cwd);
1841
1822
  const loaders = new Loaders(globalContext.cwd);
1842
1823
  tapables.throughHooks(compiler);
@@ -1866,19 +1847,19 @@ const getWebpackPlugin$1 = (bundlerContext, globalContext) => {
1866
1847
  const helpers$2 = {
1867
1848
  filters: defaultFilters
1868
1849
  };
1869
- const getPlugins = (options, context) => {
1850
+ const getPlugins = (options, context, logger) => {
1870
1851
  let realBuildEnd = 0;
1871
1852
  const bundlerContext = {
1872
1853
  start: Date.now()
1873
1854
  };
1874
1855
  const telemetryOptions = validateOptions(options);
1875
- const logger = context.getLogger(PLUGIN_NAME$3);
1876
1856
  const plugins = [];
1877
1857
  const legacyPlugin = {
1878
- name: PLUGIN_NAME$3,
1858
+ name: PLUGIN_NAME$4,
1879
1859
  enforce: "pre",
1880
1860
  esbuild: getEsbuildPlugin$1(bundlerContext, context, logger),
1881
- webpack: getWebpackPlugin$1(bundlerContext, context)
1861
+ webpack: getWebpackPlugin(bundlerContext, context),
1862
+ rspack: getWebpackPlugin(bundlerContext, context)
1882
1863
  };
1883
1864
  const universalPlugin = {
1884
1865
  name: "datadog-universal-telemetry-plugin",
@@ -1894,9 +1875,9 @@ const getPlugins = (options, context) => {
1894
1875
  context.build.end = Date.now();
1895
1876
  context.build.duration = context.build.end - context.build.start;
1896
1877
  context.build.writeDuration = context.build.end - realBuildEnd;
1897
- const metrics = [];
1878
+ const metrics = /* @__PURE__ */ new Set();
1898
1879
  const optionsDD = getOptionsDD(telemetryOptions);
1899
- metrics.push(...getMetrics(context, optionsDD, bundlerContext.report));
1880
+ addMetrics(context, optionsDD, metrics, bundlerContext.report);
1900
1881
  await outputFiles(
1901
1882
  { report: bundlerContext.report, metrics },
1902
1883
  telemetryOptions.output,
@@ -1961,11 +1942,15 @@ const getEsbuildPlugin = (context, log) => {
1961
1942
  const entrypoints = build.initialOptions.entryPoints;
1962
1943
  const entryNames = getEntryNames(entrypoints, context);
1963
1944
  build.onEnd((result) => {
1964
- context.build.errors.push(...result.errors.map((err) => err.text));
1965
- context.build.warnings.push(...result.warnings.map((err) => err.text));
1945
+ for (const error of result.errors) {
1946
+ context.build.errors.push(error.text);
1947
+ }
1948
+ for (const warning of result.warnings) {
1949
+ context.build.warnings.push(warning.text);
1950
+ }
1966
1951
  const warn = (warning) => {
1967
1952
  context.build.warnings.push(warning);
1968
- log(warning, "warn");
1953
+ log.warn(warning);
1969
1954
  };
1970
1955
  if (!result.metafile) {
1971
1956
  warn("Missing metafile from build result.");
@@ -2212,7 +2197,7 @@ const getRollupPlugin = (context, log) => {
2212
2197
  const reportOutputsIndexed = {};
2213
2198
  const warn = (warning) => {
2214
2199
  context.build.warnings.push(warning);
2215
- log(warning, "warn");
2200
+ log.warn(warning);
2216
2201
  };
2217
2202
  for (const [filepath, { dependencies, dependents }] of Object.entries(importsReport)) {
2218
2203
  for (const dependency of dependencies) {
@@ -2362,14 +2347,14 @@ const getRollupPlugin = (context, log) => {
2362
2347
  };
2363
2348
  };
2364
2349
 
2365
- const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2350
+ const getXpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2366
2351
  const inputs = [];
2367
2352
  const outputs = [];
2368
2353
  const entries = [];
2369
- const warnings = [];
2370
2354
  const reportInputsIndexed = /* @__PURE__ */ new Map();
2371
2355
  const reportOutputsIndexed = /* @__PURE__ */ new Map();
2372
2356
  const modulesPerFile = /* @__PURE__ */ new Map();
2357
+ const moduleIndex = /* @__PURE__ */ new Map();
2373
2358
  const tempSourcemaps = [];
2374
2359
  const tempDeps = /* @__PURE__ */ new Map();
2375
2360
  const isModuleSupported = (moduleIdentifier) => {
@@ -2379,83 +2364,148 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2379
2364
  );
2380
2365
  };
2381
2366
  const warn = (warning) => {
2382
- warnings.push(warning);
2383
- log(warning, "warn");
2367
+ context.build.warnings.push(warning);
2368
+ log.warn(warning);
2384
2369
  };
2385
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
2386
- compilation.hooks.finishModules.tap(PLUGIN_NAME, (finishedModules) => {
2387
- const getModuleFromDep = (dep) => {
2388
- return compilation.moduleGraph ? compilation.moduleGraph.getModule(dep) : dep.module;
2389
- };
2390
- for (const module of finishedModules) {
2391
- const moduleIdentifier = module.identifier();
2392
- const dependencies = new Set(
2393
- [...module.dependencies, ...module.blocks.flatMap((b) => b.dependencies)].filter(
2394
- (dep) => (
2395
- // Ignore side effects.
2396
- dep.type !== "harmony side effect evaluation" && // Ignore those we can't identify.
2397
- getModuleFromDep(dep)?.identifier() && // Only what we support.
2398
- isModuleSupported(getModuleFromDep(dep)?.identifier()) && // Don't add itself as a dependency.
2399
- getModuleFromDep(dep)?.identifier() !== moduleIdentifier
2400
- )
2401
- ).map((dep) => {
2402
- return getModuleFromDep(dep)?.identifier();
2403
- }).filter(Boolean)
2404
- );
2405
- if (!isModuleSupported(moduleIdentifier)) {
2406
- continue;
2407
- }
2408
- for (const depIdentifier of dependencies) {
2409
- const depDeps = tempDeps.get(depIdentifier) || {
2410
- dependencies: /* @__PURE__ */ new Set(),
2411
- dependents: /* @__PURE__ */ new Set()
2412
- };
2413
- depDeps.dependents.add(moduleIdentifier);
2414
- tempDeps.set(depIdentifier, depDeps);
2415
- }
2416
- const moduleDeps = tempDeps.get(moduleIdentifier) || {
2417
- dependents: /* @__PURE__ */ new Set(),
2418
- dependencies: /* @__PURE__ */ new Set()
2419
- };
2420
- for (const moduleDep of dependencies) {
2421
- moduleDeps.dependencies.add(moduleDep);
2370
+ const getKeysToIndex = (mod) => {
2371
+ const values = {
2372
+ identifier: mod.identifier()
2373
+ };
2374
+ if ("resource" in mod && typeof mod.resource === "string") {
2375
+ values.resource = mod.resource;
2376
+ }
2377
+ if ("request" in mod && typeof mod.request === "string") {
2378
+ values.request = mod.request;
2379
+ }
2380
+ if ("rawRequest" in mod && typeof mod.rawRequest === "string") {
2381
+ values.rawRequest = mod.rawRequest;
2382
+ }
2383
+ if ("userRequest" in mod && typeof mod.userRequest === "string") {
2384
+ values.userRequest = mod.userRequest;
2385
+ }
2386
+ const keysToIndex = /* @__PURE__ */ new Set();
2387
+ for (const [key, value] of Object.entries(values)) {
2388
+ if (!value) {
2389
+ continue;
2390
+ }
2391
+ if (moduleIndex.has(value)) {
2392
+ warn(`Module ${mod.identifier()} is already indexed by ${key}.`);
2393
+ if (moduleIndex.get(value) !== mod) {
2394
+ warn(`Module ${mod.identifier()} is indexed with a different value.`);
2422
2395
  }
2423
- tempDeps.set(moduleIdentifier, moduleDeps);
2424
- const file = {
2425
- size: module.size() || 0,
2426
- name: cleanName(context, moduleIdentifier),
2427
- dependencies: /* @__PURE__ */ new Set(),
2428
- dependents: /* @__PURE__ */ new Set(),
2429
- filepath: moduleIdentifier,
2430
- type: getType(moduleIdentifier)
2431
- };
2432
- inputs.push(file);
2433
- reportInputsIndexed.set(moduleIdentifier, file);
2396
+ } else {
2397
+ keysToIndex.add(value);
2434
2398
  }
2435
- for (const input of inputs) {
2436
- const depsReport = tempDeps.get(input.filepath);
2437
- if (!depsReport) {
2438
- warn(`Could not find dependency report for ${input.name}`);
2439
- continue;
2399
+ }
2400
+ return keysToIndex;
2401
+ };
2402
+ const getAllDependencies = (module, dependencies = []) => {
2403
+ if ("dependencies" in module) {
2404
+ for (const dependency of module.dependencies) {
2405
+ dependencies.push(dependency);
2406
+ getAllDependencies(dependency, dependencies);
2407
+ }
2408
+ }
2409
+ if ("blocks" in module) {
2410
+ for (const block of module.blocks) {
2411
+ getAllDependencies(block, dependencies);
2412
+ }
2413
+ }
2414
+ return dependencies;
2415
+ };
2416
+ const getModuleFromDep = (mod, dep) => {
2417
+ if ("request" in dep && dep.request) {
2418
+ if (moduleIndex.has(dep.request)) {
2419
+ return moduleIndex.get(dep.request);
2420
+ }
2421
+ if (mod.context && moduleIndex.has(getAbsolutePath(mod.context, dep.request))) {
2422
+ return moduleIndex.get(getAbsolutePath(mod.context, dep.request));
2423
+ }
2424
+ }
2425
+ };
2426
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
2427
+ compilation.hooks.finishModules.tap(
2428
+ PLUGIN_NAME,
2429
+ (finishedModules) => {
2430
+ for (const module of finishedModules) {
2431
+ const keysToIndex = getKeysToIndex(module);
2432
+ for (const key of keysToIndex) {
2433
+ moduleIndex.set(key, module);
2434
+ }
2440
2435
  }
2441
- for (const dependency of depsReport.dependencies) {
2442
- const depInput = reportInputsIndexed.get(dependency);
2443
- if (!depInput) {
2444
- warn(`Could not find input of dependency ${dependency}`);
2436
+ for (const module of finishedModules) {
2437
+ const moduleIdentifier = module.identifier();
2438
+ const dependencies = new Set(
2439
+ getAllDependencies(module).map((dep) => {
2440
+ const mod = getModuleFromDep(module, dep);
2441
+ if (!mod || !mod.identifier()) {
2442
+ return false;
2443
+ }
2444
+ const identifier = mod.identifier();
2445
+ if (!isModuleSupported(identifier)) {
2446
+ return false;
2447
+ }
2448
+ if (identifier === moduleIdentifier) {
2449
+ return false;
2450
+ }
2451
+ return identifier;
2452
+ }).filter(Boolean)
2453
+ );
2454
+ if (!isModuleSupported(moduleIdentifier)) {
2445
2455
  continue;
2446
2456
  }
2447
- input.dependencies.add(depInput);
2457
+ for (const depIdentifier of dependencies) {
2458
+ const depDeps = tempDeps.get(depIdentifier) || {
2459
+ dependencies: /* @__PURE__ */ new Set(),
2460
+ dependents: /* @__PURE__ */ new Set()
2461
+ };
2462
+ depDeps.dependents.add(moduleIdentifier);
2463
+ tempDeps.set(depIdentifier, depDeps);
2464
+ }
2465
+ const moduleDeps = tempDeps.get(moduleIdentifier) || {
2466
+ dependents: /* @__PURE__ */ new Set(),
2467
+ dependencies: /* @__PURE__ */ new Set()
2468
+ };
2469
+ for (const moduleDep of dependencies) {
2470
+ moduleDeps.dependencies.add(moduleDep);
2471
+ }
2472
+ tempDeps.set(moduleIdentifier, moduleDeps);
2473
+ const file = {
2474
+ size: module.size() || 0,
2475
+ name: cleanName(context, moduleIdentifier),
2476
+ dependencies: /* @__PURE__ */ new Set(),
2477
+ dependents: /* @__PURE__ */ new Set(),
2478
+ filepath: moduleIdentifier,
2479
+ type: getType(moduleIdentifier)
2480
+ };
2481
+ inputs.push(file);
2482
+ reportInputsIndexed.set(moduleIdentifier, file);
2448
2483
  }
2449
- for (const dependent of depsReport.dependents) {
2450
- const depInput = reportInputsIndexed.get(dependent);
2451
- if (!depInput) {
2452
- warn(`Could not find input of dependent ${dependent}`);
2484
+ for (const input of inputs) {
2485
+ const depsReport = tempDeps.get(input.filepath);
2486
+ if (!depsReport) {
2487
+ warn(`Could not find dependency report for ${input.name}`);
2453
2488
  continue;
2454
2489
  }
2455
- input.dependents.add(depInput);
2490
+ for (const dependency of depsReport.dependencies) {
2491
+ const depInput = reportInputsIndexed.get(dependency);
2492
+ if (!depInput) {
2493
+ warn(`Could not find input of dependency ${dependency}`);
2494
+ continue;
2495
+ }
2496
+ input.dependencies.add(depInput);
2497
+ }
2498
+ for (const dependent of depsReport.dependents) {
2499
+ const depInput = reportInputsIndexed.get(dependent);
2500
+ if (!depInput) {
2501
+ warn(`Could not find input of dependent ${dependent}`);
2502
+ continue;
2503
+ }
2504
+ input.dependents.add(depInput);
2505
+ }
2456
2506
  }
2457
2507
  }
2458
- });
2508
+ );
2459
2509
  });
2460
2510
  compiler.hooks.afterEmit.tap(PLUGIN_NAME, (result) => {
2461
2511
  const chunks = result.chunks;
@@ -2468,7 +2518,13 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2468
2518
  const chunkGraph = result.chunkGraph;
2469
2519
  for (const chunk of chunks) {
2470
2520
  const files = getChunkFiles(chunk);
2471
- const chunkModules = (chunkGraph ? chunkGraph?.getChunkModules(chunk) : chunk.getModules()).flatMap((m) => {
2521
+ const chunkModules = (chunkGraph ? (
2522
+ // @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
2523
+ chunkGraph?.getChunkModules(chunk)
2524
+ ) : (
2525
+ // This one is for webpack 4.
2526
+ "getModules" in chunk && typeof chunk.getModules === "function" ? chunk.getModules() : []
2527
+ )).flatMap((m) => {
2472
2528
  return "modules" in m && Array.isArray(m.modules) ? m.modules.map((m2) => m2.identifier()) : m.identifier();
2473
2529
  }).filter(isModuleSupported);
2474
2530
  for (const file of files) {
@@ -2523,11 +2579,16 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2523
2579
  let size = 0;
2524
2580
  const entryFiles = entrypoint.chunks.flatMap(getChunkFiles);
2525
2581
  const entryFilename = entrypoint.chunks.filter(
2526
- (c) => (
2527
- // Webpack5 forces you to use the chunkGraph to get the modules.
2528
- chunkGraph ? chunkGraph.getNumberOfEntryModules(c) > 0 : c.hasEntryModule()
2582
+ (chunk) => chunkGraph ? (
2583
+ // @ts-expect-error: Reconciliating Webpack 4, Webpack 5 and Rspack is hard.
2584
+ chunkGraph.getChunkEntryModulesIterable(chunk)
2585
+ ) : (
2586
+ // This one is for webpack 4.
2587
+ "hasEntryModule" in chunk && typeof chunk.hasEntryModule === "function" ? chunk.hasEntryModule() : false
2529
2588
  )
2530
- ).flatMap((c) => Array.from(c.files))[0];
2589
+ ).flatMap((c) => Array.from(c.files)).filter(
2590
+ (f) => f.includes(name) || entrypoint.name && f.includes(entrypoint.name)
2591
+ ).find((f) => getType(f) === "js");
2531
2592
  for (const file2 of entryFiles) {
2532
2593
  const outputFound = reportOutputsIndexed.get(file2);
2533
2594
  if (!file2 || !outputFound) {
@@ -2550,23 +2611,27 @@ const getWebpackPlugin = (context, PLUGIN_NAME, log) => (compiler) => {
2550
2611
  };
2551
2612
  entries.push(file);
2552
2613
  }
2553
- context.build.errors.push(...result.errors.map((err) => err.message));
2554
- context.build.warnings.push(...warnings, ...result.warnings.map((err) => err.message));
2614
+ for (const error of result.errors) {
2615
+ context.build.errors.push(error.message);
2616
+ }
2617
+ for (const warning of result.warnings) {
2618
+ context.build.warnings.push(warning.message);
2619
+ }
2555
2620
  context.build.inputs = inputs;
2556
2621
  context.build.outputs = outputs;
2557
2622
  context.build.entries = entries;
2558
2623
  });
2559
2624
  };
2560
2625
 
2561
- const PLUGIN_NAME$2 = "datadog-build-report-plugin";
2562
- const getBuildReportPlugins = (context) => {
2563
- const log = context.getLogger(PLUGIN_NAME$2);
2626
+ const PLUGIN_NAME$3 = "datadog-build-report-plugin";
2627
+ const getBuildReportPlugins = (context, log) => {
2564
2628
  return [
2565
2629
  {
2566
- name: PLUGIN_NAME$2,
2630
+ name: PLUGIN_NAME$3,
2567
2631
  enforce: "post",
2568
2632
  esbuild: getEsbuildPlugin(context, log),
2569
- webpack: getWebpackPlugin(context, PLUGIN_NAME$2, log),
2633
+ rspack: getXpackPlugin(context, PLUGIN_NAME$3, log),
2634
+ webpack: getXpackPlugin(context, PLUGIN_NAME$3, log),
2570
2635
  // Vite and Rollup have the same API.
2571
2636
  vite: getRollupPlugin(context, log),
2572
2637
  rollup: getRollupPlugin(context, log)
@@ -2574,7 +2639,7 @@ const getBuildReportPlugins = (context) => {
2574
2639
  ];
2575
2640
  };
2576
2641
 
2577
- const PLUGIN_NAME$1 = "datadog-bundler-report-plugin";
2642
+ const PLUGIN_NAME$2 = "datadog-bundler-report-plugin";
2578
2643
  const rollupPlugin = (context) => ({
2579
2644
  options(options) {
2580
2645
  context.bundler.rawConfig = options;
@@ -2589,9 +2654,15 @@ const rollupPlugin = (context) => ({
2589
2654
  }
2590
2655
  }
2591
2656
  });
2657
+ const xpackPlugin = (context) => (compiler) => {
2658
+ context.bundler.rawConfig = compiler.options;
2659
+ if (compiler.options.output?.path) {
2660
+ context.bundler.outDir = compiler.options.output.path;
2661
+ }
2662
+ };
2592
2663
  const getBundlerReportPlugins = (globalContext) => {
2593
2664
  const bundlerReportPlugin = {
2594
- name: PLUGIN_NAME$1,
2665
+ name: PLUGIN_NAME$2,
2595
2666
  enforce: "pre",
2596
2667
  esbuild: {
2597
2668
  setup(build) {
@@ -2605,12 +2676,8 @@ const getBundlerReportPlugins = (globalContext) => {
2605
2676
  build.initialOptions.metafile = true;
2606
2677
  }
2607
2678
  },
2608
- webpack(compiler) {
2609
- globalContext.bundler.rawConfig = compiler.options;
2610
- if (compiler.options.output?.path) {
2611
- globalContext.bundler.outDir = compiler.options.output.path;
2612
- }
2613
- },
2679
+ webpack: xpackPlugin(globalContext),
2680
+ rspack: xpackPlugin(globalContext),
2614
2681
  // Vite and Rollup have the same API.
2615
2682
  vite: rollupPlugin(globalContext),
2616
2683
  rollup: rollupPlugin(globalContext)
@@ -2778,10 +2845,11 @@ const getRepositoryData = async (git, repositoryURL) => {
2778
2845
  return data;
2779
2846
  };
2780
2847
 
2848
+ const PLUGIN_NAME$1 = "datadog-git-plugin";
2781
2849
  const getGitPlugins = (options, context) => {
2782
2850
  return [
2783
2851
  {
2784
- name: "datadog-git-plugin",
2852
+ name: PLUGIN_NAME$1,
2785
2853
  enforce: "pre",
2786
2854
  async buildStart() {
2787
2855
  const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;
@@ -2839,10 +2907,10 @@ const processItem = async (item, log) => {
2839
2907
  } catch (error) {
2840
2908
  const itemId = `${item.type} - ${truncateString(item.value)}`;
2841
2909
  if (item.fallback) {
2842
- log(`Fallback for "${itemId}": ${error.toString()}`, "warn");
2910
+ log.warn(`Fallback for "${itemId}": ${error.toString()}`);
2843
2911
  result = await processItem(item.fallback, log);
2844
2912
  } else {
2845
- log(`Failed "${itemId}": ${error.toString()}`, "warn");
2913
+ log.warn(`Failed "${itemId}": ${error.toString()}`);
2846
2914
  result = "";
2847
2915
  }
2848
2916
  }
@@ -2857,8 +2925,7 @@ const processInjections = async (toInject, log) => {
2857
2925
  return results.filter(Boolean);
2858
2926
  };
2859
2927
 
2860
- const getInjectionPlugins = (bundler, context, toInject) => {
2861
- const log = context.getLogger(PLUGIN_NAME);
2928
+ const getInjectionPlugins = (bundler, context, toInject, log) => {
2862
2929
  const contentToInject = [];
2863
2930
  const getContentToInject = () => {
2864
2931
  const before = `
@@ -2898,11 +2965,11 @@ ${after}`;
2898
2965
  );
2899
2966
  try {
2900
2967
  if (fs.existsSync(absolutePathInjectFile)) {
2901
- log(`Temporary file "${INJECTED_FILE_PATH}" already exists.`, "warn");
2968
+ log.warn(`Temporary file "${INJECTED_FILE_PATH}" already exists.`);
2902
2969
  }
2903
2970
  await outputFile(absolutePathInjectFile, getContentToInject());
2904
2971
  } catch (e) {
2905
- log(`Could not create the file: ${e.message}`, "error");
2972
+ log.error(`Could not create the file: ${e.message}`);
2906
2973
  }
2907
2974
  },
2908
2975
  async buildEnd() {
@@ -2913,6 +2980,7 @@ ${after}`;
2913
2980
  context.bundler.outDir,
2914
2981
  INJECTED_FILE_PATH
2915
2982
  );
2983
+ log.debug(`Removing temporary file "${INJECTED_FILE_PATH}".`);
2916
2984
  await rm(absolutePathInjectFile);
2917
2985
  }
2918
2986
  },
@@ -2935,7 +3003,7 @@ ${after}`;
2935
3003
  const BannerPlugin = compiler?.webpack?.BannerPlugin || bundler?.BannerPlugin || bundler?.default?.BannerPlugin;
2936
3004
  compiler?.webpack?.ChunkGraph || bundler?.ChunkGraph || bundler?.default?.ChunkGraph;
2937
3005
  if (!BannerPlugin) {
2938
- log("Missing BannerPlugin", "error");
3006
+ log.error("Missing BannerPlugin");
2939
3007
  }
2940
3008
  let chunkGraph;
2941
3009
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
@@ -2967,6 +3035,20 @@ ${after}`;
2967
3035
  })
2968
3036
  );
2969
3037
  },
3038
+ rspack: (compiler) => {
3039
+ compiler.options.plugins = compiler.options.plugins || [];
3040
+ compiler.options.plugins.push(
3041
+ new compiler.rspack.BannerPlugin({
3042
+ // Not wrapped in comments.
3043
+ raw: true,
3044
+ // Only entry modules.
3045
+ entryOnly: true,
3046
+ banner() {
3047
+ return getContentToInject();
3048
+ }
3049
+ })
3050
+ );
3051
+ },
2970
3052
  rollup: rollupInjectionPlugin,
2971
3053
  vite: rollupInjectionPlugin
2972
3054
  }
@@ -2998,25 +3080,43 @@ const buildPluginFactory = ({
2998
3080
  injections,
2999
3081
  version
3000
3082
  });
3083
+ const getLogger = getLoggerFactory(context.build, options.logLevel);
3001
3084
  context.pluginNames.push(HOST_NAME);
3002
3085
  const plugins = [
3003
3086
  // Prefill with our internal plugins.
3004
3087
  // #internal-plugins-injection-marker
3005
- ...getBuildReportPlugins(context),
3088
+ ...getBuildReportPlugins(context, getLogger("datadog-build-report-plugin")),
3006
3089
  ...getBundlerReportPlugins(context),
3007
3090
  ...getGitPlugins(options, context),
3008
- ...getInjectionPlugins(bundler, context, injections)
3091
+ ...getInjectionPlugins(
3092
+ bundler,
3093
+ context,
3094
+ injections,
3095
+ getLogger("datadog-injection-plugin")
3096
+ )
3009
3097
  // #internal-plugins-injection-marker
3010
3098
  ];
3011
3099
  if (options.customPlugins) {
3012
- const customPlugins = options.customPlugins(options, context);
3100
+ const customPlugins = options.customPlugins(
3101
+ options,
3102
+ context,
3103
+ getLogger("datadog-custom-plugins")
3104
+ );
3013
3105
  plugins.push(...customPlugins);
3014
3106
  }
3015
3107
  if (options[CONFIG_KEY$1] && options[CONFIG_KEY$1].disabled !== true) {
3016
- plugins.push(...getPlugins$2(options, context));
3108
+ plugins.push(
3109
+ ...getPlugins$1(options, context, getLogger(PLUGIN_NAME$5))
3110
+ );
3017
3111
  }
3018
3112
  if (options[CONFIG_KEY] && options[CONFIG_KEY].disabled !== true) {
3019
- plugins.push(...getPlugins(options, context));
3113
+ plugins.push(
3114
+ ...getPlugins(
3115
+ options,
3116
+ context,
3117
+ getLogger(PLUGIN_NAME$4)
3118
+ )
3119
+ );
3020
3120
  }
3021
3121
  context.pluginNames.push(...plugins.map((plugin) => plugin.name));
3022
3122
  return plugins;
@@ -3025,7 +3125,7 @@ const buildPluginFactory = ({
3025
3125
 
3026
3126
  var name = "@datadog/webpack-plugin";
3027
3127
  var packageManager = "yarn@4.0.2";
3028
- var version$1 = "2.3.3-dev-2";
3128
+ var version$1 = "2.4.0";
3029
3129
  var license = "MIT";
3030
3130
  var author = "Datadog";
3031
3131
  var description = "Datadog Webpack Plugin";
@@ -3100,7 +3200,6 @@ var devDependencies = {
3100
3200
  var peerDependencies = {
3101
3201
  webpack: ">= 4.x < 6.x"
3102
3202
  };
3103
- var stableVersion = "2.3.2";
3104
3203
  var pkg = {
3105
3204
  name: name,
3106
3205
  packageManager: packageManager,
@@ -3119,8 +3218,7 @@ var pkg = {
3119
3218
  scripts: scripts,
3120
3219
  dependencies: dependencies,
3121
3220
  devDependencies: devDependencies,
3122
- peerDependencies: peerDependencies,
3123
- stableVersion: stableVersion
3221
+ peerDependencies: peerDependencies
3124
3222
  };
3125
3223
 
3126
3224
  const datadogWebpackPlugin = buildPluginFactory({