@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.
package/dist/cjs/index.js CHANGED
@@ -1138,29 +1138,31 @@ function releaseManagementPlugin(_ref) {
1138
1138
  }
1139
1139
 
1140
1140
  function telemetryPlugin(_ref) {
1141
- var sentryClient = _ref.sentryClient,
1142
- pluginExecutionTransaction = _ref.pluginExecutionTransaction,
1141
+ var sentryHub = _ref.sentryHub,
1142
+ sentryClient = _ref.sentryClient,
1143
1143
  shouldSendTelemetry = _ref.shouldSendTelemetry,
1144
1144
  logger = _ref.logger;
1145
1145
  return {
1146
1146
  name: "sentry-telemetry-plugin",
1147
1147
  buildStart: function buildStart() {
1148
- void shouldSendTelemetry.then(function (willSendTelemetry) {
1149
- if (willSendTelemetry) {
1150
- logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1151
- }
1152
- });
1153
- pluginExecutionTransaction.startTimestamp = Date.now() / 1000;
1154
- },
1155
- writeBundle: function writeBundle() {
1156
1148
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1157
1149
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1158
1150
  while (1) switch (_context.prev = _context.next) {
1159
1151
  case 0:
1160
- pluginExecutionTransaction.finish();
1161
- _context.next = 3;
1162
- return sentryClient.flush();
1163
- case 3:
1152
+ _context.next = 2;
1153
+ return shouldSendTelemetry;
1154
+ case 2:
1155
+ if (!_context.sent) {
1156
+ _context.next = 7;
1157
+ break;
1158
+ }
1159
+ logger.info("Sending error and performance telemetry data to Sentry. To disable telemetry, set `options.telemetry` to `false`.");
1160
+ sentryHub.startTransaction({
1161
+ name: "Sentry Bundler Plugin execution"
1162
+ }).finish();
1163
+ _context.next = 7;
1164
+ return sentryClient.flush(3000);
1165
+ case 7:
1164
1166
  case "end":
1165
1167
  return _context.stop();
1166
1168
  }
@@ -1221,7 +1223,7 @@ function createSentryInstance(options, shouldSendTelemetry, bundler) {
1221
1223
  dsn: "https://4c2bae7d9fbc413e8f7385f55c515d51@o1.ingest.sentry.io/6690737",
1222
1224
  tracesSampleRate: 1,
1223
1225
  sampleRate: 1,
1224
- release: "2.1.0",
1226
+ release: "2.2.0",
1225
1227
  integrations: [],
1226
1228
  tracePropagationTargets: ["sentry.io/api"],
1227
1229
  stackParser: node.defaultStackParser,
@@ -1287,34 +1289,25 @@ function setTelemetryDataOnHub(options, hub, bundler) {
1287
1289
  release = options.release,
1288
1290
  errorHandler = options.errorHandler,
1289
1291
  sourcemaps = options.sourcemaps;
1292
+ hub.setTag("upload-legacy-sourcemaps", !!release.uploadLegacySourcemaps);
1290
1293
  if (release.uploadLegacySourcemaps) {
1291
1294
  hub.setTag("uploadLegacySourcemapsEntries", Array.isArray(release.uploadLegacySourcemaps) ? release.uploadLegacySourcemaps.length : 1);
1292
1295
  }
1293
1296
 
1294
1297
  // Optional release pipeline steps
1295
- if (release.cleanArtifacts) {
1296
- hub.setTag("clean-artifacts", true);
1297
- }
1298
+ hub.setTag("clean-artifacts", release.cleanArtifacts);
1298
1299
  if (release.setCommits) {
1299
1300
  hub.setTag("set-commits", release.setCommits.auto === true ? "auto" : "manual");
1301
+ } else {
1302
+ hub.setTag("set-commits", "undefined");
1300
1303
  }
1301
- if (release.finalize) {
1302
- hub.setTag("finalize-release", true);
1303
- }
1304
- if (release.deploy) {
1305
- hub.setTag("add-deploy", true);
1306
- }
1304
+ hub.setTag("finalize-release", release.finalize);
1305
+ hub.setTag("deploy-options", !!release.deploy);
1307
1306
 
1308
1307
  // Miscelaneous options
1309
- if (errorHandler) {
1310
- hub.setTag("error-handler", "custom");
1311
- }
1312
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets) {
1313
- hub.setTag("debug-id-upload", true);
1314
- }
1315
- if (sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload) {
1316
- hub.setTag("delete-after-upload", true);
1317
- }
1308
+ hub.setTag("custom-error-handler", !!errorHandler);
1309
+ hub.setTag("sourcemaps-assets", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.assets));
1310
+ hub.setTag("delete-after-upload", !!(sourcemaps !== null && sourcemaps !== void 0 && sourcemaps.deleteFilesAfterUpload));
1318
1311
  hub.setTag("node", process.version);
1319
1312
  hub.setTags({
1320
1313
  organization: org,
@@ -1428,25 +1421,41 @@ function sentryUnpluginFactory(_ref) {
1428
1421
  var _createSentryInstance = createSentryInstance(options, shouldSendTelemetry, unpluginMetaContext.framework),
1429
1422
  sentryHub = _createSentryInstance.sentryHub,
1430
1423
  sentryClient = _createSentryInstance.sentryClient;
1431
- var pluginExecutionTransaction = sentryHub.startTransaction({
1432
- name: "Sentry Bundler Plugin execution"
1424
+ var sentrySession = sentryHub.startSession();
1425
+ sentryHub.captureSession();
1426
+ var sentEndSession = false; // Just to prevent infinite loops with beforeExit, which is called whenever the event loop empties out
1427
+ // We also need to manually end sesisons on errors because beforeExit is not called on crashes
1428
+ process.on("beforeExit", function () {
1429
+ if (!sentEndSession) {
1430
+ sentryHub.endSession();
1431
+ sentEndSession = true;
1432
+ }
1433
1433
  });
1434
- sentryHub.getScope().setSpan(pluginExecutionTransaction);
1435
1434
  var logger = createLogger({
1436
1435
  prefix: "[sentry-".concat(unpluginMetaContext.framework, "-plugin]"),
1437
1436
  silent: options.silent,
1438
1437
  debug: options.debug
1439
1438
  });
1440
1439
  function handleRecoverableError(unknownError) {
1441
- pluginExecutionTransaction.setStatus("internal_error");
1442
- if (options.errorHandler) {
1443
- if (unknownError instanceof Error) {
1444
- options.errorHandler(unknownError);
1440
+ sentrySession.status = "abnormal";
1441
+ try {
1442
+ if (options.errorHandler) {
1443
+ try {
1444
+ if (unknownError instanceof Error) {
1445
+ options.errorHandler(unknownError);
1446
+ } else {
1447
+ options.errorHandler(new Error("An unknown error occured"));
1448
+ }
1449
+ } catch (e) {
1450
+ sentrySession.status = "crashed";
1451
+ throw e;
1452
+ }
1445
1453
  } else {
1446
- options.errorHandler(new Error("An unknown error occured"));
1454
+ sentrySession.status = "crashed";
1455
+ throw unknownError;
1447
1456
  }
1448
- } else {
1449
- throw unknownError;
1457
+ } finally {
1458
+ sentryHub.endSession();
1450
1459
  }
1451
1460
  }
1452
1461
  if (!validateOptions(options, logger)) {
@@ -1457,10 +1466,10 @@ function sentryUnpluginFactory(_ref) {
1457
1466
  }
1458
1467
  var plugins = [];
1459
1468
  plugins.push(telemetryPlugin({
1460
- pluginExecutionTransaction: pluginExecutionTransaction,
1469
+ sentryClient: sentryClient,
1470
+ sentryHub: sentryHub,
1461
1471
  logger: logger,
1462
- shouldSendTelemetry: shouldSendTelemetry,
1463
- sentryClient: sentryClient
1472
+ shouldSendTelemetry: shouldSendTelemetry
1464
1473
  }));
1465
1474
  if (!options.release.inject) {
1466
1475
  logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");