@loglayer/transport-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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 LogLayer
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,63 @@
1
+ # @loglayer/transport-sentry
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@loglayer/transport-sentry.svg)](https://www.npmjs.com/package/@loglayer/transport-sentry)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@loglayer/transport-sentry.svg)](https://www.npmjs.com/package/@loglayer/transport-sentry)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
6
+
7
+ Sentry transport for the LogLayer logging library. This transport sends structured logs to Sentry using any Sentry logger instance.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @loglayer/transport-sentry serialize-error <sentry-sdk>
13
+ ```
14
+
15
+ ```bash
16
+ yarn add @loglayer/transport-sentry serialize-error <sentry-sdk>
17
+ ```
18
+
19
+ ```bash
20
+ pnpm add @loglayer/transport-sentry serialize-error <sentry-sdk>
21
+ ```
22
+
23
+ Replace `<sentry-sdk>` with the appropriate Sentry SDK for your platform:
24
+
25
+ - **Browser**: [@sentry/browser](https://docs.sentry.io/platforms/javascript/logs/)
26
+ - **Next.js**: [@sentry/nextjs](https://docs.sentry.io/platforms/javascript/guides/nextjs/logs/)
27
+ - **Bun**: [@sentry/bun](https://docs.sentry.io/platforms/javascript/guides/bun/logs/)
28
+ - **Deno**: [@sentry/deno](https://docs.sentry.io/platforms/javascript/guides/deno/)
29
+ - **Node.js**: [@sentry/node](https://docs.sentry.io/platforms/javascript/guides/node/)
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import { LogLayer } from "loglayer";
35
+ import { SentryTransport } from "@loglayer/transport-sentry";
36
+ import { serializeError } from "serialize-error";
37
+ // node.js example, but most of the JS-based SDKs follow this pattern
38
+ import * as Sentry from "@sentry/node";
39
+
40
+ // In most cases, you'll want to initialize at the top-most entrypoint
41
+ // to your app so Sentry can instrument your code, such as the index.ts file
42
+ Sentry.init({
43
+ dsn: "YOUR_SENTRY_DSN",
44
+ enableLogs: true,
45
+ });
46
+
47
+ const log = new LogLayer({
48
+ errorSerializer: serializeError,
49
+ transport: [
50
+ new SentryTransport({
51
+ logger: Sentry.logger,
52
+ }),
53
+ ],
54
+ });
55
+
56
+ // Use LogLayer as normal
57
+ log.withMetadata({ userId: 123 }).info("User logged in");
58
+ log.withError(new Error("Something went wrong")).error("Operation failed");
59
+ ```
60
+
61
+ ## Documentation
62
+
63
+ For more detailed documentation, visit the [LogLayer website](https://loglayer.dev/transports/sentry).
package/dist/index.cjs ADDED
@@ -0,0 +1,75 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let __loglayer_transport = require("@loglayer/transport");
25
+ __loglayer_transport = __toESM(__loglayer_transport);
26
+
27
+ //#region src/SentryTransport.ts
28
+ /**
29
+ * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.
30
+ * It uses the Sentry logger API to send structured logs to Sentry.
31
+ *
32
+ * Features:
33
+ * - Uses Sentry logger for structured logging
34
+ * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)
35
+ * - Automatic error and debug callbacks
36
+ * - Integrates with Sentry's structured logging features
37
+ */
38
+ var SentryTransport = class extends __loglayer_transport.BaseTransport {
39
+ /**
40
+ * Processes and ships log entries to Sentry using the Sentry logger.
41
+ *
42
+ * @param params - Log parameters including level, messages, and metadata
43
+ * @returns The original messages array
44
+ */
45
+ shipToLogger({ logLevel, messages, data, hasData }) {
46
+ const args = [messages.join(" ")];
47
+ if (data && hasData) args.push(data);
48
+ switch (logLevel) {
49
+ case "trace":
50
+ this.logger.trace(...args);
51
+ break;
52
+ case "debug":
53
+ this.logger.debug(...args);
54
+ break;
55
+ case "info":
56
+ this.logger.info(...args);
57
+ break;
58
+ case "warn":
59
+ this.logger.warn(...args);
60
+ break;
61
+ case "error":
62
+ this.logger.error(...args);
63
+ break;
64
+ case "fatal":
65
+ this.logger.fatal(...args);
66
+ break;
67
+ default: this.logger.info(...args);
68
+ }
69
+ return messages;
70
+ }
71
+ };
72
+
73
+ //#endregion
74
+ exports.SentryTransport = SentryTransport;
75
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["BaseTransport"],"sources":["../src/SentryTransport.ts"],"sourcesContent":["import type { LogLayerTransportConfig, LogLayerTransportParams } from \"@loglayer/transport\";\nimport { BaseTransport } from \"@loglayer/transport\";\n\n/**\n * Sentry logger interface\n */\nexport interface SentryLogger {\n trace: (...args: any[]) => void;\n debug: (...args: any[]) => void;\n info: (...args: any[]) => void;\n warn: (...args: any[]) => void;\n error: (...args: any[]) => void;\n fatal: (...args: any[]) => void;\n}\n\n/**\n * Configuration options for the Sentry transport.\n */\nexport interface SentryTransportConfig extends LogLayerTransportConfig<SentryLogger> {\n // No additional configuration needed beyond the base transport config\n}\n\n/**\n * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.\n * It uses the Sentry logger API to send structured logs to Sentry.\n *\n * Features:\n * - Uses Sentry logger for structured logging\n * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)\n * - Automatic error and debug callbacks\n * - Integrates with Sentry's structured logging features\n */\nexport class SentryTransport extends BaseTransport<SentryLogger> {\n /**\n * Processes and ships log entries to Sentry using the Sentry logger.\n *\n * @param params - Log parameters including level, messages, and metadata\n * @returns The original messages array\n */\n shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[] {\n // Create a new array with joined message and optional data\n const args = [messages.join(\" \")];\n\n if (data && hasData) {\n // Add data object as a separate parameter\n // @ts-expect-error\n args.push(data);\n }\n\n // Map LogLayer log levels to Sentry logger methods\n switch (logLevel) {\n case \"trace\":\n this.logger.trace(...args);\n break;\n case \"debug\":\n this.logger.debug(...args);\n break;\n case \"info\":\n this.logger.info(...args);\n break;\n case \"warn\":\n this.logger.warn(...args);\n break;\n case \"error\":\n this.logger.error(...args);\n break;\n case \"fatal\":\n this.logger.fatal(...args);\n break;\n default:\n // Fallback to info level for unknown log levels\n this.logger.info(...args);\n }\n\n return messages;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,kBAAb,cAAqCA,mCAA4B;;;;;;;CAO/D,aAAa,EAAE,UAAU,UAAU,MAAM,WAA2C;EAElF,MAAM,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;AAEjC,MAAI,QAAQ,QAGV,MAAK,KAAK,KAAK;AAIjB,UAAQ,UAAR;GACE,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,KAAK,GAAG,KAAK;AACzB;GACF,KAAK;AACH,SAAK,OAAO,KAAK,GAAG,KAAK;AACzB;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,QAEE,MAAK,OAAO,KAAK,GAAG,KAAK;;AAG7B,SAAO"}
@@ -0,0 +1,46 @@
1
+ import { BaseTransport, LogLayerTransportConfig, LogLayerTransportParams } from "@loglayer/transport";
2
+
3
+ //#region src/SentryTransport.d.ts
4
+
5
+ /**
6
+ * Sentry logger interface
7
+ */
8
+ interface SentryLogger {
9
+ trace: (...args: any[]) => void;
10
+ debug: (...args: any[]) => void;
11
+ info: (...args: any[]) => void;
12
+ warn: (...args: any[]) => void;
13
+ error: (...args: any[]) => void;
14
+ fatal: (...args: any[]) => void;
15
+ }
16
+ /**
17
+ * Configuration options for the Sentry transport.
18
+ */
19
+ interface SentryTransportConfig extends LogLayerTransportConfig<SentryLogger> {}
20
+ /**
21
+ * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.
22
+ * It uses the Sentry logger API to send structured logs to Sentry.
23
+ *
24
+ * Features:
25
+ * - Uses Sentry logger for structured logging
26
+ * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)
27
+ * - Automatic error and debug callbacks
28
+ * - Integrates with Sentry's structured logging features
29
+ */
30
+ declare class SentryTransport extends BaseTransport<SentryLogger> {
31
+ /**
32
+ * Processes and ships log entries to Sentry using the Sentry logger.
33
+ *
34
+ * @param params - Log parameters including level, messages, and metadata
35
+ * @returns The original messages array
36
+ */
37
+ shipToLogger({
38
+ logLevel,
39
+ messages,
40
+ data,
41
+ hasData
42
+ }: LogLayerTransportParams): any[];
43
+ }
44
+ //#endregion
45
+ export { type SentryLogger, SentryTransport, type SentryTransportConfig };
46
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,46 @@
1
+ import { BaseTransport, LogLayerTransportConfig, LogLayerTransportParams } from "@loglayer/transport";
2
+
3
+ //#region src/SentryTransport.d.ts
4
+
5
+ /**
6
+ * Sentry logger interface
7
+ */
8
+ interface SentryLogger {
9
+ trace: (...args: any[]) => void;
10
+ debug: (...args: any[]) => void;
11
+ info: (...args: any[]) => void;
12
+ warn: (...args: any[]) => void;
13
+ error: (...args: any[]) => void;
14
+ fatal: (...args: any[]) => void;
15
+ }
16
+ /**
17
+ * Configuration options for the Sentry transport.
18
+ */
19
+ interface SentryTransportConfig extends LogLayerTransportConfig<SentryLogger> {}
20
+ /**
21
+ * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.
22
+ * It uses the Sentry logger API to send structured logs to Sentry.
23
+ *
24
+ * Features:
25
+ * - Uses Sentry logger for structured logging
26
+ * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)
27
+ * - Automatic error and debug callbacks
28
+ * - Integrates with Sentry's structured logging features
29
+ */
30
+ declare class SentryTransport extends BaseTransport<SentryLogger> {
31
+ /**
32
+ * Processes and ships log entries to Sentry using the Sentry logger.
33
+ *
34
+ * @param params - Log parameters including level, messages, and metadata
35
+ * @returns The original messages array
36
+ */
37
+ shipToLogger({
38
+ logLevel,
39
+ messages,
40
+ data,
41
+ hasData
42
+ }: LogLayerTransportParams): any[];
43
+ }
44
+ //#endregion
45
+ export { type SentryLogger, SentryTransport, type SentryTransportConfig };
46
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { BaseTransport } from "@loglayer/transport";
2
+
3
+ //#region src/SentryTransport.ts
4
+ /**
5
+ * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.
6
+ * It uses the Sentry logger API to send structured logs to Sentry.
7
+ *
8
+ * Features:
9
+ * - Uses Sentry logger for structured logging
10
+ * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)
11
+ * - Automatic error and debug callbacks
12
+ * - Integrates with Sentry's structured logging features
13
+ */
14
+ var SentryTransport = class extends BaseTransport {
15
+ /**
16
+ * Processes and ships log entries to Sentry using the Sentry logger.
17
+ *
18
+ * @param params - Log parameters including level, messages, and metadata
19
+ * @returns The original messages array
20
+ */
21
+ shipToLogger({ logLevel, messages, data, hasData }) {
22
+ const args = [messages.join(" ")];
23
+ if (data && hasData) args.push(data);
24
+ switch (logLevel) {
25
+ case "trace":
26
+ this.logger.trace(...args);
27
+ break;
28
+ case "debug":
29
+ this.logger.debug(...args);
30
+ break;
31
+ case "info":
32
+ this.logger.info(...args);
33
+ break;
34
+ case "warn":
35
+ this.logger.warn(...args);
36
+ break;
37
+ case "error":
38
+ this.logger.error(...args);
39
+ break;
40
+ case "fatal":
41
+ this.logger.fatal(...args);
42
+ break;
43
+ default: this.logger.info(...args);
44
+ }
45
+ return messages;
46
+ }
47
+ };
48
+
49
+ //#endregion
50
+ export { SentryTransport };
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/SentryTransport.ts"],"sourcesContent":["import type { LogLayerTransportConfig, LogLayerTransportParams } from \"@loglayer/transport\";\nimport { BaseTransport } from \"@loglayer/transport\";\n\n/**\n * Sentry logger interface\n */\nexport interface SentryLogger {\n trace: (...args: any[]) => void;\n debug: (...args: any[]) => void;\n info: (...args: any[]) => void;\n warn: (...args: any[]) => void;\n error: (...args: any[]) => void;\n fatal: (...args: any[]) => void;\n}\n\n/**\n * Configuration options for the Sentry transport.\n */\nexport interface SentryTransportConfig extends LogLayerTransportConfig<SentryLogger> {\n // No additional configuration needed beyond the base transport config\n}\n\n/**\n * SentryTransport is responsible for sending logs to Sentry using the Sentry SDK.\n * It uses the Sentry logger API to send structured logs to Sentry.\n *\n * Features:\n * - Uses Sentry logger for structured logging\n * - Supports all Sentry log levels (trace, debug, info, warn, error, fatal)\n * - Automatic error and debug callbacks\n * - Integrates with Sentry's structured logging features\n */\nexport class SentryTransport extends BaseTransport<SentryLogger> {\n /**\n * Processes and ships log entries to Sentry using the Sentry logger.\n *\n * @param params - Log parameters including level, messages, and metadata\n * @returns The original messages array\n */\n shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[] {\n // Create a new array with joined message and optional data\n const args = [messages.join(\" \")];\n\n if (data && hasData) {\n // Add data object as a separate parameter\n // @ts-expect-error\n args.push(data);\n }\n\n // Map LogLayer log levels to Sentry logger methods\n switch (logLevel) {\n case \"trace\":\n this.logger.trace(...args);\n break;\n case \"debug\":\n this.logger.debug(...args);\n break;\n case \"info\":\n this.logger.info(...args);\n break;\n case \"warn\":\n this.logger.warn(...args);\n break;\n case \"error\":\n this.logger.error(...args);\n break;\n case \"fatal\":\n this.logger.fatal(...args);\n break;\n default:\n // Fallback to info level for unknown log levels\n this.logger.info(...args);\n }\n\n return messages;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAgCA,IAAa,kBAAb,cAAqC,cAA4B;;;;;;;CAO/D,aAAa,EAAE,UAAU,UAAU,MAAM,WAA2C;EAElF,MAAM,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC;AAEjC,MAAI,QAAQ,QAGV,MAAK,KAAK,KAAK;AAIjB,UAAQ,UAAR;GACE,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,KAAK,GAAG,KAAK;AACzB;GACF,KAAK;AACH,SAAK,OAAO,KAAK,GAAG,KAAK;AACzB;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,KAAK;AACH,SAAK,OAAO,MAAM,GAAG,KAAK;AAC1B;GACF,QAEE,MAAK,OAAO,KAAK,GAAG,KAAK;;AAG7B,SAAO"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@loglayer/transport-sentry",
3
+ "description": "Sentry transport for the LogLayer logging library.",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "types": "./dist/index.d.ts",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/loglayer/loglayer.git",
23
+ "directory": "packages/transports/sentry"
24
+ },
25
+ "author": "Theo Gravity <theo@suteki.nu>",
26
+ "keywords": [
27
+ "logging",
28
+ "log",
29
+ "loglayer",
30
+ "sentry",
31
+ "transport"
32
+ ],
33
+ "dependencies": {
34
+ "@loglayer/transport": "2.3.4"
35
+ },
36
+ "devDependencies": {
37
+ "@sentry/node": "10.19.0",
38
+ "@types/node": "24.7.2",
39
+ "dotenv": "17.2.3",
40
+ "serialize-error": "12.0.0",
41
+ "tsdown": "0.15.7",
42
+ "tsx": "4.20.6",
43
+ "typescript": "5.9.3",
44
+ "vitest": "3.2.4",
45
+ "loglayer": "6.9.1",
46
+ "@internal/tsconfig": "2.1.0"
47
+ },
48
+ "bugs": "https://github.com/loglayer/loglayer/issues",
49
+ "engines": {
50
+ "node": ">=18"
51
+ },
52
+ "files": [
53
+ "dist"
54
+ ],
55
+ "homepage": "https://loglayer.dev",
56
+ "scripts": {
57
+ "build": "tsdown src/index.ts",
58
+ "test": "vitest --run",
59
+ "clean": "rm -rf .turbo node_modules dist",
60
+ "lint": "biome check --no-errors-on-unmatched --write --unsafe src",
61
+ "lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
62
+ "verify-types": "tsc --noEmit",
63
+ "livetest": "tsx src/__tests__/livetest.ts"
64
+ }
65
+ }