Skip to content

Commit

Permalink
feat: configure initial config for Sentry in the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
V-ed committed Oct 13, 2024
1 parent 13c16ad commit 2ece582
Show file tree
Hide file tree
Showing 10 changed files with 728 additions and 37 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/deploy-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ jobs:
git_remote_url: 'ssh://dokku@${{ vars.DOKKU_SSH_HOST }}/${{ vars.DOKKU_APPNAME }}'
ssh_private_key: ${{ secrets.DOKKU_SSH_KEY }}

- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
with:
environment: 'api-prod'
working_directory: './api'
sourcemaps: './dist'

- name: Delete deploy branch
uses: dawidd6/action-delete-branch@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ TEST_DATABASE_URL=postgres://${DB_TEST_USER}:${DB_TEST_PSW}@${DB_TEST_CONN}/${DB

# There are rules for bucket naming, so please refer to https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
MINIO_BUCKET_PREFIX='fullstacked'

# --------------------------------
# --- Sentry variables ---
# --------------------------------

SENTRY_DSN=
8 changes: 7 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"test:e2e": "vitest --config tests/.vitest/vitest.config.e2e.ts",
"coverage": "pnpm run test --coverage",
"seed": "gulp seed",
"studio": "prisma studio"
"studio": "prisma studio",
"sentry:sourcemaps": "npm-run-all -s sentry:sourcemaps:inject sentry:sourcemaps:upload",
"sentry:sourcemaps:inject": "sentry-cli sourcemaps inject --org v-ed --project fullstacked ./dist",
"sentry:sourcemaps:upload": "sentry-cli sourcemaps upload --org v-ed --project fullstacked ./dist"
},
"prisma": {
"seed": "tsx prisma/seed.ts"
Expand All @@ -47,6 +50,8 @@
"@nestjs/throttler": "5.1.2",
"@nestjs/websockets": "10.3.3",
"@prisma/client": "5.10.1",
"@sentry/nestjs": "8.34.0",
"@sentry/profiling-node": "8.34.0",
"@sveltekit-i18n/parser-default": "1.1.1",
"@ts-rest/core": "3.33.0",
"@ts-rest/nest": "3.33.0",
Expand All @@ -73,6 +78,7 @@
"@nestjs/cli": "10.3.2",
"@nestjs/schematics": "10.1.1",
"@nestjs/testing": "10.3.3",
"@sentry/cli": "2.37.0",
"@swc/core": "1.4.2",
"@types/cookie-parser": "1.4.6",
"@types/express": "4.17.21",
Expand Down
2 changes: 2 additions & 0 deletions api/src/@common/app/app.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ContextModule } from '$context/context.module';
import { EmailModule } from '$email/email.module';
import { TypedI18nModule } from '$i18n/i18n.module';
import { PrismaModule } from '$prisma/prisma.module';
import { SentryModule } from '$sentry/sentry.module';
import { SocketModule } from '$socket/socket.module';
import { UsersModule } from '$users/users.module';
import { ModuleMetadata } from '@nestjs/common';
Expand All @@ -13,6 +14,7 @@ import { throttlerConf } from './throttler.guard';

export const BaseModules = [
ConfigModule,
SentryModule,
PrismaModule,
ContextModule,
SocketModule,
Expand Down
21 changes: 21 additions & 0 deletions api/src/@common/sentry/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */

import env from '$configs';
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { Environment } from '~env';

Sentry.init({
dsn: env.SENTRY_DSN,
integrations: [nodeProfilingIntegration()],

environment: env.NODE_ENV === Environment.Production ? 'api-prod' : 'api-develop',

// Add Tracing by setting tracesSampleRate
// We recommend adjusting this value in production
tracesSampleRate: env.NODE_ENV !== Environment.Production ? 1.0 : 0.1,

// Set sampling rate for profiling
// This is relative to tracesSampleRate
profilesSampleRate: 1.0,
});
14 changes: 14 additions & 0 deletions api/src/@common/sentry/sentry.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { SentryGlobalFilter, SentryModule as SentryModuleNestJS } from '@sentry/nestjs/setup';

@Module({
imports: [SentryModuleNestJS.forRoot()],
providers: [
{
provide: APP_FILTER,
useClass: SentryGlobalFilter,
},
],
})
export class SentryModule {}
7 changes: 7 additions & 0 deletions api/src/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ export class EnvironmentConfig {

@IsString()
readonly MINIO_BUCKET_PREFIX!: string;

// ---------------
// Sentry
// ---------------

@IsString()
readonly SENTRY_DSN!: string;
}
2 changes: 2 additions & 0 deletions api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '$sentry/instrument';

import { setupApp } from '$app/setupApp';
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
Expand Down
3 changes: 3 additions & 0 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"outDir": "./dist",

"declaration": false,
"sourceMap": true,

"sourceRoot": "/",

"importsNotUsedAsValues": "remove",
"verbatimModuleSyntax": false,
Expand Down
Loading

0 comments on commit 2ece582

Please sign in to comment.