@benhepburn/adonis-sentry 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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # The MIT License
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # AdonisJS Sentry
2
+
3
+ ## Install
4
+
5
+ Install from npm:
6
+
7
+ ```sh
8
+ npm install @benhepburn/adonis-sentry
9
+ ```
10
+
11
+ or
12
+
13
+ ```sh
14
+ pnpm install @benhepburn/adonis-sentry
15
+ ```
16
+
17
+ or
18
+
19
+ ```sh
20
+ yarn add @benhepburn/adonis-sentry
21
+ ```
22
+
23
+ Then, configure the package for Adonis:
24
+
25
+ ```sh
26
+ node ace configure @benhepburn/adonis-sentry
27
+ ```
28
+
29
+ ## Configuration
30
+
31
+ Enter the Sentry DSN and Traces sample rate in your .env file:
32
+
33
+ ```dotenv
34
+ SENTRY_DSN=https://<...>.sentry.io/<...>
35
+ SENTRY_TRACES_SAMPLE_RATE=1.0 # Set this to a lower value in production
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ Import the service to use it:
41
+
42
+ ```ts
43
+ import sentry from "@benhepburn/adonis-sentry/service"
44
+ ```
45
+
46
+ To capture all exceptions, add this line to app/exceptions/handler inside the handle function:
47
+
48
+ ```ts
49
+ sentry.captureException(error);
50
+ ```
51
+
52
+ This can be used to capture exceptions manually as well:
53
+
54
+ ```ts
55
+ try {
56
+ ...
57
+ } catch (error: unknown) {
58
+ sentry.captureException(error);
59
+ }
60
+ ```
@@ -0,0 +1,2 @@
1
+ import ConfigureCommand from '@adonisjs/core/commands/configure';
2
+ export declare function configure(_command: ConfigureCommand): Promise<void>;
@@ -0,0 +1,37 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ | Configure hook
4
+ |--------------------------------------------------------------------------
5
+ |
6
+ | The configure hook is called when someone runs "node ace configure <package>"
7
+ | command. You are free to perform any operations inside this function to
8
+ | configure the package.
9
+ |
10
+ | To make things easier, you have access to the underlying "ConfigureCommand"
11
+ | instance and you can use codemods to modify the source files.
12
+ |
13
+ */
14
+ import { stubsRoot } from './stubs/main.js';
15
+ export async function configure(_command) {
16
+ const codemods = await _command.createCodemods();
17
+ // Create config file
18
+ await codemods.makeUsingStub(stubsRoot, 'config/sentry.stub', {});
19
+ // Add env validations
20
+ try {
21
+ await codemods.defineEnvVariables({
22
+ SENTRY_DSN: '',
23
+ SENTRY_TRACES_SAMPLE_RATE: '1.0',
24
+ });
25
+ await codemods.defineEnvValidations({
26
+ leadingComment: 'Sentry environment variables',
27
+ variables: {
28
+ SENTRY_DSN: 'Env.schema.string.optional()',
29
+ SENTRY_TRACES_SAMPLE_RATE: 'Env.schema.number.optional()',
30
+ },
31
+ });
32
+ }
33
+ catch (error) {
34
+ console.error('Unable to define env variables/validations');
35
+ console.error(error);
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ export { configure } from './configure.js';
2
+ export { defineConfig } from './src/define_config.js';
package/build/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ | Package entrypoint
4
+ |--------------------------------------------------------------------------
5
+ |
6
+ | Export values from the package entrypoint as you see fit.
7
+ |
8
+ */
9
+ export { configure } from './configure.js';
10
+ export { defineConfig } from './src/define_config.js';
@@ -0,0 +1,31 @@
1
+ import type { ApplicationService } from '@adonisjs/core/types';
2
+ import * as Sentry from '@sentry/node';
3
+ export default class SentryProvider {
4
+ protected app: ApplicationService;
5
+ constructor(app: ApplicationService);
6
+ /**
7
+ * Register bindings to the container
8
+ */
9
+ register(): void;
10
+ /**
11
+ * The container bindings have booted
12
+ */
13
+ boot(): Promise<void>;
14
+ /**
15
+ * The application has been booted
16
+ */
17
+ start(): Promise<void>;
18
+ /**
19
+ * The process has been started
20
+ */
21
+ ready(): Promise<void>;
22
+ /**
23
+ * Preparing to shut down the app
24
+ */
25
+ shutdown(): Promise<void>;
26
+ }
27
+ declare module '@adonisjs/core/types' {
28
+ interface ContainerBindings {
29
+ sentry: typeof Sentry;
30
+ }
31
+ }
@@ -0,0 +1,34 @@
1
+ import * as Sentry from '@sentry/node';
2
+ export default class SentryProvider {
3
+ app;
4
+ constructor(app) {
5
+ this.app = app;
6
+ }
7
+ /**
8
+ * Register bindings to the container
9
+ */
10
+ register() {
11
+ this.app.container.singleton('sentry', async (resolver) => {
12
+ const config = await resolver.make('config');
13
+ const sentryConfig = config.get('sentry');
14
+ Sentry.init(sentryConfig);
15
+ return Sentry;
16
+ });
17
+ }
18
+ /**
19
+ * The container bindings have booted
20
+ */
21
+ async boot() { }
22
+ /**
23
+ * The application has been booted
24
+ */
25
+ async start() { }
26
+ /**
27
+ * The process has been started
28
+ */
29
+ async ready() { }
30
+ /**
31
+ * Preparing to shut down the app
32
+ */
33
+ async shutdown() { }
34
+ }
@@ -0,0 +1,3 @@
1
+ import * as Sentry from '@sentry/node';
2
+ declare let sentry: typeof Sentry;
3
+ export { sentry as default };
@@ -0,0 +1,9 @@
1
+ import app from '@adonisjs/core/services/app';
2
+ let sentry;
3
+ /**
4
+ * Returns a singleton instance of Sentry from the container.
5
+ */
6
+ await app.booted(async () => {
7
+ sentry = await app.container.make('sentry');
8
+ });
9
+ export { sentry as default };
@@ -0,0 +1,2 @@
1
+ import { NodeOptions } from '@sentry/node';
2
+ export declare function defineConfig(config: NodeOptions): NodeOptions;
@@ -0,0 +1,3 @@
1
+ export function defineConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,17 @@
1
+ {{{
2
+ exports({
3
+ to: app.configPath('sentry.ts')
4
+ })
5
+ }}}
6
+ import env from '#start/env'
7
+ import { defineConfig } from '@benhepburn/adonis-sentry'
8
+
9
+ /**
10
+ * Configuration options to use Sentry in your AdonisJS application.
11
+ */
12
+ const sentryConfig = defineConfig({
13
+ dsn: env.get('SENTRY_DSN'),
14
+ tracesSampleRate: env.get('SENTRY_TRACES_SAMPLE_RATE', 1.0),
15
+ })
16
+
17
+ export default sentryConfig
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Path to the root directory where the stubs are stored. We use
3
+ * this path within commands and the configure hook
4
+ */
5
+ export declare const stubsRoot: string;
@@ -0,0 +1,7 @@
1
+ import { dirname } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ /**
4
+ * Path to the root directory where the stubs are stored. We use
5
+ * this path within commands and the configure hook
6
+ */
7
+ export const stubsRoot = dirname(fileURLToPath(import.meta.url));
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@benhepburn/adonis-sentry",
3
+ "description": "A Sentry integration for AdonisJS v6",
4
+ "version": "1.0.0",
5
+ "engines": {
6
+ "node": ">=20.0.0"
7
+ },
8
+ "type": "module",
9
+ "main": "build/index.js",
10
+ "files": [
11
+ "build",
12
+ "!build/bin",
13
+ "!build/tests"
14
+ ],
15
+ "exports": {
16
+ ".": "./build/index.js",
17
+ "./service": "./build/services/main.js"
18
+ },
19
+ "scripts": {
20
+ "clean": "del-cli build",
21
+ "copy:templates": "copyfiles \"stubs/**/*.stub\" build",
22
+ "typecheck": "tsc --noEmit",
23
+ "lint": "eslint . --ext=.ts",
24
+ "format": "prettier --write .",
25
+ "quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
26
+ "pretest": "npm run lint",
27
+ "test": "c8 npm run quick:test",
28
+ "prebuild": "npm run lint && npm run clean",
29
+ "build": "tsc",
30
+ "postbuild": "npm run copy:templates",
31
+ "release": "np",
32
+ "version": "npm run build",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "keywords": [
36
+ "adonis",
37
+ "adonisjs",
38
+ "sentry",
39
+ "sentry.io",
40
+ "v6",
41
+ "adonis 6",
42
+ "provider",
43
+ "service"
44
+ ],
45
+ "author": "benhepburn",
46
+ "license": "MIT",
47
+ "devDependencies": {
48
+ "@adonisjs/assembler": "^7.0.0",
49
+ "@adonisjs/core": "^6.2.0",
50
+ "@adonisjs/eslint-config": "^1.2.1",
51
+ "@adonisjs/prettier-config": "^1.2.1",
52
+ "@adonisjs/tsconfig": "^1.2.1",
53
+ "@japa/assert": "^2.1.0",
54
+ "@japa/runner": "^3.1.1",
55
+ "@swc/core": "^1.3.102",
56
+ "@types/node": "^20.10.7",
57
+ "c8": "^9.0.0",
58
+ "copyfiles": "^2.4.1",
59
+ "del-cli": "^5.0.0",
60
+ "eslint": "^8.38.0",
61
+ "np": "^9.2.0",
62
+ "prettier": "^3.1.1",
63
+ "ts-node": "^10.9.2",
64
+ "typescript": "^5.3.3"
65
+ },
66
+ "peerDependencies": {
67
+ "@adonisjs/core": "^6.2.0"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public",
71
+ "tag": "latest"
72
+ },
73
+ "np": {
74
+ "message": "chore(release): %s",
75
+ "tag": "latest",
76
+ "branch": "main",
77
+ "anyBranch": false
78
+ },
79
+ "c8": {
80
+ "reporter": [
81
+ "text",
82
+ "html"
83
+ ],
84
+ "exclude": [
85
+ "tests/**"
86
+ ]
87
+ },
88
+ "eslintConfig": {
89
+ "extends": "@adonisjs/eslint-config/package"
90
+ },
91
+ "prettier": "@adonisjs/prettier-config",
92
+ "dependencies": {
93
+ "@sentry/node": "^7.109.0",
94
+ "@sentry/profiling-node": "^7.109.0"
95
+ }
96
+ }