UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

144 lines (142 loc) • 8.86 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.logException = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _browser = require("@sentry/browser"); var _platformFeatureFlags = require("@atlaskit/platform-feature-flags"); var _environment = require("./environment"); var _normaliseSentryBreadcrumbs = require("./normalise-sentry-breadcrumbs"); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080'; var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/ var packageVersion = "114.41.0"; var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) { // Remove URL as it has UGC // Ignored via go/ees007 // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format // TODO: Sanitise the URL instead of just removing it if (data.request) { delete data.request.url; } return data; }; var logException = exports.logException = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(error, tags) { var _process$env$CLOUD_EN, _yield$import, BrowserClient, defaultIntegrations, getCurrentHub, _yield$import2, ExtraErrorData, breadcrumbsIntegration, sentryOptions, client, hub; return _regenerator.default.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.prev = 0; if (!(process.env.NODE_ENV !== 'production' || process.env.CLOUD_ENV === 'branch')) { _context.next = 3; break; } return _context.abrupt("return"); case 3: _context.next = 5; return Promise.resolve().then(function () { return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-sentrybrowser" */'@sentry/browser')); }); case 5: _yield$import = _context.sent; BrowserClient = _yield$import.BrowserClient; defaultIntegrations = _yield$import.defaultIntegrations; getCurrentHub = _yield$import.getCurrentHub; _context.next = 11; return Promise.resolve().then(function () { return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-sentryintegrations" */'@sentry/integrations')); }); case 11: _yield$import2 = _context.sent; ExtraErrorData = _yield$import2.ExtraErrorData; breadcrumbsIntegration = (0, _platformFeatureFlags.fg)('platform_editor_sentry_breadcrumbs') ? new _browser.Integrations.Breadcrumbs({ // only enable breadcrumbs for dom (UI clicks and inputs) // include 'data-test-id', 'data-testid' in the breadcrumbs if they are found dom: { serializeAttribute: _normaliseSentryBreadcrumbs.SERIALIZABLE_ATTRIBUTES }, fetch: false, xhr: false, console: false, history: false, sentry: false }) : undefined; sentryOptions = { dsn: (0, _environment.isFedRamp)() ? undefined : SENTRY_DSN, release: "".concat(packageName, "@").concat(packageVersion), environment: (_process$env$CLOUD_EN = process.env.CLOUD_ENV) !== null && _process$env$CLOUD_EN !== void 0 ? _process$env$CLOUD_EN : 'unknown', beforeBreadcrumb: (0, _platformFeatureFlags.fg)('platform_editor_sentry_breadcrumbs') ? _normaliseSentryBreadcrumbs.normaliseSentryBreadcrumbs : undefined, ignoreErrors: [ // Network issues // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp /^network error/i, // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp /^network failure/i, 'TypeError: Failed to fetch', // A benign error, see https://stackoverflow.com/a/50387233/2645305 'ResizeObserver loop limit exceeded', // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp /ResizeObserver loop completed with undelivered notifications/], autoSessionTracking: false, integrations: function integrations(_integrations) { return [].concat((0, _toConsumableArray2.default)(defaultIntegrations.filter(function (_ref2) { var name = _ref2.name; return name !== 'Breadcrumbs'; })), (0, _toConsumableArray2.default)(breadcrumbsIntegration ? [breadcrumbsIntegration] : []), [ // Extracts all non-native attributes from the error object and attaches them to the event as the extra data // https://docs.sentry.io/platforms/javascript/configuration/integrations/plugin/?original_referrer=https%3A%2F%2Fduckduckgo.com%2F#extraerrordata new ExtraErrorData()]); }, beforeSend: sanitiseSentryEvents }; // Use a client to avoid picking up the errors from parent applications client = new BrowserClient(sentryOptions); hub = getCurrentHub(); // @ts-ignore - TypeScript 5.9.2 upgrade hub.bindClient(client); hub.withScope(function (scope) { var _buildInfo; scope.setTags(_objectSpread({ // Jira environment variables // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any 'jira-bundler': window.BUNDLER_VERSION, // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any 'jira-variant': window.BUILD_VARIANT, // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any 'jira-release': window.BUILD_KEY, // Confluence environment variables // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any 'confluence-frontend-version': (_buildInfo = window.__buildInfo) === null || _buildInfo === void 0 ? void 0 : _buildInfo.FRONTEND_VERSION }, tags)); // Explicitly remove the breadcrumbs as it's too likely to log UGC/PII to side-step the hub integrations not being respected scope.clearBreadcrumbs(); hub.captureException(error); }); // @ts-ignore - TypeScript 5.9.2 upgrade return _context.abrupt("return", client.close()); case 22: _context.prev = 22; _context.t0 = _context["catch"](0); case 24: case "end": return _context.stop(); } }, _callee, null, [[0, 22]]); })); return function logException(_x, _x2) { return _ref.apply(this, arguments); }; }();