@hartl-services/medusa-sentry-logger 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.
- package/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +81 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hartl Services GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Medusa Sentry Logger
|
|
2
|
+
|
|
3
|
+
Wraps Medusa's `configModule.logger` so that every `logger.error(...)` call is
|
|
4
|
+
also reported to Sentry.
|
|
5
|
+
|
|
6
|
+
Medusa's HTTP error handler catches thrown route and workflow errors and only
|
|
7
|
+
logs them, so Sentry's default Node integrations never see them. Wrapping the
|
|
8
|
+
logger captures every error the framework already logs.
|
|
9
|
+
|
|
10
|
+
Medusa's Redis Event Bus logs a failing subscriber's exception with
|
|
11
|
+
`logger.warn(err)`, even after the final retry. The wrapper therefore also
|
|
12
|
+
reports every `Error` passed to `warn`, at Sentry level `warning`; plain
|
|
13
|
+
warning messages are not reported.
|
|
14
|
+
|
|
15
|
+
This is a plain library, not a Medusa plugin: do not add it to `plugins`.
|
|
16
|
+
|
|
17
|
+
## Installation in a shop
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @hartl-services/medusa-sentry-logger @sentry/node
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`@sentry/node` is a peer dependency, so the logger reports through the same
|
|
24
|
+
Sentry client your shop initializes. Initialize Sentry in `instrumentation.ts`:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import * as Sentry from "@sentry/node";
|
|
28
|
+
|
|
29
|
+
export function register() {
|
|
30
|
+
Sentry.init({ dsn: process.env.SENTRY_DSN });
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Then wrap the logger in `medusa-config.ts`:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { logger } from "@medusajs/framework/logger";
|
|
38
|
+
import { withSentryErrorReporting } from "@hartl-services/medusa-sentry-logger";
|
|
39
|
+
|
|
40
|
+
module.exports = defineConfig({
|
|
41
|
+
logger: withSentryErrorReporting(logger),
|
|
42
|
+
// ...
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Without a `SENTRY_DSN`, Sentry stays inactive and the logger behaves as before.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Logger } from "@medusajs/framework/types";
|
|
2
|
+
/**
|
|
3
|
+
* Medusa's own HTTP error-handler middleware fully "handles" every thrown
|
|
4
|
+
* route/workflow error via logger.error(...) before it can ever reach an
|
|
5
|
+
* uncaught-exception process hook, so Sentry's default Node integrations
|
|
6
|
+
* never see it. Bridging logger.error(...) itself is the only place that
|
|
7
|
+
* reliably captures every error Medusa's framework already logs internally.
|
|
8
|
+
* Errors that Medusa logs through logger.warn(err) (failing event
|
|
9
|
+
* subscribers) are reported too, at warning level.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withSentryErrorReporting(logger: Logger): Logger;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.withSentryErrorReporting = withSentryErrorReporting;
|
|
37
|
+
const Sentry = __importStar(require("@sentry/node"));
|
|
38
|
+
/**
|
|
39
|
+
* Medusa's own HTTP error-handler middleware fully "handles" every thrown
|
|
40
|
+
* route/workflow error via logger.error(...) before it can ever reach an
|
|
41
|
+
* uncaught-exception process hook, so Sentry's default Node integrations
|
|
42
|
+
* never see it. Bridging logger.error(...) itself is the only place that
|
|
43
|
+
* reliably captures every error Medusa's framework already logs internally.
|
|
44
|
+
* Errors that Medusa logs through logger.warn(err) (failing event
|
|
45
|
+
* subscribers) are reported too, at warning level.
|
|
46
|
+
*/
|
|
47
|
+
function withSentryErrorReporting(logger) {
|
|
48
|
+
const originalError = logger.error.bind(logger);
|
|
49
|
+
const originalWarn = logger.warn.bind(logger);
|
|
50
|
+
return {
|
|
51
|
+
panic: logger.panic.bind(logger),
|
|
52
|
+
shouldLog: logger.shouldLog.bind(logger),
|
|
53
|
+
setLogLevel: logger.setLogLevel.bind(logger),
|
|
54
|
+
unsetLogLevel: logger.unsetLogLevel.bind(logger),
|
|
55
|
+
activity: logger.activity.bind(logger),
|
|
56
|
+
progress: logger.progress.bind(logger),
|
|
57
|
+
failure: logger.failure.bind(logger),
|
|
58
|
+
success: logger.success.bind(logger),
|
|
59
|
+
silly: logger.silly.bind(logger),
|
|
60
|
+
debug: logger.debug.bind(logger),
|
|
61
|
+
verbose: logger.verbose.bind(logger),
|
|
62
|
+
http: logger.http.bind(logger),
|
|
63
|
+
info: logger.info.bind(logger),
|
|
64
|
+
// Medusa's Redis Event Bus logs a failing subscriber's exception with
|
|
65
|
+
// warn(err), even on the final retry, so an Error passed to warn is a real
|
|
66
|
+
// failure too. Plain warning messages stay out of Sentry.
|
|
67
|
+
warn: (message) => {
|
|
68
|
+
if (message instanceof Error) {
|
|
69
|
+
Sentry.captureException(message, { level: "warning" });
|
|
70
|
+
}
|
|
71
|
+
return originalWarn(message);
|
|
72
|
+
},
|
|
73
|
+
log: logger.log.bind(logger),
|
|
74
|
+
error: (messageOrError, error) => {
|
|
75
|
+
const exception = error ?? (messageOrError instanceof Error ? messageOrError : new Error(messageOrError));
|
|
76
|
+
const loggerMessage = error && typeof messageOrError === "string" ? messageOrError : undefined;
|
|
77
|
+
Sentry.captureException(exception, loggerMessage ? { extra: { loggerMessage } } : undefined);
|
|
78
|
+
return originalError(messageOrError, error);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hartl-services/medusa-sentry-logger",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Bridges Medusa's configModule.logger to Sentry, so logger.error(...) calls surface in error tracking without instrumenting every route handler.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://gitlab.com/hartl-services-gmbh/services/food-supplements-e-commerce.git",
|
|
14
|
+
"directory": "plugins/sentry-logger"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": "./package.json",
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@medusajs/framework": "^2.19.0",
|
|
32
|
+
"@sentry/node": "^10.74.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@medusajs/framework": "2.19.0",
|
|
36
|
+
"@sentry/node": "^10.74.0",
|
|
37
|
+
"@swc/core": "^1.7.28",
|
|
38
|
+
"@swc/jest": "^0.2.39",
|
|
39
|
+
"@types/jest": "^29.5.14",
|
|
40
|
+
"@types/node": "^20.12.11",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"typescript": "^5.6.2"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.json",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test:unit": "jest"
|
|
51
|
+
}
|
|
52
|
+
}
|