Skip to content

Commit

Permalink
Include sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshat Jain committed Nov 6, 2024
1 parent 7e5f40a commit c29a132
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 8 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,72 @@ After you have completed the local setup, you can run the test cases to ensure e
npm test
```

### 🔍 Newrelic Integration (Optional)

The Google Analytics Extension (GA4) comes pre-configured for integration with New Relic, allowing you to monitor your application's performance in real-time. This feature provides insights to help you improve and optimize your extension efficiently.

To leverage New Relic for performance monitoring, update the default values for the following environment variables in the app/fdk/config.js file in your project directory. This step ensures the New Relic integration is securely configured with your specific credentials.

1. `NEW_RELIC_APP_NAME`: Set this to the name you wish your application to appear as in New Relic. It helps easily identify your project within the New Relic dashboard.
2. `NEW_RELIC_LICENSE_KEY`: This is your unique New Relic license key, which authorizes the New Relic agent to send monitoring data to your New Relic account.

```javascript
newrelic: {
app_name: {
doc: 'new relic app name',
format: String,
default: '',
env: 'NEW_RELIC_APP_NAME',
arg: 'new_relic_app_name',
},
license_key: {
doc: 'new relic license key',
format: String,
default: '',
env: 'NEW_RELIC_LICENSE_KEY',
args: 'new_relic_license_key',
},
},
```

By updating these variables, you can activate New Relic's data collection, offering a comprehensive view of your application's performance.

> **Notes :**
> To remove New Relic integration completely, delete the New Relic environment variables in your `app/fdk/config.js` file and uninstall the New Relic package with `npm uninstall newrelic`. Remove `require('./connections/newrelic');` from `app/index.js`. Delete the `app/connections/newrelic.js` and `newrelic.js` files and update your documentation accordingly.

### 🚨 Sentry Integration (Optional)

Similar to New Relic, the Google Analytics Extension (GA4) comes pre-configured for optional integration with Sentry. Sentry provides real-time error tracking and monitoring, offering insights to quickly identify, diagnose, and fix issues, thereby enhancing your extension's reliability and user experience.
To enable Sentry for error monitoring, update the environment variables in the `app/fdk/config.js` file with your Sentry credentials:
1. `SENTRY_DSN`: This is the unique Data Source Name (DSN) provided by Sentry, which directs error messages to your Sentry project.
2. `SENTRY_ENVIRONMENT`: Specify the environment your application is running in, such as development, staging, or production. This helps in filtering and categorizing issues within Sentry.
```javascript
sentry: {
dsn: {
doc: 'sentry url',
format: String,
default: '',
env: 'SENTRY_DSN',
arg: 'sentry_dsn',
},
environment: {
doc: 'sentry environment',
format: String,
default: 'development',
env: 'SENTRY_ENVIRONMENT',
arg: 'sentry_environment',
},
},
```
Configuring these variables enables Sentry's error tracking for your application, offering a layer of insight into its stability and helping you maintain a high-quality user experience.

> **Notes :**
> To remove Sentry integration, delete the Sentry environment variables in your `app/fdk/config.js` file and uninstall the Sentry package with `npm uninstall @sentry/node`. Remove `require('./connections/sentry');` from `app/index.js`. Delete the `app/connections/sentry.js` and `sentry.js` files and update your documentation accordingly.

### 📋 Fynd Platform Panel

<p align="center">
Expand Down
16 changes: 16 additions & 0 deletions app/common/sentry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const Sentry = require('@sentry/node');

const _ = require('lodash');
const packageJson = require('../../package.json');
const config = require('../config');

const sentryConfig = config.get('sentry');

Sentry.init({
dsn: sentryConfig.dsn,
release: packageJson.version,
environment: sentryConfig.environment,
enabled: !_.isEmpty(sentryConfig.dsn),
});

module.exports = Sentry;
16 changes: 16 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ const config = convict({
args: 'new_relic_license_key',
},
},
sentry: {
dsn: {
doc: 'sentry url',
format: String,
default: '',
env: 'SENTRY_DSN',
arg: 'sentry_dsn',
},
environment: {
doc: 'sentry environment',
format: String,
default: 'development',
env: 'SENTRY_ENVIRONMENT',
arg: 'sentry_environment',
},
},
});

config.validate({ allowed: 'strict' });
Expand Down
3 changes: 3 additions & 0 deletions app/middleware/errorHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const Sentry = require('../common/sentry');

const errorHandler = (err, req, res, next) => {
if (err) {
console.error(`[ERR] Stack trace: ${err.stack}`);
Sentry.captureException(err);
res.status(500).json({
success: false,
title: 'Internal Server Error',
Expand Down
9 changes: 2 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const config = {
'!app/fdk/**/*.js',
'!app/models/**/*.js',
'!app/routes/index.js',
'!app/connections/**/*.js',
'!app/common/**/*.js',
'!app/health_check/**/*.js',
'!app/controllers/orderController.js',
'!app/routes/**/*',
Expand All @@ -47,12 +47,7 @@ const config = {
coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
coverageReporters: ['json', 'text', 'lcov', 'clover', 'html'],

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
Expand Down
171 changes: 171 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^9.0.0",
"@sentry/node": "^7.49.0",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/eslint-config-prettier": "^9.0.0",
Expand Down Expand Up @@ -45,7 +46,7 @@
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js",
"test": "jest --coverage --coverageReporters=json-summary",
"test": "jest --coverage",
"lint:check": "eslint . --no-fix",
"lint:fix": "eslint . --fix",
"format:check": "prettier --check .",
Expand Down

0 comments on commit c29a132

Please sign in to comment.