From 08b09ee9a09b969718af99e7c07b047f7a149b7f Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Wed, 4 Oct 2023 11:41:17 -0400 Subject: [PATCH] feat(www): send form feedback from new contact view via Sentry (#1733) * Send new feedback to Sentry. * Fix error reporter attribute. * Update `source` to `accessKeySource`. * Add test cases for the contact view. * Disable `contactViewFeatureFlag`. * Fix `ContactView` storybook by mocking the error reporter with a console logger. * Use spread instead of casting to `unknown`. * Move success and error handling of contact view to `AppRoot` component. * Move error reporter to `www/shared/` instead of `infrastructure/`. * Put error reporter back into `TODO.spec.ts` now that it's back under `www/`. * Fix `ContactView` tests. * Reset `contactViewFeatureFlag` value. --- src/www/TODO.spec.ts | 2 +- src/www/app/app.ts | 3 +- src/www/app/cordova_main.ts | 2 +- src/www/app/electron_main.ts | 6 ++-- src/www/app/platform.ts | 2 +- src/www/{app => shared}/error_reporter.ts | 19 ++++++++---- src/www/ui_components/app-root.js | 27 ++++++++++++++--- src/www/views/contact_view/index.spec.ts | 30 +++++++++++++++---- src/www/views/contact_view/index.ts | 22 ++++++++++---- src/www/views/contact_view/stories.ts | 9 ++++-- .../contact_view/support_form/index.spec.ts | 10 +++---- .../views/contact_view/support_form/index.ts | 15 +++++++--- .../contact_view/support_form/stories.ts | 2 +- 13 files changed, 108 insertions(+), 41 deletions(-) rename src/www/{app => shared}/error_reporter.ts (86%) diff --git a/src/www/TODO.spec.ts b/src/www/TODO.spec.ts index 1f2613ed27..0f0a5636d3 100644 --- a/src/www/TODO.spec.ts +++ b/src/www/TODO.spec.ts @@ -27,7 +27,7 @@ // import * as outlineIcons from './ui_components/outline-icons'; import * as clipboard from './app/clipboard'; -import * as errorReporter from './app/error_reporter'; +import * as errorReporter from './shared/error_reporter'; import * as platform from './app/platform'; import * as tunnel from './app/tunnel'; import * as updater from './app/updater'; diff --git a/src/www/app/app.ts b/src/www/app/app.ts index cf4f2df583..baaef9b096 100644 --- a/src/www/app/app.ts +++ b/src/www/app/app.ts @@ -21,7 +21,7 @@ import {SERVER_CONNECTION_INDICATOR_DURATION_MS} from '../views/servers_view/ser import {Clipboard} from './clipboard'; import {EnvironmentVariables} from './environment'; -import {OutlineErrorReporter} from './error_reporter'; +import {OutlineErrorReporter} from '../shared/error_reporter'; import {OutlineServerRepository} from './outline_server_repository'; import {Settings, SettingsKey} from './settings'; import {Updater} from './updater'; @@ -105,6 +105,7 @@ export class App { this.syncConnectivityStateToServerCards(); rootEl.appVersion = environmentVars.APP_VERSION; rootEl.appBuild = environmentVars.APP_BUILD_NUMBER; + rootEl.errorReporter = this.errorReporter; if (urlInterceptor) { this.registerUrlInterceptionListener(urlInterceptor); diff --git a/src/www/app/cordova_main.ts b/src/www/app/cordova_main.ts index b3f6e40427..31ceaca9a6 100644 --- a/src/www/app/cordova_main.ts +++ b/src/www/app/cordova_main.ts @@ -26,7 +26,7 @@ import * as Sentry from '@sentry/browser'; import {AbstractClipboard} from './clipboard'; import {EnvironmentVariables} from './environment'; -import {SentryErrorReporter} from './error_reporter'; +import {SentryErrorReporter} from '../shared/error_reporter'; import {main} from './main'; import * as errors from '../model/errors'; import {OutlinePlatform} from './platform'; diff --git a/src/www/app/electron_main.ts b/src/www/app/electron_main.ts index e6583669a9..e4be0325c9 100644 --- a/src/www/app/electron_main.ts +++ b/src/www/app/electron_main.ts @@ -23,7 +23,7 @@ import {ErrorCode, OutlinePluginError} from '../model/errors'; import {AbstractClipboard} from './clipboard'; import {ElectronOutlineTunnel} from './electron_outline_tunnel'; -import {getSentryBrowserIntegrations, OutlineErrorReporter} from './error_reporter'; +import {getSentryBrowserIntegrations, OutlineErrorReporter, Tags} from '../shared/error_reporter'; import {FakeOutlineTunnel} from './fake_tunnel'; import {getLocalizationFunction, main} from './main'; import {AbstractUpdater} from './updater'; @@ -94,8 +94,8 @@ class ElectronErrorReporter implements OutlineErrorReporter { }); } - report(userFeedback: string, feedbackCategory: string, userEmail?: string): Promise { - Sentry.captureEvent({message: userFeedback, user: {email: userEmail}, tags: {category: feedbackCategory}}); + report(userFeedback: string, feedbackCategory: string, userEmail?: string, tags?: Tags): Promise { + Sentry.captureEvent({message: userFeedback, user: {email: userEmail}, tags: {...tags, category: feedbackCategory}}); return Promise.resolve(); } } diff --git a/src/www/app/platform.ts b/src/www/app/platform.ts index b9746dc2a3..31d5112950 100644 --- a/src/www/app/platform.ts +++ b/src/www/app/platform.ts @@ -14,7 +14,7 @@ import {Clipboard} from './clipboard'; import {EnvironmentVariables} from './environment'; -import {OutlineErrorReporter} from './error_reporter'; +import {OutlineErrorReporter} from '../shared/error_reporter'; import {TunnelFactory} from './tunnel'; import {Updater} from './updater'; import {UrlInterceptor} from './url_interceptor'; diff --git a/src/www/app/error_reporter.ts b/src/www/shared/error_reporter.ts similarity index 86% rename from src/www/app/error_reporter.ts rename to src/www/shared/error_reporter.ts index 053adde95d..60b84cf4a2 100644 --- a/src/www/app/error_reporter.ts +++ b/src/www/shared/error_reporter.ts @@ -15,28 +15,35 @@ import * as Sentry from '@sentry/browser'; import {Integration as SentryIntegration} from '@sentry/types'; +export type Tags = {[id: string]: string}; + export interface OutlineErrorReporter { - report(userFeedback: string, feedbackCategory: string, userEmail?: string): Promise; + report(userFeedback: string, feedbackCategory: string, userEmail?: string, tags?: Tags): Promise; } export class SentryErrorReporter implements OutlineErrorReporter { - constructor(appVersion: string, dsn: string, private tags: {[id: string]: string}) { + constructor(appVersion: string, dsn: string, private tags: Tags) { if (dsn) { Sentry.init({dsn, release: appVersion, integrations: getSentryBrowserIntegrations}); } this.setUpUnhandledRejectionListener(); } - async report(userFeedback: string, feedbackCategory: string, userEmail?: string): Promise { + async report(userFeedback: string, feedbackCategory: string, userEmail?: string, tags?: Tags): Promise { + const combinedTags = {...this.tags, ...tags}; Sentry.captureEvent({ message: userFeedback, user: {email: userEmail}, - tags: {category: feedbackCategory, isFeedback: Boolean(userFeedback)}, + tags: { + category: feedbackCategory, + isFeedback: Boolean(userFeedback), + ...combinedTags, + }, }); Sentry.configureScope(scope => { scope.setUser({email: userEmail || ''}); - if (this.tags) { - scope.setTags(this.tags); + if (combinedTags) { + scope.setTags(combinedTags); } scope.setTag('category', feedbackCategory); }); diff --git a/src/www/ui_components/app-root.js b/src/www/ui_components/app-root.js index bdd09d73fe..7f54ce48c1 100644 --- a/src/www/ui_components/app-root.js +++ b/src/www/ui_components/app-root.js @@ -295,7 +295,13 @@ export class AppRoot extends mixinBehaviors([AppLocalizeBehavior], PolymerElemen