Skip to content
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: 4 additions & 0 deletions .github/actions/build-images/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
aws-role-arn:
description: 'AWS Role to assume'
required: true
sentry-token:
description: 'Sentry auth token to push sourcemaps'
required: true

runs:
using: composite
Expand All @@ -31,5 +34,6 @@ runs:
- name: Build and push the images
env:
TAG: ${{ inputs.tag }}
SENTRY_AUTH_TOKEN: ${{ inputs.sentry-token }}
run: bash ./docker/build.sh ${{ inputs.aws-ecr-uri }} $TAG
shell: bash
1 change: 1 addition & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ jobs:
aws-ecr-uri: ${{ vars.PRIVATE_ECR }}
aws-role-arn: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
aws-ecr-uri: ${{ vars.GRAASP_PUBLIC_ECR }}
aws-role-arn: ${{ vars.AWS_ROLE_ARN }}
aws-region: us-east-1
sentry-token: ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: Auto Tag
uses: graasp/graasp-deploy/.github/actions/auto-tag-after-release@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ secret-key
# Generated
openapi.json
vacuum-report.html

# Sentry Config File
.sentryclirc
32 changes: 32 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ ENV NODE_ENV=production
COPY . .
RUN yarn build-ts

# -------------------------------------------------------
FROM base AS build-sources

WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
# We need a specific command because we need to copy the folder with it, not just the content.
COPY .yarn/releases ./.yarn/releases/
RUN yarn set version berry && yarn install --immutable

ENV NODE_ENV=production
COPY . .
RUN yarn build-ts --sourceMap true --sourceRoot '/'

# send sourcemaps to Sentry
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN,env=SENTRY_AUTH_TOKEN yarn sentry:sourcemaps

# -------------------------------------------------------
FROM base AS build-sources

WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
# We need a specific command because we need to copy the folder with it, not just the content.
COPY .yarn/releases ./.yarn/releases/
RUN yarn set version berry && yarn install --immutable

ENV NODE_ENV=production
COPY . .
RUN yarn build-ts --sourceMap true --sourceRoot '/'

# send sourcemaps to Sentry
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN,env=SENTRY_AUTH_TOKEN yarn sentry:sourcemaps

# -------------------------------------------------------
FROM base AS deps

Expand Down
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ workers_tag_full="$aws_ecr_uri/$workers_tag_short"
migrate_tag_short="graasp:migrate-$tag_version"
migrate_tag_full="$aws_ecr_uri/$migrate_tag_short"

docker build -t $core_tag_full -f docker/Dockerfile --build-arg APP_VERSION=$tag_version --build-arg BUILD_TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%S) .
docker build -t $core_tag_full -f docker/Dockerfile --build-arg APP_VERSION=$tag_version --build-arg BUILD_TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%S) --secret id=SENTRY_AUTH_TOKEN .
docker push $core_tag_full

docker build -t $workers_tag_full -f docker/workers.Dockerfile --build-arg APP_VERSION=$tag_version --build-arg BUILD_TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%S) .
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"migration:apply-test": "DB_CONNECTION=postgres://test:test@db:5432/test yarn migration:run",
"migration:generate": "yarn drizzle-kit generate",
"migration:run": "yarn drizzle-kit migrate",
"migration:check": "yarn drizzle-kit generate --name=migrationtest --out=./src/drizzle --schema=./src/drizzle/schema.ts --dialect=postgresql && [ -f '$(find ./src/drizzle | grep migrationtest)' ] && exit 1 || exit 0"
"migration:check": "yarn drizzle-kit generate --name=migrationtest --out=./src/drizzle --schema=./src/drizzle/schema.ts --dialect=postgresql && [ -f '$(find ./src/drizzle | grep migrationtest)' ] && exit 1 || exit 0",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org graasp --project graasp-core ./dist && sentry-cli sourcemaps upload --org graasp --project graasp-core ./dist"
},
"dependencies": {
"@aws-sdk/client-s3": "3.787.0",
Expand All @@ -69,7 +70,10 @@
"@graasp/etherpad-api": "2.1.1",
"@graasp/sdk": "5.16.3",
"@rapideditor/country-coder": "5.4.0",
"@sentry/node": "7.119.2",
"@sentry/cli": "2.57.0",
"@sentry/node": "10.20.0",
"@sentry/opentelemetry": "10.20.0",
"@sentry/profiling-node": "10.20.0",
"@sentry/tracing": "7.120.3",
"@sinclair/typebox": "0.34.33",
"ajv": "8.17.1",
Expand Down
40 changes: 40 additions & 0 deletions src/0-instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This file is names with a leading 0- so that the import reorder does not change its place.
*
* It NEEDS to be the first imported file otherwise sentry instrumentation does not work.
*/
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';

// Ensure to call this before importing any other modules!
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENV,
release: process.env.APP_VERSION ?? 'not-specified',
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#sendDefaultPii
sendDefaultPii: true,

integrations: [
Sentry.fastifyIntegration(),
// Add our Profiling integration
nodeProfilingIntegration(),
],

// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#tracesSampleRate
tracesSampleRate: 0.2,

// Set profilesSampleRate to 1.0 to profile 100%
// of sampled transactions.
// This is relative to tracesSampleRate
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#profilesSampleRate
profilesSampleRate: 0.2,

// Enable if you need to troubleshoot the Sentry config
debug: true,
});
6 changes: 3 additions & 3 deletions src/fastify.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/node';

import { fastifyHelmet } from '@fastify/helmet';
import type { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import { fastify } from 'fastify';
Expand All @@ -6,7 +8,6 @@ import registerAppPlugins from './app';
import { DEV, NODE_ENV, PROD } from './config/env';
import { client } from './drizzle/db';
import ajvFormats from './schemas/ajvFormats';
import { initSentry } from './sentry';
import { APP_VERSION, CORS_ORIGIN_REGEX, HOST_LISTEN_ADDRESS, PORT } from './utils/config';
import { GREETING } from './utils/constants';
import { queueDashboardPlugin } from './workers/dashboard.controller';
Expand Down Expand Up @@ -42,8 +43,7 @@ instance.addHook('onClose', async () => {
});

const start = async () => {
const { Sentry } = initSentry(instance);

Sentry.setupFastifyErrorHandler(instance);
instance.register(fastifyHelmet);

if (CORS_ORIGIN_REGEX) {
Expand Down
143 changes: 0 additions & 143 deletions src/sentry.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// 0-instrumentation.ts should be the first imported file, so that sentry can instrument the whole app code.
import './0-instrument';
import start from './fastify';

start();
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist"
"outDir": "dist",
"sourceMap": false
},
"exclude": [
"node_modules",
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
"./node_modules/@types",
"./src/@types/*"
],
"sourceMap": true
"sourceMap": true,
// Set `sourceRoot` to "/" to strip the build path prefix
// from generated source code references.
// This improves issue grouping in Sentry.
// "sourceRoot": "/"
},
"include": [
"src/**/*",
Expand Down
Loading
Loading