Skip to content

Commit 128601f

Browse files
authored
MSD: Send unknown error to logstash (#107233)
1 parent 95e34ef commit 128601f

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

client/dashboard/.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ module.exports = {
1616
// Allowed: calypso/lib/explat
1717
// Allowed: calypso/lib/interval/use-interval (temporary)
1818
// Allowed: calypso/lib/load-dev-helpers
19+
// Allowed: calypso/lib/logstash
1920
// Allowed: calypso/lib/wp
2021
'!calypso/lib',
2122
'calypso/lib/*',
2223
'!calypso/lib/explat',
2324
'!calypso/lib/interval',
2425
'!calypso/lib/load-dev-helpers',
26+
'!calypso/lib/logstash',
2527
'!calypso/lib/wp',
2628
// Allowed: calypso/assets/icons
2729
// Allowed: calypso/assets/images

client/dashboard/app/500/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Notice } from '@wordpress/components';
21
import { __ } from '@wordpress/i18n';
2+
import Notice from '../../components/notice';
33
import { PageHeader } from '../../components/page-header';
44
import PageLayout from '../../components/page-layout';
55
import RouterLinkButton from '../../components/router-link-button';
@@ -18,11 +18,7 @@ function UnknownError( { error }: { error: Error } ) {
1818
}
1919
/>
2020
}
21-
notices={
22-
<Notice status="error" isDismissible={ false }>
23-
{ error.message }
24-
</Notice>
25-
}
21+
notices={ <Notice variant="error">{ error.message }</Notice> }
2622
></PageLayout>
2723
);
2824
}

client/dashboard/app/router/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import calypsoConfig from '@automattic/calypso-config';
12
import { Router, createRoute, redirect } from '@tanstack/react-router';
3+
import { logToLogstash } from 'calypso/lib/logstash';
24
import NotFound from '../404';
35
import UnknownError from '../500';
46
import { createDomainsRoutes } from './domains';
@@ -8,6 +10,7 @@ import { createPluginsRoutes } from './plugins';
810
import { rootRoute } from './root';
911
import { createSitesRoutes } from './sites';
1012
import type { AppConfig } from '../context';
13+
import type { ErrorInfo } from 'react';
1114

1215
interface RouteContext {
1316
config?: AppConfig;
@@ -61,6 +64,19 @@ export const getRouter = ( config: AppConfig ) => {
6164
},
6265
defaultErrorComponent: UnknownError,
6366
defaultNotFoundComponent: NotFound,
67+
defaultOnCatch: ( error: Error, errorInfo: ErrorInfo ) => {
68+
logToLogstash( {
69+
feature: 'calypso_client',
70+
message: 'Unknown error',
71+
severity: calypsoConfig( 'env_id' ) === 'production' ? 'error' : 'debug',
72+
tags: [ 'dashboard' ],
73+
properties: {
74+
env: calypsoConfig( 'env_id' ),
75+
message: error.message,
76+
stack: errorInfo.componentStack,
77+
},
78+
} );
79+
},
6480
defaultPreload: 'intent',
6581
defaultPreloadStaleTime: 0,
6682
// Calling document.startViewTransition() ourselves is really tricky,

client/sites/v2/components/500.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { __ } from '@wordpress/i18n';
2+
import Notice from 'calypso/dashboard/components/notice';
3+
import { PageHeader } from 'calypso/dashboard/components/page-header';
4+
import PageLayout from 'calypso/dashboard/components/page-layout';
5+
6+
function UnknownError( { error }: { error: Error } ) {
7+
return (
8+
<PageLayout
9+
header={
10+
<PageHeader title={ __( '500 Error' ) } description={ __( 'Something wrong happened.' ) } />
11+
}
12+
notices={ <Notice variant="error">{ error.message }</Notice> }
13+
></PageLayout>
14+
);
15+
}
16+
17+
export default UnknownError;

client/sites/v2/utils/router.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1+
import calypsoConfig from '@automattic/calypso-config';
12
import pagejs from '@automattic/calypso-router';
23
import { createMemoryHistory } from '@tanstack/react-router';
4+
import { logToLogstash } from 'calypso/lib/logstash';
5+
import UnknownError from '../components/500';
36
import type { AnyRoute, AnyRouter } from '@tanstack/react-router';
47
import type { AppConfig } from 'calypso/dashboard/app/context';
8+
import type { ErrorInfo } from 'react';
59

610
export function getRouterOptions( config: AppConfig ) {
711
return {
812
basepath: config.basePath,
913
context: {
1014
config,
1115
},
16+
defaultOnCatch: ( error: Error, errorInfo: ErrorInfo ) => {
17+
logToLogstash( {
18+
feature: 'calypso_client',
19+
message: 'Unknown error (backport)',
20+
severity: calypsoConfig( 'env_id' ) === 'production' ? 'error' : 'debug',
21+
tags: [ 'dashboard' ],
22+
properties: {
23+
env: calypsoConfig( 'env_id' ),
24+
message: error.message,
25+
stack: errorInfo.componentStack,
26+
},
27+
} );
28+
},
1229
defaultPreload: 'intent' as const,
1330
defaultPreloadStaleTime: 0,
31+
defaultErrorComponent: UnknownError,
1432
defaultNotFoundComponent: () => null,
1533
defaultViewTransition: true,
1634

0 commit comments

Comments
 (0)