@sentry/bundler-plugin-core 2.2.0 → 2.2.2

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.
@@ -12,6 +12,7 @@ import childProcess from 'child_process';
12
12
  import { glob } from 'glob';
13
13
  import * as util from 'util';
14
14
  import { promisify } from 'util';
15
+ import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
15
16
  import { NodeClient, defaultStackParser, makeNodeTransport, Hub } from '@sentry/node';
16
17
 
17
18
  function ownKeys(object, enumerableOnly) {
@@ -671,16 +672,22 @@ function createDebugIdUploadFunction(_ref) {
671
672
  deleteFilesAfterUpload = _ref.deleteFilesAfterUpload;
672
673
  return /*#__PURE__*/function () {
673
674
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(buildArtifactPaths) {
674
- var folderToCleanUp, cliInstance, tmpUploadFolder, globAssets, debugIdChunkFilePaths, filePathsToDelete;
675
+ var artifactBundleUploadTransaction, folderToCleanUp, mkdtempSpan, tmpUploadFolder, globAssets, globSpan, globResult, debugIdChunkFilePaths, prepareSpan, files, stats, uploadSize, uploadSpan, cliInstance, deleteGlobSpan, filePathsToDelete, deleteSpan, cleanupSpan;
675
676
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
676
677
  while (1) switch (_context2.prev = _context2.next) {
677
678
  case 0:
678
- cliInstance = new SentryCli(null, sentryCliOptions);
679
+ artifactBundleUploadTransaction = sentryHub.startTransaction({
680
+ name: "debug-id-sourcemap-upload"
681
+ });
679
682
  _context2.prev = 1;
680
- _context2.next = 4;
683
+ mkdtempSpan = artifactBundleUploadTransaction.startChild({
684
+ description: "mkdtemp"
685
+ });
686
+ _context2.next = 5;
681
687
  return fs__default.promises.mkdtemp(path__default.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
682
- case 4:
688
+ case 5:
683
689
  tmpUploadFolder = _context2.sent;
690
+ mkdtempSpan.finish();
684
691
  folderToCleanUp = tmpUploadFolder;
685
692
  if (assets) {
686
693
  globAssets = assets;
@@ -688,33 +695,41 @@ function createDebugIdUploadFunction(_ref) {
688
695
  logger.debug("No `sourcemaps.assets` option provided, falling back to uploading detected build artifacts.");
689
696
  globAssets = buildArtifactPaths;
690
697
  }
691
- _context2.next = 9;
698
+ globSpan = artifactBundleUploadTransaction.startChild({
699
+ description: "glob"
700
+ });
701
+ _context2.next = 12;
692
702
  return glob(globAssets, {
693
703
  absolute: true,
694
704
  nodir: true,
695
705
  ignore: ignore
696
706
  });
697
- case 9:
698
- debugIdChunkFilePaths = _context2.sent.filter(function (debugIdChunkFilePath) {
707
+ case 12:
708
+ globResult = _context2.sent;
709
+ globSpan.finish();
710
+ debugIdChunkFilePaths = globResult.filter(function (debugIdChunkFilePath) {
699
711
  return debugIdChunkFilePath.endsWith(".js") || debugIdChunkFilePath.endsWith(".mjs") || debugIdChunkFilePath.endsWith(".cjs");
700
712
  });
701
713
  if (!(Array.isArray(assets) && assets.length === 0)) {
702
- _context2.next = 14;
714
+ _context2.next = 19;
703
715
  break;
704
716
  }
705
717
  logger.debug("Empty `sourcemaps.assets` option provided. Will not upload sourcemaps with debug ID.");
706
- _context2.next = 22;
718
+ _context2.next = 41;
707
719
  break;
708
- case 14:
720
+ case 19:
709
721
  if (!(debugIdChunkFilePaths.length === 0)) {
710
- _context2.next = 18;
722
+ _context2.next = 23;
711
723
  break;
712
724
  }
713
725
  logger.warn("Didn't find any matching sources for debug ID upload. Please check the `sourcemaps.assets` option.");
714
- _context2.next = 22;
726
+ _context2.next = 41;
715
727
  break;
716
- case 18:
717
- _context2.next = 20;
728
+ case 23:
729
+ prepareSpan = artifactBundleUploadTransaction.startChild({
730
+ description: "prepare-bundles"
731
+ });
732
+ _context2.next = 26;
718
733
  return Promise.all(debugIdChunkFilePaths.map( /*#__PURE__*/function () {
719
734
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chunkFilePath, chunkIndex) {
720
735
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -732,8 +747,35 @@ function createDebugIdUploadFunction(_ref) {
732
747
  return _ref3.apply(this, arguments);
733
748
  };
734
749
  }()));
735
- case 20:
736
- _context2.next = 22;
750
+ case 26:
751
+ prepareSpan.finish();
752
+ _context2.next = 29;
753
+ return fs__default.promises.readdir(tmpUploadFolder);
754
+ case 29:
755
+ files = _context2.sent;
756
+ stats = files.map(function (file) {
757
+ return fs__default.promises.stat(path__default.join(tmpUploadFolder, file));
758
+ });
759
+ _context2.next = 33;
760
+ return Promise.all(stats);
761
+ case 33:
762
+ uploadSize = _context2.sent.reduce(function (accumulator, _ref4) {
763
+ var size = _ref4.size;
764
+ return accumulator + size;
765
+ }, 0);
766
+ artifactBundleUploadTransaction.setMeasurement("files", files.length, "none");
767
+ artifactBundleUploadTransaction.setMeasurement("upload_size", uploadSize, "byte");
768
+ uploadSpan = artifactBundleUploadTransaction.startChild({
769
+ description: "upload"
770
+ });
771
+ cliInstance = new SentryCli(null, _objectSpread2(_objectSpread2({}, sentryCliOptions), {}, {
772
+ headers: _objectSpread2({
773
+ "sentry-trace": uploadSpan.toTraceparent(),
774
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
775
+ baggage: dynamicSamplingContextToSentryBaggageHeader(artifactBundleUploadTransaction.getDynamicSamplingContext())
776
+ }, sentryCliOptions.headers)
777
+ }));
778
+ _context2.next = 40;
737
779
  return cliInstance.releases.uploadSourceMaps(releaseName !== null && releaseName !== void 0 ? releaseName : "undefined",
738
780
  // unfortunetly this needs a value for now but it will not matter since debug IDs overpower releases anyhow
739
781
  {
@@ -744,52 +786,71 @@ function createDebugIdUploadFunction(_ref) {
744
786
  }],
745
787
  useArtifactBundle: true
746
788
  });
747
- case 22:
789
+ case 40:
790
+ uploadSpan.finish();
791
+ case 41:
748
792
  if (!deleteFilesAfterUpload) {
749
- _context2.next = 29;
793
+ _context2.next = 52;
750
794
  break;
751
795
  }
752
- _context2.next = 25;
796
+ deleteGlobSpan = artifactBundleUploadTransaction.startChild({
797
+ description: "delete-glob"
798
+ });
799
+ _context2.next = 45;
753
800
  return glob(deleteFilesAfterUpload, {
754
801
  absolute: true,
755
802
  nodir: true
756
803
  });
757
- case 25:
804
+ case 45:
758
805
  filePathsToDelete = _context2.sent;
806
+ deleteGlobSpan.finish();
759
807
  filePathsToDelete.forEach(function (filePathToDelete) {
760
808
  logger.debug("Deleting asset after upload: ".concat(filePathToDelete));
761
809
  });
762
- _context2.next = 29;
810
+ deleteSpan = artifactBundleUploadTransaction.startChild({
811
+ description: "delete-files-after-upload"
812
+ });
813
+ _context2.next = 51;
763
814
  return Promise.all(filePathsToDelete.map(function (filePathToDelete) {
764
815
  return fs__default.promises.rm(filePathToDelete, {
765
816
  force: true
766
817
  });
767
818
  }));
768
- case 29:
769
- _context2.next = 37;
819
+ case 51:
820
+ deleteSpan.finish();
821
+ case 52:
822
+ _context2.next = 58;
770
823
  break;
771
- case 31:
772
- _context2.prev = 31;
824
+ case 54:
825
+ _context2.prev = 54;
773
826
  _context2.t0 = _context2["catch"](1);
774
- sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
775
- _context2.next = 36;
776
- return sentryClient.flush();
777
- case 36:
827
+ sentryHub.withScope(function (scope) {
828
+ scope.setSpan(artifactBundleUploadTransaction);
829
+ sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
830
+ });
778
831
  handleRecoverableError(_context2.t0);
779
- case 37:
780
- _context2.prev = 37;
832
+ case 58:
833
+ _context2.prev = 58;
781
834
  if (folderToCleanUp) {
835
+ cleanupSpan = artifactBundleUploadTransaction.startChild({
836
+ description: "cleanup"
837
+ });
782
838
  void fs__default.promises.rm(folderToCleanUp, {
783
839
  recursive: true,
784
840
  force: true
785
841
  });
842
+ cleanupSpan.finish();
786
843
  }
787
- return _context2.finish(37);
788
- case 40:
844
+ artifactBundleUploadTransaction.finish();
845
+ _context2.next = 63;
846
+ return sentryClient.flush();
847
+ case 63:
848
+ return _context2.finish(58);
849
+ case 64:
789
850
  case "end":
790
851
  return _context2.stop();
791
852
  }
792
- }, _callee2, null, [[1, 31, 37, 40]]);
853
+ }, _callee2, null, [[1, 54, 58, 64]]);
793
854
  }));
794
855
  return function (_x) {
795
856
  return _ref2.apply(this, arguments);
@@ -837,7 +898,7 @@ function _prepareBundleForDebugIdUpload() {
837
898
  bundleContent += "\n//# debugId=".concat(debugId);
838
899
  writeSourceFilePromise = fs__default.promises.writeFile(path__default.join(uploadFolder, "".concat(uniqueUploadName, ".js")), bundleContent, "utf-8");
839
900
  writeSourceMapFilePromise = determineSourceMapPathFromBundle(bundleFilePath, bundleContent, logger).then( /*#__PURE__*/function () {
840
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceMapPath) {
901
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceMapPath) {
841
902
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
842
903
  while (1) switch (_context3.prev = _context3.next) {
843
904
  case 0:
@@ -856,7 +917,7 @@ function _prepareBundleForDebugIdUpload() {
856
917
  }, _callee3);
857
918
  }));
858
919
  return function (_x17) {
859
- return _ref4.apply(this, arguments);
920
+ return _ref5.apply(this, arguments);
860
921
  };
861
922
  }());
862
923
  return _context4.abrupt("return", Promise.all([writeSourceFilePromise, writeSourceMapFilePromise]));
@@ -920,7 +981,7 @@ function _determineSourceMapPathFromBundle() {
920
981
  _context5.t0 = _context5["catch"](8);
921
982
  case 17:
922
983
  // This is just a debug message because it can be quite spammy for some frameworks
923
- logger.debug("Could not determine source map path for bundle: ".concat(bundlePath));
984
+ logger.debug("Could not determine source map path for bundle: ".concat(bundlePath, " - Did you turn on source map generation in your bundler?"));
924
985
  return _context5.abrupt("return", undefined);
925
986
  case 19:
926
987
  case "end":
@@ -1190,7 +1251,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1190
1251
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1191
1252
  tracesSampleRate: 1,
1192
1253
  sampleRate: 1,
1193
- release: "2.2.0",
1254
+ release: "2.2.2",
1194
1255
  integrations: [],
1195
1256
  tracePropagationTargets: ["sentry.io/api"],
1196
1257
  stackParser: defaultStackParser,
@@ -1276,6 +1337,7 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1276
1337
  hub.setTag("sourcemaps-assets", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets));
1277
1338
  hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload));
1278
1339
  hub.setTag("node", process.version);
1340
+ hub.setTag("platform", process.platform);
1279
1341
  hub.setTags({
1280
1342
  organization: org,
1281
1343
  project: project,
@@ -1403,6 +1465,9 @@ function sentryUnpluginFactory(_ref) {
1403
1465
  silent: options.silent,
1404
1466
  debug: options.debug
1405
1467
  });
1468
+
1469
+ // Set the User-Agent that Sentry CLI will use when interacting with Sentry
1470
+ process.env["SENTRY_PIPELINE"] = "".concat(unpluginMetaContext.framework, "-plugin/", "2.2.2");
1406
1471
  function handleRecoverableError(unknownError) {
1407
1472
  sentrySession.status = "abnormal";
1408
1473
  try {
@@ -1605,12 +1670,11 @@ function createRollupDebugIdInjectionHooks() {
1605
1670
  // As an additional complication `"use strict";`s may come after any number of comments.
1606
1671
  var commentUseStrictRegex =
1607
1672
  // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
1608
- /^(?:\s*|\/\*(?:.|\r|\n)*\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;
1609
- if ((_code$match = code.match(commentUseStrictRegex)) !== null && _code$match !== void 0 && _code$match[0]) {
1673
+ /^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;
1674
+ var match = (_code$match = code.match(commentUseStrictRegex)) === null || _code$match === void 0 ? void 0 : _code$match[0];
1675
+ if (match) {
1610
1676
  // Add injected code after any comments or "use strict" at the beginning of the bundle.
1611
- ms.replace(commentUseStrictRegex, function (match) {
1612
- return "".concat(match).concat(codeToInject);
1613
- });
1677
+ ms.appendLeft(match.length, codeToInject);
1614
1678
  } else {
1615
1679
  // ms.replace() doesn't work when there is an empty string match (which happens if
1616
1680
  // there is neither, a comment, nor a "use strict" at the top of the chunk) so we