OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Merge remote-tracking branch 'origin/release/11.4' into dev
Wieland Lindenthal5d782626a991
diff --cc Gemfile.lockindex 230a464bc61,b7e49643f2a..ec04cd6c6e9--- a/Gemfile.lock+++ b/Gemfile.lock@@@ -522,8 -511,10 +522,11 @@@ GEmustermann-grape (~> 1.0.0)rack (>= 1.3.0)rack-accept+ grape_logging (1.8.4)+ grape+ rackgravatar_image_tag (1.2.0)+ hana (1.3.7)hashdiff (1.0.1)hashery (2.1.2)hashie (3.6.0)diff --cc frontend/src/app/core/errors/sentry/sentry-reporter.tsindex 4341edef00d,00000000000..df24f6d3eeamode 100644,000000..100644--- a/frontend/src/app/core/errors/sentry/sentry-reporter.ts+++ b/frontend/src/app/core/errors/sentry/sentry-reporter.ts@@@ -1,229 -1,0 +1,230 @@@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2021 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See COPYRIGHT and LICENSE files for more details.+//++++import {+ Event as SentryEvent,+ Hub,+ Scope,+ Severity,+} from '@sentry/types';+import { environment } from '../../../../environments/environment';+import { EventHint } from '@sentry/angular';+import { HttpErrorResponse } from '@angular/common/http';+import { debugLog } from 'core-app/shared/helpers/debug_output';++export type ScopeCallback = (scope:Scope) => void;+export type MessageSeverity = 'fatal'|'error'|'warning'|'log'|'info'|'debug';++export interface CaptureInterface {+ /** Capture a message */+ captureMessage(msg:string, level?:MessageSeverity):void;++ /** Capture an exception(!) only */+ captureException(err:Error):void;+}++export interface SentryClient extends CaptureInterface {+ configureScope(scope:ScopeCallback):void;++ withScope(scope:ScopeCallback):void;+}++export interface ErrorReporter extends CaptureInterface {+ /** Register a context callback handler */+ addContext(...callbacks:ScopeCallback[]):void;+}++interface QueuedMessage {+ type:'captureMessage'|'captureException';+ args:unknown[];+}++export class SentryReporter implements ErrorReporter {+ private contextCallbacks:ScopeCallback[] = [];++ private messageStack:QueuedMessage[] = [];++ private readonly sentryConfigured:boolean = true;++ private client:Hub;++ constructor() {+ const sentryElement = document.querySelector('meta[name=openproject_sentry]') as HTMLElement;+ if (sentryElement !== null) {+ this.loadSentry(sentryElement);+ } else {+ this.sentryConfigured = false;+ this.messageStack = [];+ }+ }++ private loadSentry(sentryElement:HTMLElement) {+ const dsn = sentryElement.dataset.dsn || '';+ const version = sentryElement.dataset.version || 'unknown';+ const traceFactor = parseFloat(sentryElement.dataset.tracingFactor || '0.0');++ void import('./sentry-dependency').then((imported) => {+ const sentry = imported.Sentry;+ sentry.init({+ dsn,+ debug: !environment.production,+ release: `op-frontend@${version}`,+ environment: environment.production ? 'production' : 'development',++ // Integrations+ integrations: [new imported.Integrations.BrowserTracing()],++ tracesSampler: (samplingContext) => {+ switch (samplingContext.transactionContext.op) {+ case 'op':+ case 'navigation':+ // Trace 1% of page loads and navigation events+ return Math.min(0.01 * traceFactor, 1.0);+ default:+ // Trace 0.1% of requests+ return Math.min(0.001 * traceFactor, 1.0);+ }+ },++ ignoreErrors: [+ // Transition movements,+ 'The transition has been superseded by a different transition',+ // Uncaught promise rejections+ 'Uncaught (in promise)',+ // Non-errors caught for hal resources+ 'Non-Error exception captured with keys: $embedded, $halType, $links, $loaded',++ ],+ beforeSend: (event, hint) => SentryReporter.filterEvent(event, hint),+ });++ this.sentryLoaded(sentry as unknown as Hub);+ });+ }++ public sentryLoaded(client:Hub):void {+ this.client = client;+ client.configureScope(this.setupContext.bind(this));++ // Send all messages from before sentry got loaded+ this.messageStack.forEach((item) => {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access+ this[item.type].bind(this).apply(item.args);+ });+ }++ public captureMessage(msg:string, severity:MessageSeverity = 'info'):void {+ if (!this.client) {+ this.handleOfflineMessage('captureMessage', [msg, severity]);+ return;+ }++ this.client.withScope((scope:Scope) => {+ this.setupContext(scope);+ this.client.captureMessage(msg, Severity.fromString(severity));+ });+ }++ public captureException(err:Error|string):void {+ if (!this.client || !err) {+ this.handleOfflineMessage('captureException', [err]);+ throw (err as Error);+ }++ if (typeof err === 'string') {+ this.captureMessage(err, 'error');+ return;+ }++ this.client.withScope((scope:Scope) => {+ this.setupContext(scope);+ this.client.captureException(err);+ });+ }++ public addContext(...callbacks:ScopeCallback[]):void {+ this.contextCallbacks.push(...callbacks);++ if (this.client) {+ /** Add to global context as well */+ callbacks.forEach((cb) => this.client.configureScope(cb));+ }+ }++ /**+ * Remember a message or error for later handling+ * @param type+ * @param args+ */+ private handleOfflineMessage(type:'captureMessage'|'captureException', args:unknown[]) {+ if (this.sentryConfigured) {+ this.messageStack.push({ type, args });+ } else {+ debugLog('[ErrorReporter] Would queue sentry message %O %O, but is not configured.', type, args);+ }+ }++ /**+ * Set up the current scope for the event to be sent.+ * @param scope+ */+ private setupContext(scope:Scope) {++ scope.setTag('code_origin', 'frontend');+ scope.setTag('locale', window.I18n.locale);+ scope.setTag('domain', window.location.hostname);+ scope.setTag('url_path', window.location.pathname);+ scope.setExtra('url_query', window.location.search);++ /** Execute callbacks */+ this.contextCallbacks.forEach((cb) => cb(scope));+ }++ /**+ * Filters the event content's or removes+ * it from being sent.+ *+ * @param event+ * @param hint+ */+ private static filterEvent(event:SentryEvent, hint:EventHint|undefined):SentryEvent|null {+ // avoid duplicate requests on thrown angular errors, they+ // are handled by the hal error handler+ // https://github.com/getsentry/sentry-javascript/issues/2532#issuecomment-875428325+ if (hint?.originalException instanceof HttpErrorResponse) {+ return null;+ }++ const unsupportedBrowser = document.body.classList.contains('-unsupported-browser');+ if (unsupportedBrowser) {+ console.warn('Browser is not supported, skipping sentry reporting completely.');+ return null;+ }++ return event;+ }+}