generator-jhipster-sentry-module 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # generator-jhipster-sentry-module
2
+
3
+ [![NPM version][npm-image]][npm-url] [![Build Status][github-actions-image]][github-actions-url] [![Dependency Status][daviddm-image]][daviddm-url]
4
+
5
+ > JHipster module, adding sentry to jhipster generator
6
+
7
+ # Introduction
8
+
9
+ This is a [JHipster](https://www.jhipster.tech/) module, that is meant to be used in a JHipster application.
10
+
11
+ # Prerequisites
12
+
13
+ As this is a [JHipster](https://www.jhipster.tech/) module, we expect you have JHipster and its related tools already installed:
14
+
15
+ - [Installing JHipster](https://www.jhipster.tech/installation/)
16
+
17
+ # Installation
18
+
19
+ ## With NPM
20
+
21
+ To install this module:
22
+
23
+ ```bash
24
+ npm install -g generator-jhipster-sentry-module
25
+ ```
26
+
27
+ To update this module:
28
+
29
+ ```bash
30
+ npm update -g generator-jhipster-sentry-module
31
+ ```
32
+
33
+ ## With Yarn
34
+
35
+ To install this module:
36
+
37
+ ```bash
38
+ yarn global add generator-jhipster-sentry-module
39
+ ```
40
+
41
+ To update this module:
42
+
43
+ ```bash
44
+ yarn global upgrade generator-jhipster-sentry-module
45
+ ```
46
+
47
+ # Usage
48
+
49
+ After installing the module, run it in your JHipster project:
50
+
51
+ ```bash
52
+ yo jhipster-sentry-module
53
+ ```
54
+
55
+ The generator will prompt you to:
56
+ - Enable/disable Sentry integration
57
+ - Enter your Sentry DSN (if enabled)
58
+
59
+ ## Verifying Sentry Integration
60
+
61
+ After running the generator, verify that Sentry has been added successfully by checking the following:
62
+
63
+ ### 1. Check Configuration Files
64
+
65
+ **Backend Configuration:**
66
+ - ✅ Verify `src/main/resources/config/sentry.yml` exists
67
+ - ✅ Check that it contains your Sentry DSN:
68
+ ```yaml
69
+ sentry:
70
+ dsn: "https://your-dsn@sentry.io/project-id"
71
+ environment: dev
72
+ traces-sample-rate: 0.2
73
+ ```
74
+
75
+ **Frontend Configuration:**
76
+ - ✅ Verify `src/main/webapp/app/sentry.ts` exists (for React/Angular)
77
+ - ✅ Check that it contains your Sentry DSN:
78
+ ```typescript
79
+ Sentry.init({
80
+ dsn: 'https://your-dsn@sentry.io/project-id',
81
+ environment: 'dev',
82
+ });
83
+ ```
84
+
85
+ ### 2. Check Dependencies
86
+
87
+ **Maven Projects:**
88
+ - ✅ Check `pom.xml` for Sentry dependency:
89
+ ```xml
90
+ <dependency>
91
+ <groupId>io.sentry</groupId>
92
+ <artifactId>sentry-spring-boot-starter</artifactId>
93
+ <version>7.3.0</version>
94
+ </dependency>
95
+ ```
96
+
97
+ **Gradle Projects:**
98
+ - ✅ Check `build.gradle` for Sentry dependency:
99
+ ```gradle
100
+ implementation 'io.sentry:sentry-spring-boot-starter:7.3.0'
101
+ ```
102
+
103
+ **Frontend (package.json):**
104
+ - ✅ For React: Check for `@sentry/react: ^7.3.0`
105
+ - ✅ For Angular: Check for `@sentry/angular: ^7.3.0`
106
+
107
+ ### 3. Check Module Registration
108
+
109
+ - ✅ Verify `.yo-rc.json` contains Sentry configuration:
110
+ ```json
111
+ {
112
+ "generator-jhipster": {
113
+ "sentry": {
114
+ "enabled": true,
115
+ "dsn": "https://your-dsn@sentry.io/project-id"
116
+ }
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### 4. Verify Integration in Code
122
+
123
+ **Backend (Spring Boot):**
124
+ - ✅ Sentry should auto-configure when Spring Boot starts
125
+ - ✅ Check application logs for Sentry initialization
126
+ - ✅ Test by throwing an exception - it should appear in Sentry dashboard
127
+
128
+ **Frontend:**
129
+ - ✅ Import and initialize Sentry in your main app file:
130
+ ```typescript
131
+ // For React
132
+ import './sentry';
133
+
134
+ // For Angular
135
+ import './sentry';
136
+ ```
137
+ - ✅ Add the import in `src/main/webapp/app/app.tsx` (React) or `src/main/webapp/app/app.module.ts` (Angular)
138
+
139
+ ### 5. Test Sentry Integration
140
+
141
+ **Backend Test:**
142
+ ```java
143
+ // Create a test endpoint or add to existing controller
144
+ @GetMapping("/api/test-sentry")
145
+ public void testSentry() {
146
+ throw new RuntimeException("Test Sentry integration");
147
+ }
148
+ ```
149
+
150
+ **Frontend Test:**
151
+ ```typescript
152
+ // Add to a component or service
153
+ try {
154
+ throw new Error('Test Sentry integration');
155
+ } catch (error) {
156
+ Sentry.captureException(error);
157
+ }
158
+ ```
159
+
160
+ ### 6. Verify in Sentry Dashboard
161
+
162
+ 1. ✅ Start your application
163
+ 2. ✅ Trigger a test error (backend or frontend)
164
+ 3. ✅ Check your Sentry project dashboard
165
+ 4. ✅ Verify the error appears with stack trace and context
166
+
167
+ ### Troubleshooting
168
+
169
+ **If Sentry files are missing:**
170
+ - Run the generator again: `yo jhipster-sentry-module`
171
+ - Check that you answered "yes" to enable Sentry
172
+
173
+ **If dependencies are missing:**
174
+ - Run `npm install` (for frontend)
175
+ - Run `./mvnw clean install` (Maven) or `./gradlew build` (Gradle)
176
+
177
+ **If errors don't appear in Sentry:**
178
+ - Verify your DSN is correct in configuration files
179
+ - Check Sentry project settings
180
+ - Verify network connectivity to Sentry servers
181
+ - Check application logs for Sentry initialization errors
182
+
183
+ # License
184
+
185
+ [npm-image]: https://img.shields.io/npm/v/generator-jhipster-sentry-module.svg
186
+ [npm-url]: https://npmjs.org/package/generator-jhipster-sentry-module
187
+ [github-actions-image]: https://github.com/Sara/generator-jhipster-sentry-module/workflows/Build/badge.svg
188
+ [github-actions-url]: https://github.com/Sara/generator-jhipster-sentry-module/actions
189
+ [daviddm-image]: https://david-dm.org/Sara/generator-jhipster-sentry-module.svg?theme=shields.io
190
+ [daviddm-url]: https://david-dm.org/Sara/generator-jhipster-sentry-module
@@ -0,0 +1,211 @@
1
+ const chalk = require('chalk');
2
+ const semver = require('semver');
3
+ const BaseGenerator = require('generator-jhipster/generators/generator-base');
4
+ const jhipsterConstants = require('generator-jhipster/generators/generator-constants');
5
+ const packagejs = require('../../package.json');
6
+
7
+ module.exports = class extends BaseGenerator {
8
+ get initializing() {
9
+ return {
10
+ init(args) {
11
+ if (args === 'default') {
12
+ this.message = 'default message';
13
+ }
14
+ },
15
+
16
+ readConfig() {
17
+ this.jhipsterAppConfig = this.getAllJhipsterConfig();
18
+ if (!this.jhipsterAppConfig) {
19
+ this.error('Cannot read .yo-rc.json');
20
+ }
21
+ },
22
+
23
+ displayLogo() {
24
+ this.printJHipsterLogo();
25
+ this.log(
26
+ `\nWelcome to the ${chalk.bold.yellow(
27
+ 'JHipster Sentry Module'
28
+ )} generator! ${chalk.yellow(`v${packagejs.version}\n`)}`
29
+ );
30
+ },
31
+
32
+ checkJhipster() {
33
+ const currentJhipsterVersion = this.jhipsterAppConfig.jhipsterVersion;
34
+ const minimumJhipsterVersion = packagejs.dependencies['generator-jhipster'];
35
+
36
+ if (!semver.satisfies(currentJhipsterVersion, minimumJhipsterVersion)) {
37
+ this.warning(
38
+ `\nYour generated project uses JHipster ${currentJhipsterVersion}. ` +
39
+ `Minimum required is ${minimumJhipsterVersion}\n`
40
+ );
41
+ }
42
+ }
43
+ };
44
+ }
45
+
46
+ prompting() {
47
+ const prompts = [
48
+ {
49
+ type: 'confirm',
50
+ name: 'enableSentry',
51
+ message: 'Do you want to enable Sentry error tracking?',
52
+ default: true
53
+ },
54
+ {
55
+ when: answers => answers.enableSentry,
56
+ type: 'input',
57
+ name: 'sentryDsn',
58
+ message: 'Enter your Sentry DSN'
59
+ }
60
+ ];
61
+
62
+ const done = this.async();
63
+ this.prompt(prompts).then(answers => {
64
+ this.promptAnswers = answers;
65
+ done();
66
+ });
67
+ }
68
+
69
+ writing() {
70
+ /* -------------------------------
71
+ * Read JHipster config
72
+ * ----------------------------- */
73
+ this.baseName = this.jhipsterAppConfig.baseName;
74
+ this.packageName = this.jhipsterAppConfig.packageName;
75
+ this.packageFolder = this.jhipsterAppConfig.packageFolder;
76
+ this.clientFramework = this.jhipsterAppConfig.clientFramework;
77
+ this.clientPackageManager = this.jhipsterAppConfig.clientPackageManager;
78
+ this.buildTool = this.jhipsterAppConfig.buildTool;
79
+
80
+ this.angularAppName = this.getAngularAppName();
81
+
82
+ const javaDir = `${jhipsterConstants.SERVER_MAIN_SRC_DIR}${this.packageFolder}/`;
83
+ const resourceDir = jhipsterConstants.SERVER_MAIN_RES_DIR;
84
+ const webappDir = jhipsterConstants.CLIENT_MAIN_SRC_DIR;
85
+
86
+ /* -------------------------------
87
+ * Persist config (regen safe)
88
+ * ----------------------------- */
89
+ this.jhipsterAppConfig.sentry = {
90
+ enabled: this.promptAnswers.enableSentry,
91
+ dsn: this.promptAnswers.sentryDsn
92
+ };
93
+
94
+ // Save config back to .yo-rc.json
95
+ const configPath = this.destinationPath('.yo-rc.json');
96
+ const fs = require('fs');
97
+ if (fs.existsSync(configPath)) {
98
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
99
+ if (!config['generator-jhipster']) {
100
+ config['generator-jhipster'] = {};
101
+ }
102
+ config['generator-jhipster'].sentry = this.jhipsterAppConfig.sentry;
103
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
104
+ }
105
+
106
+ /* -------------------------------
107
+ * Logging
108
+ * ----------------------------- */
109
+ this.log('\n--- JHipster Config ---');
110
+ this.log(`baseName=${this.baseName}`);
111
+ this.log(`packageName=${this.packageName}`);
112
+ this.log(`clientFramework=${this.clientFramework}`);
113
+ this.log(`buildTool=${this.buildTool}`);
114
+
115
+ this.log('\n--- Directories ---');
116
+ this.log(`javaDir=${javaDir}`);
117
+ this.log(`resourceDir=${resourceDir}`);
118
+ this.log(`webappDir=${webappDir}`);
119
+
120
+ this.log('\n--- Sentry ---');
121
+ this.log(`enabled=${this.promptAnswers.enableSentry}`);
122
+ this.log('----------------------\n');
123
+
124
+ if (!this.promptAnswers.enableSentry) {
125
+ this.log(chalk.yellow('Sentry is disabled — skipping integration'));
126
+ return;
127
+ }
128
+
129
+ /* -------------------------------
130
+ * Backend (Spring Boot)
131
+ * ----------------------------- */
132
+ if (this.buildTool === 'maven') {
133
+ this.addMavenDependency(
134
+ 'io.sentry',
135
+ 'sentry-spring-boot-starter',
136
+ '7.3.0'
137
+ );
138
+ }
139
+
140
+ if (this.buildTool === 'gradle') {
141
+ this.addGradleDependency(
142
+ 'implementation',
143
+ 'io.sentry:sentry-spring-boot-starter:7.3.0'
144
+ );
145
+ }
146
+
147
+ this.template(
148
+ 'server/sentry-application.yml.ejs',
149
+ `${resourceDir}config/sentry.yml`
150
+ );
151
+
152
+ /* -------------------------------
153
+ * Frontend
154
+ * ----------------------------- */
155
+ if (this.clientFramework === 'react') {
156
+ this.addNpmDependency('@sentry/react', '^7.3.0');
157
+
158
+ this.template(
159
+ 'client/react/sentry.ts.ejs',
160
+ `${webappDir}app/sentry.ts`
161
+ );
162
+ }
163
+
164
+ if (this.clientFramework === 'angularX') {
165
+ this.addNpmDependency('@sentry/angular', '^7.3.0');
166
+
167
+ this.template(
168
+ 'client/angular/sentry.ts.ejs',
169
+ `${webappDir}app/sentry.ts`
170
+ );
171
+ }
172
+
173
+ /* -------------------------------
174
+ * Register module hook
175
+ * ----------------------------- */
176
+ try {
177
+ this.registerModule(
178
+ 'generator-jhipster-sentry-module',
179
+ 'app',
180
+ 'post',
181
+ 'app',
182
+ 'Adds Sentry integration'
183
+ );
184
+ } catch (err) {
185
+ this.log(
186
+ `${chalk.red.bold('WARN!')} Could not register JHipster hook`
187
+ );
188
+ }
189
+ }
190
+
191
+ install() {
192
+ const logMsg = `To install dependencies manually, run: ${chalk.yellow.bold(
193
+ `${this.clientPackageManager} install`
194
+ )}`;
195
+
196
+ if (this.options['skip-install']) {
197
+ this.log(logMsg);
198
+ return;
199
+ }
200
+
201
+ this.installDependencies({
202
+ npm: this.clientPackageManager === 'npm',
203
+ yarn: this.clientPackageManager === 'yarn',
204
+ bower: false
205
+ });
206
+ }
207
+
208
+ end() {
209
+ this.log(chalk.green('✔ Sentry module generation complete'));
210
+ }
211
+ };
@@ -0,0 +1,6 @@
1
+ import * as Sentry from '@sentry/angular';
2
+
3
+ Sentry.init({
4
+ dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
+ environment: 'dev',
6
+ });
@@ -0,0 +1,6 @@
1
+ import * as Sentry from '@sentry/react';
2
+
3
+ Sentry.init({
4
+ dsn: '<%= jhipsterAppConfig.sentry.dsn %>',
5
+ environment: 'dev',
6
+ });
@@ -0,0 +1,2 @@
1
+ hello sentry-module!
2
+ It's dummy.txt
@@ -0,0 +1,4 @@
1
+ sentry:
2
+ dsn: "<%= jhipsterAppConfig.sentry.dsn %>"
3
+ environment: dev
4
+ traces-sample-rate: 0.2
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "generator-jhipster-sentry-module",
3
+ "version": "1.0.0",
4
+ "description": "adding sentry to jhipster generator",
5
+ "keywords": [
6
+ "yeoman-generator",
7
+ "jhipster-module",
8
+ "jhipster",
9
+ "jhipster-6",
10
+ "jhipster-blueprint",
11
+ "sentry",
12
+ "error-tracking"
13
+ ],
14
+ "homepage": "https://github.com/Sara/generator-jhipster-sentry-module",
15
+ "author": {
16
+ "name": "Firstname Lastname",
17
+ "email": "",
18
+ "url": ""
19
+ },
20
+ "files": [
21
+ "generators"
22
+ ],
23
+ "main": "generators/app/index.js",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/Sara/generator-jhipster-sentry-module.git"
27
+ },
28
+ "dependencies": {
29
+ "chalk": "3.0.0",
30
+ "generator-jhipster": ">=6.0.0",
31
+ "mkdirp": "0.5.1",
32
+ "semver": "7.1.1",
33
+ "shelljs": "0.8.3",
34
+ "yeoman-generator": "4.4.0"
35
+ },
36
+ "devDependencies": {
37
+ "eslint": "6.8.0",
38
+ "eslint-config-airbnb-base": "14.0.0",
39
+ "eslint-config-prettier": "6.9.0",
40
+ "eslint-plugin-import": "2.19.1",
41
+ "eslint-plugin-prettier": "3.1.2",
42
+ "fs-extra": "8.1.0",
43
+ "husky": "3.1.0",
44
+ "lint-staged": "9.5.0",
45
+ "mocha": "6.2.2",
46
+ "prettier": "1.19.1",
47
+ "yeoman-assert": "3.1.1",
48
+ "yeoman-test": "2.0.0"
49
+ },
50
+ "scripts": {
51
+ "prettier:format": "prettier --write \"{,**/}*.{js,json,md,yml}\"",
52
+ "pretest": "eslint .",
53
+ "lint": "eslint .",
54
+ "lint-fix": "eslint . --fix",
55
+ "release": "git push && git push --tags && npm publish",
56
+ "release:patch": "npm version patch -a -m \"Update to %s\" && npm run release",
57
+ "release:minor": "npm version minor -a -m \"Update to %s\" && npm run release",
58
+ "release:major": "npm version major -a -m \"Update to %s\" && npm run release",
59
+ "test": "mocha test"
60
+ },
61
+ "husky": {
62
+ "hooks": {
63
+ "pre-commit": "lint-staged"
64
+ }
65
+ },
66
+ "lint-staged": {
67
+ "*.{js,json,yml,md}": [
68
+ "prettier --write",
69
+ "git add"
70
+ ]
71
+ },
72
+ "bugs": {
73
+ "url": "https://github.com/Sara/generator-jhipster-sentry-module/issues"
74
+ }
75
+ }