@benhepburn/adonis-sentry 1.0.0 → 1.0.3
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
CHANGED
|
@@ -43,13 +43,17 @@ Import the service to use it:
|
|
|
43
43
|
import sentry from "@benhepburn/adonis-sentry/service"
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
To capture all exceptions, add
|
|
46
|
+
To capture all exceptions, add the capture line to app/exceptions/handler.ts inside the report function:
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
|
-
|
|
49
|
+
async report(error: unknown, ctx: HttpContext) {
|
|
50
|
+
sentry.captureException(error); // Add this line
|
|
51
|
+
...
|
|
52
|
+
return super.report(error, ctx);
|
|
53
|
+
}
|
|
50
54
|
```
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
Exceptions can be captured manually as well:
|
|
53
57
|
|
|
54
58
|
```ts
|
|
55
59
|
try {
|
package/build/configure.js
CHANGED
|
@@ -34,4 +34,14 @@ export async function configure(_command) {
|
|
|
34
34
|
console.error('Unable to define env variables/validations');
|
|
35
35
|
console.error(error);
|
|
36
36
|
}
|
|
37
|
+
// Add service to rc file
|
|
38
|
+
try {
|
|
39
|
+
await codemods.updateRcFile((rcFile) => {
|
|
40
|
+
rcFile.addProvider('@benhepburn/adonis-sentry/sentry_provider');
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('Unable to update adonisrc.ts file');
|
|
45
|
+
console.error(error);
|
|
46
|
+
}
|
|
37
47
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Sentry from '@sentry/node';
|
|
2
|
+
import { adonisEventProcessor } from '../src/adonis_event_processor.js';
|
|
2
3
|
export default class SentryProvider {
|
|
3
4
|
app;
|
|
4
5
|
constructor(app) {
|
|
@@ -12,6 +13,7 @@ export default class SentryProvider {
|
|
|
12
13
|
const config = await resolver.make('config');
|
|
13
14
|
const sentryConfig = config.get('sentry');
|
|
14
15
|
Sentry.init(sentryConfig);
|
|
16
|
+
Sentry.addEventProcessor(adonisEventProcessor);
|
|
15
17
|
return Sentry;
|
|
16
18
|
});
|
|
17
19
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
export const adonisEventProcessor = (event, _hint) => {
|
|
3
|
+
const ctx = HttpContext.get();
|
|
4
|
+
if (!ctx)
|
|
5
|
+
return event;
|
|
6
|
+
let body = ctx.request.body();
|
|
7
|
+
if (JSON.stringify(body).length > 2000)
|
|
8
|
+
body = undefined;
|
|
9
|
+
if (!event.contexts)
|
|
10
|
+
event.contexts = {};
|
|
11
|
+
// Add request data
|
|
12
|
+
event.request = {
|
|
13
|
+
method: ctx.request.method(),
|
|
14
|
+
url: ctx.request.url(true),
|
|
15
|
+
data: body,
|
|
16
|
+
};
|
|
17
|
+
// Add response data
|
|
18
|
+
event.contexts.response = {
|
|
19
|
+
status_code: ctx.response.getStatus(),
|
|
20
|
+
};
|
|
21
|
+
// Add user
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
event.user = ctx.auth?.user || null;
|
|
24
|
+
return event;
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@benhepburn/adonis-sentry",
|
|
3
3
|
"description": "A Sentry integration for AdonisJS v6",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0"
|
|
7
7
|
},
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./build/index.js",
|
|
17
|
+
"./sentry_provider": "./build/providers/sentry_provider.js",
|
|
17
18
|
"./service": "./build/services/main.js"
|
|
18
19
|
},
|
|
19
20
|
"scripts": {
|