@sentry/bundler-plugin-core 2.1.0 → 2.2.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.
@@ -1105,29 +1105,31 @@ function releaseManagementPlugin(_ref) {
1105
1105
  }
1106
1106
 
1107
1107
  function telemetryPlugin(_ref) {
1108
- var sentryClient = _ref.sentryClient,
1109
- pluginExecutionTransaction = _ref.pluginExecutionTransaction,
1108
+ var sentryHub = _ref.sentryHub,
1109
+ sentryClient = _ref.sentryClient,
1110
1110
  shouldSendTelemetry = _ref.shouldSendTelemetry,
1111
1111
  logger = _ref.logger;
1112
1112
  return {
1113
1113
  name: "sentry-telemetry-plugin",
1114
1114
  buildStart: function buildStart() {
1115
- void shouldSendTelemetry.then(function (willSendTelemetry) {
1116
- if (willSendTelemetry) {
1117
- logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1118
- }
1119
- });
1120
- pluginExecutionTransaction.startTimestamp = Date.now() / 1000;
1121
- },
1122
- writeBundle: function writeBundle() {
1123
1115
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1124
1116
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1125
1117
  while (1) switch (_context.prev = _context.next) {
1126
1118
  case 0:
1127
- pluginExecutionTransaction.finish();
1128
- _context.next = 3;
1129
- return sentryClient.flush();
1130
- case 3:
1119
+ _context.next = 2;
1120
+ return shouldSendTelemetry;
1121
+ case 2:
1122
+ if (!_context.sent) {
1123
+ _context.next = 7;
1124
+ break;
1125
+ }
1126
+ logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1127
+ sentryHub.startTransaction({
1128
+ name: "Sentry Bundler Plugin execution"
1129
+ }).finish();
1130
+ _context.next = 7;
1131
+ return sentryClient.flush(3000);
1132
+ case 7:
1131
1133
  case "end":
1132
1134
  return _context.stop();
1133
1135
  }
@@ -1188,7 +1190,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1188
1190
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1189
1191
  tracesSampleRate: 1,
1190
1192
  sampleRate: 1,
1191
- release: "2.1.0",
1193
+ release: "2.2.0",
1192
1194
  integrations: [],
1193
1195
  tracePropagationTargets: ["sentry.io/api"],
1194
1196
  stackParser: defaultStackParser,
@@ -1254,34 +1256,25 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1254
1256
  release = options.release,
1255
1257
  errorHandler = options.errorHandler,
1256
1258
  sourcemaps = options.sourcemaps;
1259
+ hub.setTag("upload-legacy-sourcemaps", !!release.uploadLegacySourcemaps);
1257
1260
  if (release.uploadLegacySourcemaps) {
1258
1261
  hub.setTag("uploadLegacySourcemapsEntries", Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1);
1259
1262
  }
1260
1263
 
1261
1264
  // Optional release pipeline steps
1262
- if (release.cleanArtifacts) {
1263
- hub.setTag("clean-artifacts", true);
1264
- }
1265
+ hub.setTag("clean-artifacts", release.cleanArtifacts);
1265
1266
  if (release.setCommits) {
1266
1267
  hub.setTag("set-commits", release.setCommits.auto === true ? "auto" : "manual");
1268
+ } else {
1269
+ hub.setTag("set-commits", "undefined");
1267
1270
  }
1268
- if (release.finalize) {
1269
- hub.setTag("finalize-release", true);
1270
- }
1271
- if (release.deploy) {
1272
- hub.setTag("add-deploy", true);
1273
- }
1271
+ hub.setTag("finalize-release", release.finalize);
1272
+ hub.setTag("deploy-options", !!release.deploy);
1274
1273
 
1275
1274
  // Miscelaneous options
1276
- if (errorHandler) {
1277
- hub.setTag("error-handler", "custom");
1278
- }
1279
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets) {
1280
- hub.setTag("debug-id-upload", true);
1281
- }
1282
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload) {
1283
- hub.setTag("delete-after-upload", true);
1284
- }
1275
+ hub.setTag("custom-error-handler", !!errorHandler);
1276
+ hub.setTag("sourcemaps-assets", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets));
1277
+ hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload));
1285
1278
  hub.setTag("node", process.version);
1286
1279
  hub.setTags({
1287
1280
  organization: org,
@@ -1395,25 +1388,41 @@ function sentryUnpluginFactory(_ref) {
1395
1388
  var _createSentryInstance = createSentryInstance(options, shouldSendTelemetry, unpluginMetaContext.framework),
1396
1389
  sentryHub = _createSentryInstance.sentryHub,
1397
1390
  sentryClient = _createSentryInstance.sentryClient;
1398
- var pluginExecutionTransaction = sentryHub.startTransaction({
1399
- name: "Sentry Bundler Plugin execution"
1391
+ var sentrySession = sentryHub.startSession();
1392
+ sentryHub.captureSession();
1393
+ var sentEndSession = false; // Just to prevent infinite loops with beforeExit, which is called whenever the event loop empties out
1394
+ // We also need to manually end sesisons on errors because beforeExit is not called on crashes
1395
+ process.on("beforeExit", function () {
1396
+ if (!sentEndSession) {
1397
+ sentryHub.endSession();
1398
+ sentEndSession = true;
1399
+ }
1400
1400
  });
1401
- sentryHub.getScope().setSpan(pluginExecutionTransaction);
1402
1401
  var logger = createLogger({
1403
1402
  prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1404
1403
  silent: options.silent,
1405
1404
  debug: options.debug
1406
1405
  });
1407
1406
  function handleRecoverableError(unknownError) {
1408
- pluginExecutionTransaction.setStatus("internal_error");
1409
- if (options.errorHandler) {
1410
- if (unknownError instanceof Error) {
1411
- options.errorHandler(unknownError);
1407
+ sentrySession.status = "abnormal";
1408
+ try {
1409
+ if (options.errorHandler) {
1410
+ try {
1411
+ if (unknownError instanceof Error) {
1412
+ options.errorHandler(unknownError);
1413
+ } else {
1414
+ options.errorHandler(new Error("An unknown error occured"));
1415
+ }
1416
+ } catch (e) {
1417
+ sentrySession.status = "crashed";
1418
+ throw e;
1419
+ }
1412
1420
  } else {
1413
- options.errorHandler(new Error("An unknown error occured"));
1421
+ sentrySession.status = "crashed";
1422
+ throw unknownError;
1414
1423
  }
1415
- } else {
1416
- throw unknownError;
1424
+ } finally {
1425
+ sentryHub.endSession();
1417
1426
  }
1418
1427
  }
1419
1428
  if (!validateOptions(options, logger)) {
@@ -1424,10 +1433,10 @@ function sentryUnpluginFactory(_ref) {
1424
1433
  }
1425
1434
  var plugins = [];
1426
1435
  plugins.push(telemetryPlugin({
1427
- pluginExecutionTransaction: pluginExecutionTransaction,
1436
+ sentryClient: sentryClient,
1437
+ sentryHub: sentryHub,
1428
1438
  logger: logger,
1429
- shouldSendTelemetry: shouldSendTelemetry,
1430
- sentryClient: sentryClient
1439
+ shouldSendTelemetry: shouldSendTelemetry
1431
1440
  }));
1432
1441
  if (!options.release.inject) {
1433
1442
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");