Skip to content

Commit

Permalink
Merge pull request #25 from J-Hoplin/feat/sentry
Browse files Browse the repository at this point in the history
Feat/sentry
  • Loading branch information
J-Hoplin authored Jan 17, 2024
2 parents 3790b78 + 0f4a538 commit 7dd32d5
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ AWS_REGION=""
AWS_ACCESS_ID=""
AWS_ACCESS_SECRET=""
AWS_SQS_QUEUE=""
AWS_S3_BUCKET=""
AWS_S3_BUCKET=""

# Sentry
SENTRY_DSN=""
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.16",
"@prisma/client": "^5.6.0",
"@sentry/node": "^7.93.0",
"@sentry/profiling-node": "^1.3.5",
"@types/multer": "^1.4.11",
"axios": "^1.6.2",
"bcryptjs": "^2.4.3",
Expand Down
1 change: 1 addition & 0 deletions src/filter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sentry.filter';
11 changes: 11 additions & 0 deletions src/filter/sentry.filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ArgumentsHost, Catch } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import * as Sentry from '@sentry/node';

@Catch()
export class SentryFilter extends BaseExceptionFilter {
catch(exception: any, host: ArgumentsHost): void {
Sentry.captureException(exception);
super.catch(exception, host);
}
}
21 changes: 20 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { InitializeAdmin } from './admin-init';
import { AppModule } from './app.module';
import { SentryFilter } from './filter';
import * as Sentry from '@sentry/node';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

// Get Express http adapter
const { httpAdapter } = app.get(HttpAdapterHost);

app.enableCors();
app.useGlobalPipes(
// Docs: https://docs.nestjs.com/techniques/validation
Expand All @@ -18,6 +24,11 @@ async function bootstrap() {
const config = new DocumentBuilder()
.setTitle('Online-Judge-Server')
.setDescription('Online Judge Server')
.setContact(
'J-Hoplin',
'https://github.com/J-Hoplin',
'hoplin.dev@gmail.com',
)
.setVersion('1.0')
.addBearerAuth()
.build();
Expand All @@ -30,6 +41,14 @@ async function bootstrap() {
explorer: true,
});

// Sentry
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});
app.useGlobalFilters(new SentryFilter(httpAdapter));

await app.listen(process.env.PORT || 3000);
}
bootstrap();
77 changes: 76 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,54 @@
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.6.0.tgz#82c445aa10633bbc0388aa2d6e411a0bd94c9439"
integrity sha512-Mt2q+GNJpU2vFn6kif24oRSBQv1KOkYaterQsi0k2/lA+dLvhRX6Lm26gon6PYHwUM8/h8KRgXIUMU0PCLB6bw==

"@sentry-internal/tracing@7.93.0":
version "7.93.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.93.0.tgz#8cee8b610695d828af75edd2929b64b7caf0385d"
integrity sha512-DjuhmQNywPp+8fxC9dvhGrqgsUb6wI/HQp25lS2Re7VxL1swCasvpkg8EOYP4iBniVQ86QK0uITkOIRc5tdY1w==
dependencies:
"@sentry/core" "7.93.0"
"@sentry/types" "7.93.0"
"@sentry/utils" "7.93.0"

"@sentry/core@7.93.0":
version "7.93.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.93.0.tgz#50a14bf305130dfef51810e4c97fcba4972a57ef"
integrity sha512-vZQSUiDn73n+yu2fEcH+Wpm4GbRmtxmnXnYCPgM6IjnXqkVm3awWAkzrheADblx3kmxrRiOlTXYHw9NTWs56fg==
dependencies:
"@sentry/types" "7.93.0"
"@sentry/utils" "7.93.0"

"@sentry/node@^7.93.0":
version "7.93.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.93.0.tgz#7786d05d1e3e984207a866b07df1bf891355892e"
integrity sha512-nUXPCZQm5Y9Ipv7iWXLNp5dbuyi1VvbJ3RtlwD7utgsNkRYB4ixtKE9w2QU8DZZAjaEF6w2X94OkYH6C932FWw==
dependencies:
"@sentry-internal/tracing" "7.93.0"
"@sentry/core" "7.93.0"
"@sentry/types" "7.93.0"
"@sentry/utils" "7.93.0"
https-proxy-agent "^5.0.0"

"@sentry/profiling-node@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@sentry/profiling-node/-/profiling-node-1.3.5.tgz#e7e15fae88745b4c062ca49086bf85688b6ffe66"
integrity sha512-n2bfEbtLW3WuIMQGyxKJKzBNZOb1JYfMeJQ2WQn/42F++69m+u7T0S3EDGRN0Y//fbt5+r0any+4r3kChRXZkQ==
dependencies:
detect-libc "^2.0.2"
node-abi "^3.52.0"

"@sentry/types@7.93.0":
version "7.93.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.93.0.tgz#d76d26259b40cd0688e1d634462fbff31476c1ec"
integrity sha512-UnzUccNakhFRA/esWBWP+0v7cjNg+RilFBQC03Mv9OEMaZaS29zSbcOGtRzuFOXXLBdbr44BWADqpz3VW0XaNw==

"@sentry/utils@7.93.0":
version "7.93.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.93.0.tgz#36225038661fe977baf01e4695ef84794d591e45"
integrity sha512-Iovj7tUnbgSkh/WrAaMrd5UuYjW7AzyzZlFDIUrwidsyIdUficjCG2OIxYzh76H6nYIx9SxewW0R54Q6XoB4uA==
dependencies:
"@sentry/types" "7.93.0"

"@sinclair/typebox@^0.27.8":
version "0.27.8"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
Expand Down Expand Up @@ -3121,6 +3169,13 @@ acorn@^8.4.1, acorn@^8.7.1, acorn@^8.8.2, acorn@^8.9.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.2.tgz#ca0d78b51895be5390a5903c5b3bdcdaf78ae40b"
integrity sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==

agent-base@6:
version "6.0.2"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==
dependencies:
debug "4"

ajv-formats@2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520"
Expand Down Expand Up @@ -3785,7 +3840,7 @@ debug@2.6.9:
dependencies:
ms "2.0.0"

debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand Down Expand Up @@ -3838,6 +3893,11 @@ destroy@1.2.0:
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015"
integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==

detect-libc@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.2.tgz#8ccf2ba9315350e1241b88d0ac3b0e1fbd99605d"
integrity sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==

detect-newline@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
Expand Down Expand Up @@ -4601,6 +4661,14 @@ http-errors@2.0.0:
statuses "2.0.1"
toidentifier "1.0.1"

https-proxy-agent@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz#c59ef224a04fe8b754f3db0063a25ea30d0005d6"
integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==
dependencies:
agent-base "6"
debug "4"

human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
Expand Down Expand Up @@ -5664,6 +5732,13 @@ neo-async@^2.6.2:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==

node-abi@^3.52.0:
version "3.54.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.54.0.tgz#f6386f7548817acac6434c6cba02999c9aebcc69"
integrity sha512-p7eGEiQil0YUV3ItH4/tBb781L5impVmmx2E9FRKF7d18XXzp4PGT2tdYMFY6wQqgxD0IwNZOiSJ0/K0fSi/OA==
dependencies:
semver "^7.3.5"

node-abort-controller@^3.0.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.1.1.tgz#a94377e964a9a37ac3976d848cb5c765833b8548"
Expand Down

0 comments on commit 7dd32d5

Please sign in to comment.