sentry-sails 0.0.1 → 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 +86 -11
- package/index.js +48 -30
- package/package.json +16 -7
package/README.md
CHANGED
|
@@ -1,29 +1,104 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sentry-sails
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sails hook for [Sentry](https://sentry.io) error tracking and performance monitoring.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install sails
|
|
8
|
+
npm install sentry-sails
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Quick Start
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
1. Install the hook:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install sentry-sails
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. Set your Sentry DSN via environment variable:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
SENTRY_DSN=https://your-dsn@sentry.io/project
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or create `config/sentry.js`:
|
|
14
26
|
|
|
15
27
|
```javascript
|
|
16
28
|
module.exports.sentry = {
|
|
17
|
-
dsn:
|
|
18
|
-
|
|
19
|
-
};
|
|
29
|
+
dsn: process.env.SENTRY_DSN
|
|
30
|
+
}
|
|
20
31
|
```
|
|
21
32
|
|
|
33
|
+
That's it! The hook will automatically capture errors and set up performance tracing.
|
|
34
|
+
|
|
22
35
|
## Configuration
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
All configuration options can be set in `config/sentry.js`:
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
module.exports.sentry = {
|
|
41
|
+
dsn: process.env.SENTRY_DSN,
|
|
42
|
+
environment: process.env.NODE_ENV || 'development',
|
|
43
|
+
tracesSampleRate: 1.0,
|
|
44
|
+
profilesSampleRate: 1.0,
|
|
45
|
+
sendDefaultPii: true
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Options
|
|
50
|
+
|
|
51
|
+
| Option | Type | Default | Description |
|
|
52
|
+
|--------|------|---------|-------------|
|
|
53
|
+
| `dsn` | string | `process.env.SENTRY_DSN` | Your Sentry Data Source Name |
|
|
54
|
+
| `environment` | string | `process.env.NODE_ENV` | Environment name (e.g., 'production') |
|
|
55
|
+
| `tracesSampleRate` | number | `1.0` | Sample rate for performance tracing (0.0 to 1.0) |
|
|
56
|
+
| `profilesSampleRate` | number | `1.0` | Sample rate for profiling (0.0 to 1.0) |
|
|
57
|
+
| `sendDefaultPii` | boolean | `true` | Capture request headers and IP |
|
|
58
|
+
|
|
59
|
+
## Manual Error Capture
|
|
60
|
+
|
|
61
|
+
Access the Sentry instance via `sails.sentry`:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
// In any controller or action
|
|
65
|
+
try {
|
|
66
|
+
await riskyOperation()
|
|
67
|
+
} catch (error) {
|
|
68
|
+
sails.sentry.captureException(error)
|
|
69
|
+
throw error
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Adding Context
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// Set user context
|
|
77
|
+
sails.sentry.setUser({
|
|
78
|
+
id: req.session.userId,
|
|
79
|
+
email: req.session.userEmail
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Add breadcrumb
|
|
83
|
+
sails.sentry.addBreadcrumb({
|
|
84
|
+
category: 'auth',
|
|
85
|
+
message: 'User logged in',
|
|
86
|
+
level: 'info'
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Set tags
|
|
90
|
+
sails.sentry.setTag('feature', 'checkout')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Requirements
|
|
94
|
+
|
|
95
|
+
- Node.js >= 18.0.0
|
|
96
|
+
- Sails.js >= 1.0.0
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
Full documentation available at [docs.sailscasts.com/sentry-sails](https://docs.sailscasts.com/sentry-sails)
|
|
26
101
|
|
|
27
102
|
## License
|
|
28
103
|
|
|
29
|
-
|
|
104
|
+
MIT
|
package/index.js
CHANGED
|
@@ -1,46 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* sentry hook
|
|
2
|
+
* sentry-sails hook
|
|
3
3
|
*
|
|
4
|
-
* @description :: A
|
|
5
|
-
* @docs :: https://
|
|
4
|
+
* @description :: A Sails hook for Sentry error tracking and performance monitoring.
|
|
5
|
+
* @docs :: https://docs.sailscasts.com/sentry-sails
|
|
6
6
|
*/
|
|
7
7
|
const Sentry = require('@sentry/node')
|
|
8
|
+
|
|
8
9
|
module.exports = function defineSentryHook(sails) {
|
|
9
10
|
return {
|
|
10
|
-
/**
|
|
11
|
-
* Runs when this Sails app loads/lifts.
|
|
12
|
-
*/
|
|
13
11
|
defaults: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
sentry: {
|
|
13
|
+
tracesSampleRate: 1.0,
|
|
14
|
+
profilesSampleRate: 1.0,
|
|
15
|
+
environment: process.env.NODE_ENV || 'development',
|
|
16
|
+
release: process.env.SENTRY_RELEASE,
|
|
17
|
+
sendDefaultPii: true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
configure: function () {
|
|
22
|
+
const dsn = sails.config.sentry.dsn || process.env.SENTRY_DSN
|
|
23
|
+
|
|
24
|
+
if (!dsn) {
|
|
25
|
+
sails.log.warn(
|
|
26
|
+
'sentry-sails: No DSN configured. Sentry will not capture errors.'
|
|
27
|
+
)
|
|
28
|
+
sails.log.warn(
|
|
29
|
+
'sentry-sails: Set SENTRY_DSN environment variable or configure dsn in config/sentry.js'
|
|
30
|
+
)
|
|
31
|
+
}
|
|
19
32
|
},
|
|
20
|
-
|
|
33
|
+
|
|
34
|
+
initialize: function (done) {
|
|
21
35
|
sails.after('hook:http:loaded', () => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}),
|
|
29
|
-
// enable Express.js middleware tracing
|
|
30
|
-
new Sentry.Integrations.Express({ app: sails.hooks.http.app })
|
|
31
|
-
]
|
|
36
|
+
const config = sails.config.sentry
|
|
37
|
+
const dsn = config.dsn || process.env.SENTRY_DSN
|
|
38
|
+
|
|
39
|
+
if (!dsn) {
|
|
40
|
+
sails.log.verbose('sentry-sails: Skipping initialization (no DSN)')
|
|
41
|
+
return done()
|
|
32
42
|
}
|
|
33
|
-
Sentry.init(sentryInitOptions)
|
|
34
|
-
// The request handler must be the first middleware on the app
|
|
35
|
-
sails.hooks.http.app.use(Sentry.Handlers.requestHandler())
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
Sentry.init({
|
|
45
|
+
dsn,
|
|
46
|
+
environment: config.environment,
|
|
47
|
+
tracesSampleRate: config.tracesSampleRate,
|
|
48
|
+
profilesSampleRate: config.profilesSampleRate,
|
|
49
|
+
sendDefaultPii: config.sendDefaultPii,
|
|
50
|
+
...config
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
sails.after('ready', () => {
|
|
54
|
+
Sentry.setupExpressErrorHandler(sails.hooks.http.app)
|
|
55
|
+
sails.log.verbose('sentry-sails: Express error handler attached')
|
|
56
|
+
})
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
sails.hooks.http.app.use(Sentry.Handlers.errorHandler())
|
|
58
|
+
sails.sentry = Sentry
|
|
42
59
|
|
|
43
|
-
sails.log.info('
|
|
60
|
+
sails.log.info('sentry-sails: Initialized successfully')
|
|
61
|
+
return done()
|
|
44
62
|
})
|
|
45
63
|
}
|
|
46
64
|
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentry-sails",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Sails
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Sails hook for Sentry error tracking and performance monitoring",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {},
|
|
7
7
|
"keywords": [
|
|
8
8
|
"sails",
|
|
9
9
|
"sentry",
|
|
10
10
|
"error",
|
|
11
|
-
"monitoring"
|
|
11
|
+
"monitoring",
|
|
12
|
+
"apm",
|
|
13
|
+
"tracing",
|
|
14
|
+
"performance"
|
|
12
15
|
],
|
|
13
16
|
"author": "Kelvin Omereshone<kelvin@sailscasts.com>",
|
|
14
17
|
"license": "MIT",
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/sailscastshq/sails
|
|
20
|
+
"url": "git+https://github.com/sailscastshq/sentry-sails.git"
|
|
18
21
|
},
|
|
19
22
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/sailscastshq/sails
|
|
23
|
+
"url": "https://github.com/sailscastshq/sentry-sails/issues"
|
|
21
24
|
},
|
|
22
|
-
"homepage": "https://
|
|
25
|
+
"homepage": "https://docs.sailscasts.com/sentry-sails",
|
|
23
26
|
"sails": {
|
|
24
27
|
"isHook": true,
|
|
25
28
|
"hookName": "sentry"
|
|
26
29
|
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"sails": ">=1.0.0"
|
|
35
|
+
},
|
|
27
36
|
"devDependencies": {
|
|
28
37
|
"@commitlint/cli": "^19.6.1",
|
|
29
38
|
"@commitlint/config-conventional": "^19.6.0",
|
|
@@ -35,6 +44,6 @@
|
|
|
35
44
|
"**/*": "prettier --write --ignore-unknown"
|
|
36
45
|
},
|
|
37
46
|
"dependencies": {
|
|
38
|
-
"@sentry/node": "^
|
|
47
|
+
"@sentry/node": "^9.0.0"
|
|
39
48
|
}
|
|
40
49
|
}
|