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