Sentry is Error Tracking Service which provides cloud service and OSS. This post describes how to setup Sentry(Raven) with TypeScript/Node.js.
🎃 Install libraries
yarn add raven dotenv |
🏀 Configure Sentry
Provide SENTRY_DSN
environment variable to your application. In this case, we will provide the env variable by .env
file with dotenv.
SENTRY_DSN='{PROTOCOL}://{PUBLIC_KEY}@{HOST}/{PATH}{PROJECT_ID}' |
Create src/utils/Config.ts
file to load environment variable.
import * as dotenv from "dotenv"; |
Create src/utils/Sentry.ts
file for initializing Sentry.
import * as Raven from "raven"; |
🎳 Activate Sentry in your code
Please write the following code to fist position of src/index.js
(src/main.js
) entry file.
setUpSentry().then(() => console.log('Initialize Sentry')); |
🐠 Report error manually
Raven.config().install()
method sets up global handler to automatically capture any uncatch exception. You can also report errors manually.
try { |
🐮 Report message
Raven.captureMessage('Broken!'); |
🐝 Add Context
You can also add context data to the Sentry error report. It supports your tracing a error.
Raven.context(function () { |
🗻 Express.js Configuration
If you want to set up Sentry with Express.js/TypeScript, pease configure as follows:
export default new App(); |
🤔 More information
If you want to know more information, please see https://docs.sentry.io/clients/node/ .
🚜 References
🖥 Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!