Skip to content
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

feat(api): Add Sentry Integeration #133

Merged
merged 21 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_CALLBACK_URL=

SENTRY_DSN=
SENTRY_TRACES_SAMPLE_RATE=
SENTRY_PROFILES_SAMPLE_RATE=

SMTP_HOST=
SMTP_PORT=
SMTP_EMAIL_ADDRESS=
Expand All @@ -15,3 +19,5 @@ JWT_SECRET=secret

WEB_FRONTEND_URL=https://keyshade.xyz
WORKSPACE_FRONTEND_URL=https://app.keyshade.xyz

NODE_ENV='development <prod | dev>'
HarshPatel5940 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ Thumbs.db
pnpm-lock.yaml

# Database
data/
data/
# Sentry Config File
.sentryclirc
67 changes: 44 additions & 23 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import chalk from 'chalk'
import moment from 'moment'
import { QueryTransformPipe } from './common/query.transform.pipe'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import * as Sentry from '@sentry/node'
import { ProfilingIntegration } from '@sentry/profiling-node'

class CustomLogger implements LoggerService {
log(message: string) {
Expand Down Expand Up @@ -43,30 +45,49 @@ class CustomLogger implements LoggerService {
}

async function bootstrap() {
const logger = new CustomLogger()
const app = await NestFactory.create(AppModule, {
logger
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
tracesSampleRate: Number(process.env.SENTRY_TRACES_SAMPLE_RATE) || 1.0,
profilesSampleRate: Number(process.env.SENTRY_PROFILES_SAMPLE_RATE) || 1.0,
integrations: [new ProfilingIntegration()],
debug: process.env.NODE_ENV.startsWith('dev')
})
const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true
}),
new QueryTransformPipe()
)
const port = 4200
const swaggerConfig = new DocumentBuilder()
.setTitle('keyshade')
.setDescription('The keyshade API description')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, swaggerConfig)
SwaggerModule.setup('docs', app, document)
await app.listen(port)
logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
await Sentry.startSpan(
{
op: 'mainSpan',
name: 'My Main Span'
},
async () => {
const logger = new CustomLogger()
const app = await NestFactory.create(AppModule, {
logger
})
app.use(Sentry.Handlers.requestHandler())
app.use(Sentry.Handlers.tracingHandler())
const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true
}),
new QueryTransformPipe()
)
const port = 4200
const swaggerConfig = new DocumentBuilder()
.setTitle('keyshade')
.setDescription('The keyshade API description')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, swaggerConfig)
SwaggerModule.setup('docs', app, document)
app.use(Sentry.Handlers.errorHandler())
await app.listen(port)
logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
)
}
)
}

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"prettier:fix": "nx run-many -t prettier:lint --parallel",
"prettier:fix:api": "nx run api:prettier:fix",
"build": "nx run-many -t build -p api web workspace --parallel --maxParallel 3",
"build:api": "nx run api:build --configuration=production",
"build:api": "nx run api:build --configuration=production && pnpm sentry:sourcemaps",
HarshPatel5940 marked this conversation as resolved.
Show resolved Hide resolved
"build:web": "nx run web:build --configuration=production",
"build:workspace": "nx run workspace:build",
"test": "nx run-many -t test --parallel",
Expand All @@ -114,7 +114,8 @@
"db:validate": "nx run api:prisma:validate",
"db:format": "nx run api:prisma:format",
"db:reset": "nx run api:prisma:reset",
"prepare": "husky install"
"prepare": "husky install",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org programmingnotcoding --project node ./dist && sentry-cli sourcemaps upload --org programmingnotcoding --project node ./dist"
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@nestjs/schematics": "^10.0.3",
Expand Down Expand Up @@ -181,6 +182,9 @@
"@semantic-release/commit-analyzer": "^11.1.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/release-notes-generator": "^12.1.0",
"@sentry/cli": "^2.28.0",
"@sentry/node": "^7.100.1",
"@sentry/profiling-node": "^7.100.1",
"@supabase/supabase-js": "^2.39.2",
"@types/jsonwebtoken": "^9.0.5",
"axios": "^1.6.5",
Expand Down
10 changes: 9 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",

"paths": {
"cli": ["apps/cli/src/index.ts"]
}
},

"inlineSources": true,

// Set `sourceRoot` to "/" to strip the build path prefix
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
// from generated source code references.
// This improves issue grouping in Sentry.
"sourceRoot": "/"
},
"exclude": ["node_modules", "tmp"]
}
Loading