@benhepburn/adonis-sentry 1.0.4 → 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 CHANGED
@@ -1,71 +1,90 @@
1
- # AdonisJS Sentry
1
+ # Sentry for AdonisJS
2
2
 
3
- ## Install
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
+
5
+ ## Compatibility
4
6
 
5
- Install from npm:
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 |
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
6
15
 
7
16
  ```sh
8
17
  npm install @benhepburn/adonis-sentry
18
+ node ace configure @benhepburn/adonis-sentry
9
19
  ```
10
20
 
11
- or
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.
12
22
 
13
- ```sh
14
- pnpm install @benhepburn/adonis-sentry
15
- ```
23
+ ## Configure Sentry
16
24
 
17
- or
25
+ Copy the DSN from your Sentry project's Client Keys settings and set these variables in your application's environment.
18
26
 
19
- ```sh
20
- yarn add @benhepburn/adonis-sentry
27
+ ```dotenv
28
+ SENTRY_DSN=https://public-key@o0.ingest.sentry.io/0
29
+ SENTRY_TRACES_SAMPLE_RATE=0.1
21
30
  ```
22
31
 
23
- Then, configure the package for Adonis:
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.
24
33
 
25
- ```sh
26
- node ace configure @benhepburn/adonis-sentry
27
- ```
34
+ Edit `config/sentry.ts` to pass other Sentry Node SDK options through `defineConfig`, such as `environment`, `release`, or `beforeSend`.
28
35
 
29
- ## Configuration
36
+ ### Upgrade from Sentry SDK v7
30
37
 
31
- Enter the Sentry DSN and Traces sample rate in your .env file:
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)
32
39
 
33
- ```dotenv
34
- SENTRY_DSN=https://<...>.sentry.io/<...>
35
- SENTRY_TRACES_SAMPLE_RATE=1.0 # Set this to a lower value in production
36
- ```
40
+ ### Enable CPU profiling
37
41
 
38
- To enable enhanced event data, you must enable useAsyncLocalStorage in config/app.ts
39
- so the current request can be fetched ([see caveats here](https://docs.adonisjs.com/guides/async-local-storage#caveats)):
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.
40
43
 
41
- ```ts
42
- useAsyncLocalStorage: true,
44
+ ```sh
45
+ npm install --save-exact @sentry/node@11.12.0 @sentry/profiling-node@11.12.0
43
46
  ```
44
47
 
45
- ## Usage
46
-
47
- Import the service to use it:
48
+ Add the integration and profiling options to your existing `config/sentry.ts`.
48
49
 
49
50
  ```ts
50
- import sentry from "@benhepburn/adonis-sentry/service"
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
+ })
51
62
  ```
52
63
 
53
- To capture all exceptions, add the capture line to app/exceptions/handler.ts inside the report function:
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/)
54
65
 
55
- ```ts
56
- async report(error: unknown, ctx: HttpContext) {
57
- sentry.captureException(error); // Add this line
58
- ...
59
- return super.report(error, ctx);
60
- }
61
- ```
66
+ ## Report HTTP exceptions
62
67
 
63
- Exceptions can be captured manually as well:
68
+ Add the Sentry import and `report` method to your existing handler in `app/exceptions/handler.ts`.
64
69
 
65
70
  ```ts
66
- try {
67
- ...
68
- } catch (error: unknown) {
69
- sentry.captureException(error);
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
+ }
70
79
  }
71
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)
@@ -1,2 +1,2 @@
1
- import ConfigureCommand from '@adonisjs/core/commands/configure';
2
- export declare function configure(_command: ConfigureCommand): Promise<void>;
1
+ import type ConfigureCommand from '@adonisjs/core/commands/configure';
2
+ export declare function configure(command: ConfigureCommand): Promise<void>;
@@ -12,8 +12,8 @@
12
12
  |
13
13
  */
14
14
  import { stubsRoot } from './stubs/main.js';
15
- export async function configure(_command) {
16
- const codemods = await _command.createCodemods();
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
@@ -1,3 +1,3 @@
1
- import * as Sentry from '@sentry/node';
1
+ import type * as Sentry from '@sentry/node';
2
2
  declare let sentry: typeof Sentry;
3
3
  export { sentry as default };
@@ -1,2 +1,2 @@
1
- import { EventProcessor } from '@sentry/types/types/eventprocessor.js';
2
- export declare const adonisEventProcessor: EventProcessor;
1
+ import type { Event } from '@sentry/node';
2
+ export declare const adonisEventProcessor: (event: Event) => Event;
@@ -1,5 +1,5 @@
1
1
  import { HttpContext } from '@adonisjs/core/http';
2
- export const adonisEventProcessor = (event, _hint) => {
2
+ export const adonisEventProcessor = (event) => {
3
3
  const ctx = HttpContext.get();
4
4
  if (!ctx)
5
5
  return event;
@@ -15,7 +15,7 @@ export const adonisEventProcessor = (event, _hint) => {
15
15
  status_code: ctx.response.getStatus(),
16
16
  };
17
17
  // Add user
18
- // @ts-ignore
19
- event.user = ctx.auth?.user || null;
18
+ const { auth } = ctx;
19
+ event.user = auth?.user;
20
20
  return event;
21
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": "A Sentry integration for AdonisJS v6",
4
- "version": "1.0.4",
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 . --ext=.ts",
24
+ "lint": "eslint .",
25
25
  "format": "prettier --write .",
26
- "quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
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": "^7.0.0",
50
- "@adonisjs/core": "^6.2.0",
51
- "@adonisjs/eslint-config": "^1.2.1",
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": "^1.2.1",
54
- "@japa/assert": "^2.1.0",
55
- "@japa/runner": "^3.1.1",
56
- "@swc/core": "^1.3.102",
57
- "@types/node": "^20.10.7",
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": "^8.38.0",
63
+ "eslint": "^10.0.0",
62
64
  "np": "^9.2.0",
63
65
  "prettier": "^3.1.1",
64
- "ts-node": "^10.9.2",
65
- "typescript": "^5.3.3"
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": "^7.109.0",
95
- "@sentry/profiling-node": "^7.109.0"
94
+ "@sentry/node": "^11.12.0"
95
+ },
96
+ "peerDependenciesMeta": {
97
+ "@adonisjs/assembler": {
98
+ "optional": true
99
+ }
96
100
  }
97
101
  }