@benhepburn/adonis-sentry 1.0.3 → 2.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 +62 -36
- package/build/configure.d.ts +2 -2
- package/build/configure.js +2 -2
- package/build/services/main.d.ts +1 -1
- package/build/src/adonis_event_processor.d.ts +2 -2
- package/build/src/adonis_event_processor.js +3 -7
- package/build/src/define_config.d.ts +1 -1
- package/package.json +27 -23
package/README.md
CHANGED
|
@@ -1,64 +1,90 @@
|
|
|
1
|
-
# AdonisJS
|
|
1
|
+
# Sentry for AdonisJS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Report exceptions and capture performance traces in Sentry from an AdonisJS application. The package configures the Sentry Node.js SDK and exposes it as an AdonisJS container service.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Compatibility
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
| AdonisJS | Node.js | Assembler for `ace configure` |
|
|
8
|
+
| -------- | -------------------------------------- | ----------------------------- |
|
|
9
|
+
| v7 | 24 or later | v8 |
|
|
10
|
+
| v6 | 20.19+ (20.x), 22.12+ (22.x), or 23.2+ | v7 |
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Both AdonisJS versions use the Sentry Node.js SDK v11. The service import and provider registration are the same on both.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
12
15
|
|
|
13
16
|
```sh
|
|
14
|
-
|
|
17
|
+
npm install @benhepburn/adonis-sentry
|
|
18
|
+
node ace configure @benhepburn/adonis-sentry
|
|
15
19
|
```
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
The configure command creates `config/sentry.ts`, adds the Sentry environment variables and their validation rules, and registers `@benhepburn/adonis-sentry/sentry_provider` in `adonisrc.ts`. Run it with your application's matching Assembler version installed.
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
yarn add @benhepburn/adonis-sentry
|
|
21
|
-
```
|
|
23
|
+
## Configure Sentry
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
Copy the DSN from your Sentry project's Client Keys settings and set these variables in your application's environment.
|
|
24
26
|
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
+
```dotenv
|
|
28
|
+
SENTRY_DSN=https://public-key@o0.ingest.sentry.io/0
|
|
29
|
+
SENTRY_TRACES_SAMPLE_RATE=0.1
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
An empty DSN disables delivery. The trace sample rate is a number from `0` to `1` and controls performance tracing. The generated config defaults to `1.0`. Set the rate to `0` to disable trace sampling while continuing to report errors.
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
Edit `config/sentry.ts` to pass other Sentry Node SDK options through `defineConfig`, such as `environment`, `release`, or `beforeSend`.
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
SENTRY_DSN=https://<...>.sentry.io/<...>
|
|
35
|
-
SENTRY_TRACES_SAMPLE_RATE=1.0 # Set this to a lower value in production
|
|
36
|
-
```
|
|
36
|
+
### Upgrade from Sentry SDK v7
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
The generated DSN and trace sampling settings work with SDK v11. Review any custom options in `config/sentry.ts` and any SDK methods called through `/service`. For example, replace `startTransaction` with `startSpan`, and use `dataCollection` to configure SDK data collection. SDK v11 collects more data by default, including HTTP bodies, so review your data collection settings when upgrading. [Sentry SDK migration guide](https://github.com/getsentry/sentry-javascript/blob/11.12.0/MIGRATION.md)
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
### Enable CPU profiling
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
Install the profiler in your AdonisJS app. Keep it on the same exact version as the SDK resolved by the wrapper. For SDK 11.12.0, install this pair in the app.
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install --save-exact @sentry/node@11.12.0 @sentry/profiling-node@11.12.0
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
Add the integration and profiling options to your existing `config/sentry.ts`.
|
|
47
49
|
|
|
48
50
|
```ts
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
import env from '#start/env'
|
|
52
|
+
import { defineConfig } from '@benhepburn/adonis-sentry'
|
|
53
|
+
import { nodeProfilingIntegration } from '@sentry/profiling-node'
|
|
54
|
+
|
|
55
|
+
export default defineConfig({
|
|
56
|
+
dsn: env.get('SENTRY_DSN'),
|
|
57
|
+
tracesSampleRate: env.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
|
|
58
|
+
integrations: [nodeProfilingIntegration()],
|
|
59
|
+
profileSessionSampleRate: 0.1,
|
|
60
|
+
profileLifecycle: 'trace',
|
|
61
|
+
})
|
|
54
62
|
```
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
This samples 10% of profiling sessions and profiles while a sampled root span is active. Keep trace sampling enabled for this lifecycle. [Sentry profiling documentation](https://docs.sentry.io/platforms/javascript/guides/node/profiling/)
|
|
65
|
+
|
|
66
|
+
## Report HTTP exceptions
|
|
67
|
+
|
|
68
|
+
Add the Sentry import and `report` method to your existing handler in `app/exceptions/handler.ts`.
|
|
57
69
|
|
|
58
70
|
```ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
import { ExceptionHandler, type HttpContext } from '@adonisjs/core/http'
|
|
72
|
+
import sentry from '@benhepburn/adonis-sentry/service'
|
|
73
|
+
|
|
74
|
+
export default class HttpExceptionHandler extends ExceptionHandler {
|
|
75
|
+
async report(error: unknown, ctx: HttpContext) {
|
|
76
|
+
sentry.captureException(error)
|
|
77
|
+
return super.report(error, ctx)
|
|
78
|
+
}
|
|
63
79
|
}
|
|
64
80
|
```
|
|
81
|
+
|
|
82
|
+
This sends every exception that reaches the handler’s `report` method to Sentry and keeps AdonisJS’s normal reporting. For caught errors in controllers, jobs, or commands, import the same service and call `sentry.captureException(error)` from your catch block.
|
|
83
|
+
|
|
84
|
+
### Include HTTP request context
|
|
85
|
+
|
|
86
|
+
To let Sentry events pick up the current request, set `useAsyncLocalStorage: true` inside the existing `http` configuration in `config/app.ts`. The package attaches the request method and URL, the response status at capture time, and the authenticated user when available. Use `beforeSend` in `config/sentry.ts` to redact query parameters or user fields before sending events. [AdonisJS HTTP context documentation](https://docs.adonisjs.com/guides/basics/http-context#using-async-local-storage)
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
[MIT](LICENSE.md)
|
package/build/configure.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import ConfigureCommand from '@adonisjs/core/commands/configure';
|
|
2
|
-
export declare function configure(
|
|
1
|
+
import type ConfigureCommand from '@adonisjs/core/commands/configure';
|
|
2
|
+
export declare function configure(command: ConfigureCommand): Promise<void>;
|
package/build/configure.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
|
|
|
13
13
|
*/
|
|
14
14
|
import { stubsRoot } from './stubs/main.js';
|
|
15
|
-
export async function configure(
|
|
16
|
-
const codemods = await
|
|
15
|
+
export async function configure(command) {
|
|
16
|
+
const codemods = await command.createCodemods();
|
|
17
17
|
// Create config file
|
|
18
18
|
await codemods.makeUsingStub(stubsRoot, 'config/sentry.stub', {});
|
|
19
19
|
// Add env validations
|
package/build/services/main.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const adonisEventProcessor:
|
|
1
|
+
import type { Event } from '@sentry/node';
|
|
2
|
+
export declare const adonisEventProcessor: (event: Event) => Event;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import { HttpContext } from '@adonisjs/core/http';
|
|
2
|
-
export const adonisEventProcessor = (event
|
|
2
|
+
export const adonisEventProcessor = (event) => {
|
|
3
3
|
const ctx = HttpContext.get();
|
|
4
4
|
if (!ctx)
|
|
5
5
|
return event;
|
|
6
|
-
let body = ctx.request.body();
|
|
7
|
-
if (JSON.stringify(body).length > 2000)
|
|
8
|
-
body = undefined;
|
|
9
6
|
if (!event.contexts)
|
|
10
7
|
event.contexts = {};
|
|
11
8
|
// Add request data
|
|
12
9
|
event.request = {
|
|
13
10
|
method: ctx.request.method(),
|
|
14
11
|
url: ctx.request.url(true),
|
|
15
|
-
data: body,
|
|
16
12
|
};
|
|
17
13
|
// Add response data
|
|
18
14
|
event.contexts.response = {
|
|
19
15
|
status_code: ctx.response.getStatus(),
|
|
20
16
|
};
|
|
21
17
|
// Add user
|
|
22
|
-
|
|
23
|
-
event.user =
|
|
18
|
+
const { auth } = ctx;
|
|
19
|
+
event.user = auth?.user;
|
|
24
20
|
return event;
|
|
25
21
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NodeOptions } from '@sentry/node';
|
|
1
|
+
import type { NodeOptions } from '@sentry/node';
|
|
2
2
|
export declare function defineConfig(config: NodeOptions): NodeOptions;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@benhepburn/adonis-sentry",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "Sentry error monitoring and tracing for AdonisJS v6 and v7",
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=20.0.0"
|
|
6
|
+
"node": ">=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "build/index.js",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"clean": "del-cli build",
|
|
22
22
|
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
|
-
"lint": "eslint .
|
|
24
|
+
"lint": "eslint .",
|
|
25
25
|
"format": "prettier --write .",
|
|
26
|
-
"quick:test": "node --import
|
|
26
|
+
"quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
|
|
27
27
|
"pretest": "npm run lint",
|
|
28
28
|
"test": "c8 npm run quick:test",
|
|
29
29
|
"prebuild": "npm run lint && npm run clean",
|
|
@@ -41,31 +41,34 @@
|
|
|
41
41
|
"v6",
|
|
42
42
|
"adonis 6",
|
|
43
43
|
"provider",
|
|
44
|
-
"service"
|
|
44
|
+
"service",
|
|
45
|
+
"v7",
|
|
46
|
+
"adonis 7"
|
|
45
47
|
],
|
|
46
48
|
"author": "benhepburn",
|
|
47
49
|
"license": "MIT",
|
|
48
50
|
"devDependencies": {
|
|
49
|
-
"@adonisjs/assembler": "^
|
|
50
|
-
"@adonisjs/core": "^
|
|
51
|
-
"@adonisjs/eslint-config": "^
|
|
51
|
+
"@adonisjs/assembler": "^8.0.0",
|
|
52
|
+
"@adonisjs/core": "^7.0.0",
|
|
53
|
+
"@adonisjs/eslint-config": "^3.0.0",
|
|
52
54
|
"@adonisjs/prettier-config": "^1.2.1",
|
|
53
|
-
"@adonisjs/tsconfig": "^
|
|
54
|
-
"@japa/assert": "^2.
|
|
55
|
-
"@japa/runner": "^3.
|
|
56
|
-
"@
|
|
57
|
-
"@types/node": "^
|
|
55
|
+
"@adonisjs/tsconfig": "^2.0.0",
|
|
56
|
+
"@japa/assert": "^4.2.0",
|
|
57
|
+
"@japa/runner": "^5.3.0",
|
|
58
|
+
"@poppinss/ts-exec": "^1.4.4",
|
|
59
|
+
"@types/node": "^24.0.0",
|
|
58
60
|
"c8": "^9.0.0",
|
|
59
61
|
"copyfiles": "^2.4.1",
|
|
60
62
|
"del-cli": "^5.0.0",
|
|
61
|
-
"eslint": "^
|
|
63
|
+
"eslint": "^10.0.0",
|
|
62
64
|
"np": "^9.2.0",
|
|
63
65
|
"prettier": "^3.1.1",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
+
"typescript": "~5.9.3",
|
|
67
|
+
"youch": "^4.1.0"
|
|
66
68
|
},
|
|
67
69
|
"peerDependencies": {
|
|
68
|
-
"@adonisjs/core": "^6.2.0"
|
|
70
|
+
"@adonisjs/core": "^6.2.0 || ^7.0.0",
|
|
71
|
+
"@adonisjs/assembler": "^7.0.0 || ^8.0.0"
|
|
69
72
|
},
|
|
70
73
|
"publishConfig": {
|
|
71
74
|
"access": "public",
|
|
@@ -86,12 +89,13 @@
|
|
|
86
89
|
"tests/**"
|
|
87
90
|
]
|
|
88
91
|
},
|
|
89
|
-
"eslintConfig": {
|
|
90
|
-
"extends": "@adonisjs/eslint-config/package"
|
|
91
|
-
},
|
|
92
92
|
"prettier": "@adonisjs/prettier-config",
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@sentry/node": "^
|
|
95
|
-
|
|
94
|
+
"@sentry/node": "^11.12.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependenciesMeta": {
|
|
97
|
+
"@adonisjs/assembler": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
96
100
|
}
|
|
97
101
|
}
|