Skip to content

Migrate from Rollbar to Sentry #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ E2E_LOGIN_URL='https://jetstream-e2e-dev-ed.develop.my.salesforce.com'
EXAMPLE_USER_OVERRIDE='true'
EXAMPLE_USER_PASSWORD='EXAMPLE_123!'

NX_PUBLIC_ROLLBAR_KEY=''
NX_PUBLIC_AMPLITUDE_KEY=''
NX_PUBLIC_SENTRY_DSN=''

# Credentials for sending emails
# If you are not using the example user, then you may need to configure this for MFA
Expand All @@ -89,8 +89,6 @@ GOOGLE_CLIENT_ID=''
GOOGLE_CLIENT_SECRET=''
GOOGLE_REDIRECT_URI='http://localhost:3333/oauth/google/callback'

ROLLBAR_SERVER_TOKEN=''

# Algolia API key - used to index docs pages
ALGOLIA_APPLICATION_ID=''
ALGOLIA_API_KEY=''
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ env:
CONTENTFUL_SPACE: wuv9tl5d77ll
CONTENTFUL_TOKEN: ${{ secrets.CONTENTFUL_TOKEN }}
NX_CLOUD_DISTRIBUTED_EXECUTION: false
NX_PUBLIC_AMPLITUDE_KEY: ${{ secrets.NX_PUBLIC_AMPLITUDE_KEY }}
NX_PUBLIC_ROLLBAR_KEY: ${{ secrets.NX_PUBLIC_ROLLBAR_KEY }}
NX_PUBLIC_CLIENT_URL: 'http://localhost:3333/app'
NX_PUBLIC_SERVER_URL: 'http://localhost:3333'

Expand Down
4 changes: 2 additions & 2 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"releaseName": "Jetstream ${version}"
},
"hooks": {
"before:init": ["yarn test:all", "SKIP_ROLLBAR=true yarn build"],
"after:release": "CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && git checkout release && git reset --hard $CURRENT_BRANCH && git push origin release -f && git checkout main && yarn rollbar:create-deploy"
"before:init": ["yarn test:all", "SKIP_SENTRY=true yarn build"],
"after:release": "CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) && git checkout release && git reset --hard $CURRENT_BRANCH && git push origin release -f && git checkout main"
}
}
55 changes: 34 additions & 21 deletions apps/api/src/app/utils/response.handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ENV, getExceptionLog, logger, prisma, rollbarServer } from '@jetstream/api-config';
import { ENV, getExceptionLog, logger, prisma, sentryServer } from '@jetstream/api-config';
import { AuthError, createCSRFToken, getCookieConfig } from '@jetstream/auth/server';
import { ERROR_MESSAGES, HTTP } from '@jetstream/shared/constants';
import { Maybe } from '@jetstream/types';
Expand Down Expand Up @@ -76,14 +76,17 @@ export function sendJson<ResponseType = unknown>(res: Response, content?: Respon
if (res.headersSent) {
res.log.warn('Response headers already sent');
try {
rollbarServer.warn('Response not handled by sendJson, headers already sent', new Error('headers already sent'), {
context: `route#sendJson`,
custom: {
sentryServer.captureException(new Error('headers already sent'), {
tags: {
requestId: res.locals.requestId,
},
extra: {
message: 'Response not handled by sendJson, headers already sent',
location: `route#sendJson`,
},
});
} catch (ex) {
res.log.error(getExceptionLog(ex), 'Error sending to Rollbar');
res.log.error(getExceptionLog(ex), 'Error sending to Sentry');
}
return;
}
Expand Down Expand Up @@ -141,20 +144,25 @@ export async function uncaughtErrorHandler(err: any, req: express.Request, res:
if (res.headersSent) {
responseLogger.warn('Response headers already sent');
try {
rollbarServer.warn('Error not handled by error handler, headers already sent', req, {
context: `route#errorHandler`,
custom: {
...getExceptionLog(err, true),
sentryServer.captureException(new Error('headers already sent'), {
user: {
id: req.session.user?.id,
email: req.session.user?.email,
name: req.session.user?.name,
},
tags: {
requestId: res.locals.requestId,
},
extra: {
message: 'Response not handled by sendJson, headers already sent',
location: `route#sendJson`,
url: req.url,
params: req.params,
query: req.query,
body: req.body,
userId: req.session.user?.id,
requestId: res.locals.requestId,
},
});
} catch (ex) {
responseLogger.error(getExceptionLog(ex), 'Error sending to Rollbar');
responseLogger.error(getExceptionLog(ex), 'Error sending to Sentry');
}
return;
}
Expand Down Expand Up @@ -258,20 +266,25 @@ export async function uncaughtErrorHandler(err: any, req: express.Request, res:
}

try {
rollbarServer.warn('Error not handled by error handler', req, {
context: `route#errorHandler`,
custom: {
...getExceptionLog(err, true),
sentryServer.captureException(new Error('headers already sent'), {
user: {
id: req.session.user?.id,
email: req.session.user?.email,
name: req.session.user?.name,
},
tags: {
requestId: res.locals.requestId,
},
extra: {
message: 'Error not handled by ErrorHandler',
location: `route#errorHandler`,
url: req.url,
params: req.params,
query: req.query,
body: req.body,
userId: req.session.user?.id,
requestId: res.locals.requestId,
},
});
} catch (ex) {
responseLogger.error(getExceptionLog(ex), 'Error sending to Rollbar');
responseLogger.error(getExceptionLog(ex), 'Error sending to Sentry');
}

const errorMessage = 'There was an error processing the request';
Expand Down
21 changes: 11 additions & 10 deletions apps/api/src/app/utils/route.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExceptionLog, logger, rollbarServer } from '@jetstream/api-config';
import { getExceptionLog, logger, sentryServer } from '@jetstream/api-config';
import { CookieOptions, UserProfileSession } from '@jetstream/auth/types';
import { ApiConnection } from '@jetstream/salesforce-api';
import { NextFunction } from 'express';
Expand Down Expand Up @@ -98,18 +98,19 @@ export function createRoute<TParamsSchema extends z.ZodTypeAny, TBodySchema exte
next(ex);
}
} catch (ex) {
rollbarServer.error('Route Validation Error', req, {
context: `route#createRoute`,
custom: {
...getExceptionLog(ex, true),
message: ex.message,
stack: ex.stack,
sentryServer.captureException(ex, {
user: {
id: req.session.user?.id,
email: req.session.user?.email,
name: req.session.user?.name,
},
tags: { requestId: res.locals.requestId },
extra: {
message: 'Route validation error',
location: `route#createRoute`,
url: req.url,
params: req.params,
query: req.query,
body: req.body,
userId: req.session.user?.id,
requestId: res.locals.requestId,
},
});
req.log.error(getExceptionLog(ex), '[ROUTE][VALIDATION ERROR]');
Expand Down
55 changes: 39 additions & 16 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,23 @@ if (ENV.NODE_ENV === 'production' && !ENV.CI && cluster.isPrimary) {
// Setup session
app.use(sessionMiddleware);

const sentryReportingUri = ENV.SENTRY_CSP_REPORT_URI
? `${ENV.SENTRY_CSP_REPORT_URI}&sentry_environment=${ENV.ENVIRONMENT}&sentry_release=${ENV.VERSION || 'unknown'}`
: null;

// app.use(compression());
app.use(
helmet({
contentSecurityPolicy: {
directives: {
reportUri: sentryReportingUri || [],
reportTo: 'csp-endpoint',
defaultSrc: [
"'self'",
'*.google-analytics.com',
'*.google.com',
'*.googleapis.com',
'*.gstatic.com',
'*.rollbar.com',
'api.amplitude.com',
'api.cloudinary.com',
'https://challenges.cloudflare.com',
Expand All @@ -167,6 +172,7 @@ if (ENV.NODE_ENV === 'production' && !ENV.CI && cluster.isPrimary) {
'https://api.stripe.com',
'https://*.js.stripe.com',
'https://hooks.stripe.com',
'*.sentry.io',
],
baseUri: ["'self'"],
blockAllMixedContent: [],
Expand Down Expand Up @@ -216,6 +222,21 @@ if (ENV.NODE_ENV === 'production' && !ENV.CI && cluster.isPrimary) {
})
);

app.use((req, res, next) => {
if (sentryReportingUri) {
res.setHeader(
'Report-To',
JSON.stringify({
group: 'csp-endpoint',
max_age: 10886400,
endpoints: [{ url: sentryReportingUri }],
include_subdomains: true,
})
);
}
next();
});

app.use(blockBotByUserAgentMiddleware);

if (ENV.ENVIRONMENT === 'development') {
Expand Down Expand Up @@ -329,7 +350,7 @@ if (ENV.NODE_ENV === 'production' && !ENV.CI && cluster.isPrimary) {

app.use('/webhook', webhookRoutes);

app.use(raw({ limit: '30mb', type: ['text/csv'] }));
app.use(raw({ limit: '30mb', type: ['text/csv', 'text/plain'] }));
app.use(raw({ limit: '30mb', type: ['application/zip'] }));
app.use(json({ limit: '20mb', type: ['json', 'application/csp-report'] }));
app.use(urlencoded({ extended: true }));
Expand Down Expand Up @@ -408,23 +429,25 @@ if (ENV.NODE_ENV === 'production' && !ENV.CI && cluster.isPrimary) {
logger.error(getExceptionLog(error), '[SERVER][ERROR]');
});

process.on('SIGTERM', () => {
logger.info('SIGTERM received, shutting down gracefully');
server.close(() => {
logger.info('Server closed');
if (ENV.ENVIRONMENT !== 'development') {
process.on('SIGTERM', () => {
logger.info('SIGTERM received, shutting down gracefully');
server.close(() => {
logger.info('Server closed');

pgPool.end().then(() => {
logger.info('DB pool closed');
process.exit(0);
pgPool.end().then(() => {
logger.info('DB pool closed');
process.exit(0);
});
});
});

// Force close after 30s
setTimeout(() => {
logger.error('Could not close connections in time, forcefully shutting down');
process.exit(1);
}, 30_000);
});
// Force close after 30s
setTimeout(() => {
logger.error('Could not close connections in time, forcefully shutting down');
process.exit(1);
}, 30_000);
});
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion apps/cron-tasks/src/config/env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const ENV = {
NODE_ENV: process.env.NODE_ENV,
ENVIRONMENT: process.env.ENVIRONMENT || 'production',
GIT_VERSION: VERSION,
ROLLBAR_SERVER_TOKEN: process.env.ROLLBAR_SERVER_TOKEN,
// FIXME: there was a typo in env variables, using both temporarily as a safe fallback
JETSTREAM_POSTGRES_DBURI: process.env.JETSTREAM_POSTGRES_DBURI || process.env.JESTREAM_POSTGRES_DBURI,
PRISMA_DEBUG: process.env.PRISMA_DEBUG && process.env.PRISMA_DEBUG.toLocaleLowerCase().startsWith('t'),
Expand Down
14 changes: 6 additions & 8 deletions apps/geo-ip-api/src/route.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExceptionLog, rollbarServer } from '@jetstream/api-config';
import { getExceptionLog, sentryServer } from '@jetstream/api-config';
import type { Request as ExpressRequest, Response as ExpressResponse } from 'express';
import { NextFunction } from 'express';
import type pino from 'pino';
Expand Down Expand Up @@ -48,16 +48,14 @@ export function createRoute<TParamsSchema extends z.ZodTypeAny, TBodySchema exte
next(ex);
}
} catch (ex) {
rollbarServer.error('Route Validation Error', req, {
context: `route#createRoute`,
custom: {
...getExceptionLog(ex, true),
message: ex.message,
stack: ex.stack,
sentryServer.captureException(ex, {
tags: { requestId: res.locals.requestId },
extra: {
message: 'Route validation error',
location: `route#createRoute`,
url: req.url,
params: req.params,
query: req.query,
body: req.body,
},
});
req.log.error(getExceptionLog(ex), '[ROUTE][VALIDATION ERROR]');
Expand Down
4 changes: 2 additions & 2 deletions apps/jetstream-web-extension/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"configurations": {
"development": {
"fileReplacements": [],
"optimization": false,
"optimization": true,
"outputHashing": "none",
"sourceMap": false,
"sourceMap": true,
"namedChunks": false,
"extractLicenses": false,
"vendorChunk": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: true,
serverUrl: 'https://getjetstream.app',
rollbarClientAccessToken: process.env.NX_PUBLIC_ROLLBAR_KEY,
sentryDsn: process.env.NX_PUBLIC_SENTRY_DSN,
amplitudeToken: process.env.NX_PUBLIC_AMPLITUDE_KEY,
isWebExtension: true,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: true,
serverUrl: 'https://staging.jetstream-app.com',
rollbarClientAccessToken: process.env.NX_PUBLIC_ROLLBAR_KEY,
sentryDsn: process.env.NX_PUBLIC_SENTRY_DSN,
amplitudeToken: process.env.NX_PUBLIC_AMPLITUDE_KEY,
isWebExtension: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export const environment = {
production: false,
serverUrl: 'http://localhost:3333',
rollbarClientAccessToken: process.env.NX_PUBLIC_ROLLBAR_KEY,
sentryDsn: process.env.NX_PUBLIC_SENTRY_DSN,
amplitudeToken: process.env.NX_PUBLIC_AMPLITUDE_KEY,
isWebExtension: true,
};
5 changes: 2 additions & 3 deletions apps/jetstream-web-extension/src/pages/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import { SObjectExport } from '@jetstream/feature/sobject-export';
import { MassUpdateRecords, MassUpdateRecordsDeployment, MassUpdateRecordsSelection } from '@jetstream/feature/update-records';
import { APP_ROUTES } from '@jetstream/shared/ui-router';
import { appActionObservable, AppActionTypes } from '@jetstream/shared/ui-utils';
import { AppHome, AppLoading, ErrorBoundaryFallback, Feedback, HeaderNavbar } from '@jetstream/ui-core';
import { AppHome, AppLoading, ErrorBoundary, Feedback, HeaderNavbar } from '@jetstream/ui-core';
import { Suspense, useEffect } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';
import { AppWrapper } from '../../core/AppWrapper';
import { initAndRenderReact } from '../../utils/web-extension.utils';
Expand Down Expand Up @@ -62,7 +61,7 @@ export function App() {
<HeaderNavbar isBillingEnabled={false} isChromeExtension />
<div className="app-container slds-p-horizontal_xx-small slds-p-vertical_xx-small" data-testid="content">
<Suspense fallback={<AppLoading />}>
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<ErrorBoundary>
<Routes>
<Route path={APP_ROUTES.HOME.ROUTE} element={<AppHome showChromeExtension={false} />} />
<Route path={APP_ROUTES.QUERY.ROUTE} element={<Query />}>
Expand Down
14 changes: 13 additions & 1 deletion apps/jetstream-web-extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,28 @@ module.exports = composePlugins(withNx(), withReact(), (config, { configuration
},
},
};

config.plugins = config.plugins || [];
config.plugins.push(
// @ts-expect-error this is valid, not sure why it is complaining
new webpack.NormalModuleReplacementPlugin(/@sentry\/react/, '@jetstream/mocks/sentry')
);
// Omit Sentry from the build - it is huge and there is a lot of work to get it going with the web extension
config.plugins.push(
// @ts-expect-error this is valid, not sure why it is complaining
new webpack.EnvironmentPlugin({
NX_PUBLIC_AMPLITUDE_KEY: '',
NX_PUBLIC_ROLLBAR_KEY: '',
NX_PUBLIC_SENTRY_DSN: '',
}),
new webpack.DefinePlugin({
'globalThis.__IS_BROWSER_EXTENSION__': true,
'import.meta.env.NX_PUBLIC_AMPLITUDE_KEY': 'null',
'import.meta.env.NX_PUBLIC_SENTRY_DSN': 'null',
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
__RRWEB_EXCLUDE_IFRAME__: true,
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
}),
createHtmlPagePlugin('app', 'app'),
createHtmlPagePlugin('popup', 'popup'),
Expand Down
Loading
Loading