Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion apps/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"extends": "../../package.json"
},
"dependencies": {
"@sentry/node": "^7.109.0",
"@sentry/node": "^8.0.0-beta.1",
"express": "^4.19.2"
},
"devDependencies": {
Expand Down
26 changes: 12 additions & 14 deletions apps/express/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
debug: true,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});

// can use `import` instead of `require` because of `'esModuleInterop': true` in tsconfig.json
import express from 'express';

declare global {
Expand All @@ -10,19 +21,6 @@ declare global {
const app = express();
const port = 3030;

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
debug: true,
tunnel: `http://127.0.0.1:3031/`, // proxy server
tracesSampleRate: 1,
integrations: [new Sentry.Integrations.Express({ app })],
});

app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler());

app.get('/test-success', function (req, res) {
res.send({ version: 'v1' });
});
Expand Down Expand Up @@ -91,7 +89,7 @@ app.get('/test-local-variables-caught', function (req, res) {
res.send({ exceptionId, randomVariableToRecord });
});

app.use(Sentry.Handlers.errorHandler());
Sentry.setupExpressErrorHandler(app);

// @ts-ignore
app.use(function onError(err, req, res, next) {
Expand Down
20 changes: 20 additions & 0 deletions apps/fastify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "fastify-test-application",
"version": "1.0.0",
"directories": {
"lib": "lib"
},
"scripts": {
"build": "tsc",
"start": "yarn build && node dist/app.js",
"clean": "npx rimraf node_modules,pnpm-lock.yaml"
},
"license": "MIT",
"volta": {
"extends": "../../package.json"
},
"dependencies": {
"@sentry/node": "8.0.0-beta.1",
"fastify": "4.26.2"
}
}
94 changes: 94 additions & 0 deletions apps/fastify/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
integrations: [],
tracesSampleRate: 1,
tunnel: 'http://localhost:3031/', // proxy server
});

import { fastify } from 'fastify';

declare global {
namespace globalThis {
var transactionIds: string[];
}
}

// Make sure fastify is imported after Sentry is initialized
const app = fastify();

// @ts-ignore
Sentry.setupFastifyErrorHandler(app);

app.get('/test-success', function (_req, res) {
res.send({ version: 'v1' });
});

app.get('/test-error', async function (req, res) {
const exceptionId = Sentry.captureException(new Error('This is an error'));

await Sentry.flush(2000);

res.send({ exceptionId });
});

app.get<{ Params: { param: string } }>('/test-param-success/:param', function (req, res) {
res.send({ paramWas: req.params.param });
});

app.get<{ Params: { param: string } }>('/test-param-error/:param', async function (req, res) {
const exceptionId = Sentry.captureException(new Error('This is an error'));

await Sentry.flush(2000);

res.send({ exceptionId, paramWas: req.params.param });
});

app.get('/test-success-manual', async function (req, res) {
Sentry.startSpan({ name: 'test-span' }, () => {
Sentry.startSpan({ name: 'child-span' }, () => {});
});

await Sentry.flush();

res.send({
transactionIds: global.transactionIds || [],
});
});

app.get('/test-error-manual', async function (req, res) {
Sentry.startSpan({ name: 'test-span' }, () => {
Sentry.startSpan({ name: 'child-span' }, () => {
Sentry.captureException(new Error('This is an error'));
});
});

await Sentry.flush(2000);

res.send({
transactionIds: global.transactionIds || [],
});
});

app.get('/test-local-variables-uncaught', function (req, res) {
const randomVariableToRecord = 'LOCAL_VARIABLE';
throw new Error(`Uncaught Local Variable Error - ${JSON.stringify({ randomVariableToRecord })}`);
});

app.get('/test-local-variables-caught', function (req, res) {
const randomVariableToRecord = 'LOCAL_VARIABLE';

let exceptionId: string;
try {
throw new Error('Local Variable Error');
} catch (e) {
exceptionId = Sentry.captureException(e);
}

res.send({ exceptionId, randomVariableToRecord });
});

app.listen({ port: 3030 });
7 changes: 7 additions & 0 deletions apps/fastify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {
"outDir": "dist"
}
}
26 changes: 26 additions & 0 deletions apps/koa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "koa-test-application",
"version": "1.0.0",
"main": "dist/main.js",
"directories": {
"lib": "lib"
},
"scripts": {
"build": "tsc",
"start": "yarn build && node dist/app.js",
"clean": "npx rimraf node_modules,pnpm-lock.yaml"
},
"license": "MIT",
"volta": {
"extends": "../../package.json"
},
"dependencies": {
"@koa/router": "12.0.1",
"@sentry/node": "8.0.0-beta.1",
"koa": "2.15.3"
},
"devDependencies": {
"@types/koa": "2.15.0",
"@types/koa__router": "12.0.4"
}
}
106 changes: 106 additions & 0 deletions apps/koa/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
debug: true,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});

import Koa from 'koa';
import Router from '@koa/router';
import { stripUrlQueryAndFragment } from '@sentry/utils';

declare global {
namespace globalThis {
var transactionIds: string[];
}
}

const router = new Router();
const app = new Koa();

router.get('/test-success', ctx => {
ctx.body = { version: 'v1' };
});

router.get('/test-error', async ctx => {
const exceptionId = Sentry.captureException(new Error('This is an error'));

Sentry.flush(2000);

ctx.body = { exceptionId };
});

router.get('/test-param-success/:param', ctx => {
ctx.body = { paramWas: ctx.params.param };
});

router.get('/test-param-error/:param', async ctx => {
const exceptionId = Sentry.captureException(new Error('This is an error'));

Sentry.flush(2000);

ctx.body = { exceptionId, paramWas: ctx.params.param };
});

router.get('/test-success-manual', async ctx => {
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => {
Sentry.startSpan({ name: 'test-span' }, () => undefined);
});

Sentry.flush();

ctx.body = {
transactionIds: global.transactionIds || [],
};
});

router.get('/test-error-manual', async ctx => {
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => {
Sentry.startSpan({ name: 'test-span' }, () => {
Sentry.captureException(new Error('This is an error'));
});
});

Sentry.flush();

ctx.body = {
transactionIds: global.transactionIds || [],
};
});

router.get('/test-local-variables-uncaught', ctx => {
const randomVariableToRecord = 'LOCAL VARIABLE';
throw new Error(`Uncaught Local Variable Error - ${JSON.stringify({ randomVariableToRecord })}`);
});

router.get('/test-local-variables-caught', ctx => {
const randomVariableToRecord = 'LOCAL VARIABLE';

let exceptionId: string;
try {
throw new Error('Local Variable Error');
} catch (e) {
exceptionId = Sentry.captureException(e);
}

ctx.body = { exceptionId, randomVariableToRecord };
});

Sentry.setupKoaErrorHandler(app);

app.on('error', (err, ctx) => {
console.log('error', err);

ctx.body({
error: err.message,
status: ctx.status,
});
});

app.use(router.routes()).use(router.allowedMethods());

app.listen(3030);
7 changes: 7 additions & 0 deletions apps/koa/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {
"outDir": "dist"
}
}
8 changes: 8 additions & 0 deletions apps/nestjs/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
31 changes: 31 additions & 0 deletions apps/nestjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "nestjs-test-application",
"version": "1.0.0",
"main": "dist/main.js",
"directories": {
"lib": "lib"
},
"scripts": {
"build": "nest build",
"start": "nest start",
"clean": "npx rimraf node_modules,pnpm-lock.yaml"
},
"license": "MIT",
"volta": {
"extends": "../../package.json"
},
"dependencies": {
"@nestjs/common": "10.3.7",
"@nestjs/core": "10.3.7",
"@nestjs/platform-express": "10.3.7",
"@sentry/node": "8.0.0-beta.1",
"@sentry/types": "8.0.0-beta.1",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
},
"devDependencies": {
"@nestjs/cli": "10.3.2",
"@nestjs/schematics": "10.1.1",
"@types/express": "^4.17.17"
}
}
Loading