Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
deps: Add @sentry/node version 6.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Mar 8, 2022
1 parent 63ea62f commit f6c5048
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ SERVER_PORT=3000
CORS_ORIGINS=http://localhost:3000

DATABASE_URI=

SENTRY_DSN=
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ XCoins code review repository.
- [Common](#common-config)
- [Server](#server-config)
- [Database](#database-config)
- [Sentry](#sentry-config)
- [Start](#start)
- [Docker](#docker)
- [Directory Layout](#directory-layout)
Expand Down Expand Up @@ -88,6 +89,12 @@ cp .env.example .env
|----------------|:------:|:-------:|:-----------------------------:|
| `DATABASE_URI` | string | - | MongoDB connection string uri |

#### Sentry Config

| Name | Type | Default | Description |
|--------------|:------:|:-------:|:------------------------:|
| `SENTRY_DSN` | string | - | Sentry project DSN value |

### Start

Start the API.
Expand Down Expand Up @@ -239,6 +246,7 @@ This section includes the issues, changes & improvements I've made, with the tho
> `express` doesn't catch async errors properly, so I added this utility to wrap the controllers before passing them
> to the `Router` instance.
- Added pagination to the endpoints that were listing records.
- Added `Sentry` to track issues in the production environment.

<!-- Footnotes -->

Expand Down
225 changes: 221 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"lint:fix": "npm run lint -- --fix"
},
"dependencies": {
"@sentry/node": "6.18.2",
"@sentry/tracing": "6.18.2",
"body-parser": "1.19.2",
"celebrate": "15.0.1",
"cors": "2.8.5",
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const NODE_ENV = process.env.NODE_ENV = check("NODE_ENV", ENV.DEVELOPMENT

export const SERVER_PORT = parseInt(check("SERVER_PORT", "3000"), 10);

export const CORS_ORIGINS = check("CORS_ORIGINS", "http://localhost:3000").split(",");

export const DATABASE_URI = check("DATABASE_URI");

export const CORS_ORIGINS = check("CORS_ORIGINS", "http://localhost:3000").split(",");
export const SENTRY_DSN = process.env.SENTRY_DSN;
3 changes: 3 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DATABASE_URI } from "#src/config.js";
import { Sentry } from "#src/lib/index.js";
import mongoose from "mongoose";

mongoose
Expand All @@ -7,6 +8,8 @@ mongoose
.catch((error) => {
console.log("❌ Failed to establish database connection!");

Sentry.captureException(error);

console.error(error);

process.exit(1);
Expand Down
18 changes: 18 additions & 0 deletions src/lib/Sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SENTRY_DSN } from "#src/config.js";
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";

Sentry.init({
dsn: SENTRY_DSN,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
new Tracing.Integrations.Express(),
],
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
});

export { Sentry };
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Joi.js";
export * from "./Sentry.js";
Loading

0 comments on commit f6c5048

Please sign in to comment.