Skip to content

Commit

Permalink
update sentry for corpus and prospect API
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetto committed Nov 8, 2024
1 parent 3482f19 commit 70e9657
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 63 deletions.
32 changes: 1 addition & 31 deletions servers/curated-corpus-api/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,6 @@ export async function startServer(port: number): Promise<{
const app = express();
const httpServer = http.createServer(app);

Sentry.init({
...config.sentry,
includeLocalVariables: true,
maxValueLength: 2000,
integrations: [
// apollo integration is broken at the moment 😕
// https://github.com/getsentry/sentry-javascript/issues/6899
//new Sentry.Integrations.Apollo(),
new Sentry.Integrations.GraphQL(),
new Sentry.Integrations.Mysql(),
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Sentry.Integrations.Express({
// to trace all requests to the default router
app,
}),
],
debug: config.sentry.environment == 'development',
});

// RequestHandler creates a separate execution context, so that all
// transactions/spans/breadcrumbs are isolated across requests.
// Because NODE is a single running process loop!
// MUST BE THE FIRST MIDDLEWARE ADDED!
app.use(Sentry.Handlers.requestHandler() as express.RequestHandler);

// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());

app.use(
// JSON parser to enable POST body with JSON
express.json(),
Expand Down Expand Up @@ -111,7 +81,7 @@ export async function startServer(port: number): Promise<{
);

// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler() as express.ErrorRequestHandler);
Sentry.setupExpressErrorHandler(app);

await new Promise<void>((resolve) => httpServer.listen({ port }, resolve));
return { app, adminServer, adminUrl, publicServer, publicUrl };
Expand Down
9 changes: 9 additions & 0 deletions servers/curated-corpus-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { serverLogger } from '@pocket-tools/ts-logger';
import * as Sentry from '@sentry/node';

import {
curatedCorpusEventEmitter,
Expand All @@ -14,6 +15,14 @@ import {
import { startServer } from './express';
import config from './config';

Sentry.init({
...config.sentry,
includeLocalVariables: true,
maxValueLength: 2000,
integrations: [Sentry.prismaIntegration()],
debug: config.sentry.environment == 'development',
});

// Initialize event handlers, this is outside server setup as tests
// mock event handling
initItemEventHandlers(curatedCorpusEventEmitter, [
Expand Down
33 changes: 1 addition & 32 deletions servers/prospect-api/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { setLogger, setMorgan } from '@pocket-tools/ts-logger';
import { AdminAPIUserContext } from './types';
import { getContext } from './context';
import { startApolloServer } from './server';
import config from './config';

export const serverLogger: any = setLogger();

Expand All @@ -32,36 +31,6 @@ export async function startServer(port: number): Promise<{
const app = express();
const httpServer = http.createServer(app);

Sentry.init({
...config.sentry,
includeLocalVariables: true,
maxValueLength: 2000,
integrations: [
// apollo integration is broken at the moment 😕
// https://github.com/getsentry/sentry-javascript/issues/6899
//new Sentry.Integrations.Apollo(),
new Sentry.Integrations.GraphQL(),
new Sentry.Integrations.Mysql(),
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Sentry.Integrations.Express({
// to trace all requests to the default router
app,
}),
],
debug: config.sentry.environment === 'development',
});

// RequestHandler creates a separate execution context, so that all
// transactions/spans/breadcrumbs are isolated across requests.
// Because NODE is a single running process loop!
// MUST BE THE FIRST MIDDLEWARE ADDED!
app.use(Sentry.Handlers.requestHandler() as express.RequestHandler);

// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());

// JSON parser to enable POST body with JSON
app.use(express.json(), setMorgan(serverLogger));

Expand All @@ -82,7 +51,7 @@ export async function startServer(port: number): Promise<{
);

// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler() as express.ErrorRequestHandler);
Sentry.setupExpressErrorHandler(app);

await new Promise<void>((resolve) => httpServer.listen({ port }, resolve));
return { app, apolloServer, url };
Expand Down
9 changes: 9 additions & 0 deletions servers/prospect-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { serverLogger } from '@pocket-tools/ts-logger';
import * as Sentry from '@sentry/node';

import config from './config';
import { startServer } from './express';

Sentry.init({
...config.sentry,
includeLocalVariables: true,
maxValueLength: 2000,
debug: config.sentry.environment == 'development',
});

(async () => {
const { url } = await startServer(4026);
serverLogger.info(`🚀 Server ready at http://localhost:4026${url}`);
Expand Down

0 comments on commit 70e9657

Please sign in to comment.