@elysiumjs/plugin-sentry 0.1.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.
Files changed (3) hide show
  1. package/README.md +36 -0
  2. package/index.ts +71 -0
  3. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @elysiumjs/plugin-sentry
2
+
3
+ Enables Sentry error reporting for Elysium applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @elysiumjs/plugin-sentry
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { Application } from '@elysiumjs/core';
15
+ import { plugin as sentry } from '@elysiumjs/plugin-sentry';
16
+
17
+ @Application.register({
18
+ // Your other app options
19
+ plugins: [
20
+ sentry({
21
+ serverName: 'my-app',
22
+ dsn: 'https://<key>@sentry.io/<project>'
23
+ })
24
+ // Your other plugins
25
+ ]
26
+ })
27
+ class MyApp extends Application {}
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ This plugin forwards all options to the Sentry initialization method. You can find the full list of options [here](https://docs.sentry.io/platforms/javascript/guides/bun/configuration/options/).
33
+
34
+ ## License
35
+
36
+ This project is licensed under the terms of the [Apache License 2.0](LICENSE).
package/index.ts ADDED
@@ -0,0 +1,71 @@
1
+ import type { Application, ElysiumPlugin } from '@elysiumjs/core';
2
+
3
+ import { opentelemetry } from '@elysiajs/opentelemetry';
4
+ import { Env } from '@elysiumjs/core';
5
+ import * as Sentry from '@sentry/bun';
6
+ import { Elysia } from 'elysia';
7
+
8
+ /**
9
+ * Elysium plugin for Sentry integration.
10
+ * @author Axel Nana <axel.nana@workbud.com>
11
+ * @param options Plugin options.
12
+ */
13
+ export const plugin = (options?: Sentry.BunOptions): ElysiumPlugin => {
14
+ return async (_app: Application) => {
15
+ const dsn = options?.dsn ?? Env.get('SENTRY_DSN');
16
+ if (!dsn) {
17
+ throw new Error('Must provide a DSN');
18
+ }
19
+
20
+ const environment = options?.environment ?? Env.get('SENTRY_ENVIRONMENT');
21
+
22
+ Sentry.init({
23
+ dsn,
24
+ environment,
25
+ tracesSampleRate: 1.0,
26
+ integrations: [
27
+ Sentry.bunServerIntegration(),
28
+ Sentry.onUnhandledRejectionIntegration({
29
+ mode: 'warn'
30
+ }),
31
+ Sentry.onUncaughtExceptionIntegration()
32
+ ],
33
+ ...options
34
+ });
35
+
36
+ return (
37
+ new Elysia({
38
+ name: '@elysiumjs/plugin-sentry'
39
+ })
40
+ .decorate('Sentry', Sentry)
41
+ .use(
42
+ opentelemetry({
43
+ serviceName: options?.serverName
44
+ })
45
+ )
46
+ // Capture exceptions
47
+ .onError({ as: 'global' }, ({ error, Sentry }) => {
48
+ Sentry.captureException(error);
49
+ })
50
+ // Need this to inject attributes into the span
51
+ // https://github.com/elysiajs/opentelemetry/issues/40
52
+ .onAfterResponse(
53
+ { as: 'global' },
54
+ // @ts-expect-error Unused parameters
55
+ function injectAttributes({
56
+ body,
57
+ cookie,
58
+ params,
59
+ request,
60
+ response,
61
+ route,
62
+ server,
63
+ store,
64
+ headers,
65
+ path,
66
+ query
67
+ }) {}
68
+ )
69
+ );
70
+ };
71
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@elysiumjs/plugin-sentry",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "description": "The CLI tool for the Elysium framework.",
6
+ "private": false,
7
+ "author": {
8
+ "name": "Axel Nana",
9
+ "email": "axel.nana@workbud.com"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Workerly/elysium"
14
+ },
15
+ "homepage": "https://github.com/Workerly/elysium",
16
+ "scripts": {
17
+ "format": "prettier --write \"./src/**/*.ts\""
18
+ },
19
+ "keywords": [
20
+ "elysium",
21
+ "framework",
22
+ "web",
23
+ "api",
24
+ "typescript",
25
+ "sentry",
26
+ "error",
27
+ "reporting"
28
+ ],
29
+ "type": "module",
30
+ "module": "index.ts",
31
+ "devDependencies": {
32
+ "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
33
+ "@types/bun": "latest"
34
+ },
35
+ "peerDependencies": {
36
+ "@elysiumjs/core": "latest",
37
+ "typescript": "^5.8.3"
38
+ },
39
+ "dependencies": {
40
+ "@elysiajs/opentelemetry": "^1.2.0",
41
+ "@sentry/bun": "^9.14.0"
42
+ }
43
+ }