@logtape/sentry 0.1.0-dev.3

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,20 @@
1
+ MIT License
2
+
3
+ Copyright 2024 Hong Minhee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ @logtape/sentry: LogTape Sentry Sink
2
+ ====================================
3
+
4
+ [![JSR][JSR badge]][JSR]
5
+ [![npm][npm badge]][npm]
6
+ [![GitHub Actions][GitHub Actions badge]][GitHub Actions]
7
+
8
+ This package provides an [Sentry] sink for [LogTape]. It allows you to
9
+ capture your LogTape logs and send them to Sentry.
10
+
11
+ ![LogTape messages show up in Sentry](./screenshot.png)
12
+
13
+ [JSR]: https://jsr.io/@logtape/sentry
14
+ [JSR badge]: https://jsr.io/badges/@logtape/sentry
15
+ [npm]: https://www.npmjs.com/package/@logtape/sentry
16
+ [npm badge]: https://img.shields.io/npm/v/@logtape/sentry?logo=npm
17
+ [GitHub Actions]: https://github.com/dahlia/logtape-sentry/actions/workflows/main.yaml
18
+ [GitHub Actions badge]: https://github.com/dahlia/logtape-sentry/actions/workflows/main.yaml/badge.svg
19
+ [Sentry]: https://sentry.io/
20
+ [LogTape]: https://logtape.org/
21
+
22
+
23
+ Installation
24
+ ------------
25
+
26
+ The package is available on [JSR] and [npm].
27
+
28
+ ~~~~ bash
29
+ deno add @logtape/sentry # for Deno
30
+ npm add @logtape/sentry # for npm
31
+ pnpm add @logtape/sentry # for pnpm
32
+ yarn add @logtape/sentry # for Yarn
33
+ bun add @logtape/sentry # for Bun
34
+ ~~~~
35
+
36
+
37
+ Usage
38
+ -----
39
+
40
+ The quickest way to get started is to use the `getSentrySink()` function
41
+ without any arguments:
42
+
43
+ ~~~~ typescript
44
+ import { configure } from "@logtape/logtape";
45
+ import { getSentrySink } from "@logtape/sentry";
46
+
47
+ await configure({
48
+ sinks: {
49
+ sentry: getSentrySink(),
50
+ },
51
+ filters: {},
52
+ loggers: [
53
+ { category: [], sinks: ["sentry"], level: "debug" },
54
+ ],
55
+ });
56
+ ~~~~
57
+
58
+ If you want to explicitly configure the Sentry client, you can pass the
59
+ `Client` instance to the `getSentrySink()` function:
60
+
61
+ ~~~~ typescript
62
+ import { configure } from "@logtape/logtape";
63
+ import { init } from "@sentry/node";
64
+
65
+ const client = init({
66
+ dsn: process.env.SENTRY_DSN,
67
+ });
68
+
69
+ await configure({
70
+ sinks: {
71
+ sentry: getSentrySink(client),
72
+ },
73
+ filters: {},
74
+ loggers: [
75
+ { category: [], sinks: ["sentry"], level: "debug" },
76
+ ],
77
+ });
78
+ ~~~~
79
+
80
+
81
+ Changelog
82
+ ---------
83
+
84
+ ### Version 0.1.0
85
+
86
+ To be released.
@@ -0,0 +1,57 @@
1
+ const dntGlobals = {};
2
+ export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
3
+ function createMergeProxy(baseObj, extObj) {
4
+ return new Proxy(baseObj, {
5
+ get(_target, prop, _receiver) {
6
+ if (prop in extObj) {
7
+ return extObj[prop];
8
+ }
9
+ else {
10
+ return baseObj[prop];
11
+ }
12
+ },
13
+ set(_target, prop, value) {
14
+ if (prop in extObj) {
15
+ delete extObj[prop];
16
+ }
17
+ baseObj[prop] = value;
18
+ return true;
19
+ },
20
+ deleteProperty(_target, prop) {
21
+ let success = false;
22
+ if (prop in extObj) {
23
+ delete extObj[prop];
24
+ success = true;
25
+ }
26
+ if (prop in baseObj) {
27
+ delete baseObj[prop];
28
+ success = true;
29
+ }
30
+ return success;
31
+ },
32
+ ownKeys(_target) {
33
+ const baseKeys = Reflect.ownKeys(baseObj);
34
+ const extKeys = Reflect.ownKeys(extObj);
35
+ const extKeysSet = new Set(extKeys);
36
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
37
+ },
38
+ defineProperty(_target, prop, desc) {
39
+ if (prop in extObj) {
40
+ delete extObj[prop];
41
+ }
42
+ Reflect.defineProperty(baseObj, prop, desc);
43
+ return true;
44
+ },
45
+ getOwnPropertyDescriptor(_target, prop) {
46
+ if (prop in extObj) {
47
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
48
+ }
49
+ else {
50
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
51
+ }
52
+ },
53
+ has(_target, prop) {
54
+ return prop in extObj || prop in baseObj;
55
+ },
56
+ });
57
+ }
package/esm/mod.js ADDED
@@ -0,0 +1,58 @@
1
+ import * as dntShim from "./_dnt.shims.js";
2
+ import { getClient } from "@sentry/core";
3
+ function getParameterizedString(record) {
4
+ let result = "";
5
+ let tplString = "";
6
+ const tplValues = [];
7
+ for (let i = 0; i < record.message.length; i++) {
8
+ if (i % 2 === 0) {
9
+ result += record.message[i];
10
+ tplString += String(record.message[i]).replaceAll("%", "%%");
11
+ }
12
+ else {
13
+ const value = inspect(record.message[i]);
14
+ result += value;
15
+ tplString += `%s`;
16
+ tplValues.push(value);
17
+ }
18
+ }
19
+ const paramStr = new String(result);
20
+ paramStr.__sentry_template_string__ = tplString;
21
+ paramStr.__sentry_template_values__ = tplValues;
22
+ return result;
23
+ }
24
+ /**
25
+ * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
26
+ * and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
27
+ * falls back to {@link JSON.stringify}.
28
+ *
29
+ * @param value The value to inspect.
30
+ * @returns The string representation of the value.
31
+ */
32
+ const inspect =
33
+ // @ts-ignore: Deno global
34
+ "Deno" in dntShim.dntGlobalThis && "inspect" in globalThis.Deno &&
35
+ // @ts-ignore: Deno global
36
+ typeof globalThis.Deno.inspect === "function"
37
+ // @ts-ignore: Deno global
38
+ ? globalThis.Deno.inspect
39
+ // @ts-ignore: Node.js global
40
+ : "util" in dntShim.dntGlobalThis && "inspect" in globalThis.util &&
41
+ // @ts-ignore: Node.js global
42
+ globalThis.util.inspect === "function"
43
+ // @ts-ignore: Node.js global
44
+ ? globalThis.util.inspect
45
+ : JSON.stringify;
46
+ /**
47
+ * Gets a LogTape sink that sends logs to Sentry.
48
+ * @param client The Sentry client. If omitted, the global default client is
49
+ * used.
50
+ * @returns A LogTape sink that sends logs to Sentry.
51
+ */
52
+ export function getSentrySink(client) {
53
+ return (record) => {
54
+ if (client == null)
55
+ client = getClient();
56
+ client?.captureMessage(getParameterizedString(record), record.level, { data: record.properties });
57
+ };
58
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@logtape/sentry",
3
+ "version": "0.1.0-dev.3+ff41ddb4",
4
+ "description": "LogTape Sentry Sink",
5
+ "keywords": [
6
+ "LogTape",
7
+ "Sentry"
8
+ ],
9
+ "author": {
10
+ "name": "Hong Minhee",
11
+ "email": "hong@minhee.org",
12
+ "url": "https://hongminhee.org/"
13
+ },
14
+ "homepage": "https://github.com/dahlia/logtape-sentry",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/dahlia/logtape-sentry.git"
18
+ },
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://github.com/dahlia/logtape-sentry/issues"
22
+ },
23
+ "main": "./script/mod.js",
24
+ "module": "./esm/mod.js",
25
+ "types": "./types/mod.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": {
29
+ "types": "./types/mod.d.ts",
30
+ "default": "./esm/mod.js"
31
+ },
32
+ "require": {
33
+ "types": "./types/mod.d.ts",
34
+ "default": "./script/mod.js"
35
+ }
36
+ }
37
+ },
38
+ "scripts": {
39
+ "test": "node test_runner.js"
40
+ },
41
+ "funding": [
42
+ "https://github.com/sponsors/dahlia"
43
+ ],
44
+ "dependencies": {
45
+ "@logtape/logtape": "^0.8.0",
46
+ "@sentry/core": "^8.40.0",
47
+ "@sentry/types": "^8.40.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^20.9.0",
51
+ "picocolors": "^1.0.0"
52
+ },
53
+ "_generatedBy": "dnt@dev"
54
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dntGlobalThis = void 0;
4
+ const dntGlobals = {};
5
+ exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
6
+ function createMergeProxy(baseObj, extObj) {
7
+ return new Proxy(baseObj, {
8
+ get(_target, prop, _receiver) {
9
+ if (prop in extObj) {
10
+ return extObj[prop];
11
+ }
12
+ else {
13
+ return baseObj[prop];
14
+ }
15
+ },
16
+ set(_target, prop, value) {
17
+ if (prop in extObj) {
18
+ delete extObj[prop];
19
+ }
20
+ baseObj[prop] = value;
21
+ return true;
22
+ },
23
+ deleteProperty(_target, prop) {
24
+ let success = false;
25
+ if (prop in extObj) {
26
+ delete extObj[prop];
27
+ success = true;
28
+ }
29
+ if (prop in baseObj) {
30
+ delete baseObj[prop];
31
+ success = true;
32
+ }
33
+ return success;
34
+ },
35
+ ownKeys(_target) {
36
+ const baseKeys = Reflect.ownKeys(baseObj);
37
+ const extKeys = Reflect.ownKeys(extObj);
38
+ const extKeysSet = new Set(extKeys);
39
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
40
+ },
41
+ defineProperty(_target, prop, desc) {
42
+ if (prop in extObj) {
43
+ delete extObj[prop];
44
+ }
45
+ Reflect.defineProperty(baseObj, prop, desc);
46
+ return true;
47
+ },
48
+ getOwnPropertyDescriptor(_target, prop) {
49
+ if (prop in extObj) {
50
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
51
+ }
52
+ else {
53
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
54
+ }
55
+ },
56
+ has(_target, prop) {
57
+ return prop in extObj || prop in baseObj;
58
+ },
59
+ });
60
+ }
package/script/mod.js ADDED
@@ -0,0 +1,84 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getSentrySink = getSentrySink;
27
+ const dntShim = __importStar(require("./_dnt.shims.js"));
28
+ const core_1 = require("@sentry/core");
29
+ function getParameterizedString(record) {
30
+ let result = "";
31
+ let tplString = "";
32
+ const tplValues = [];
33
+ for (let i = 0; i < record.message.length; i++) {
34
+ if (i % 2 === 0) {
35
+ result += record.message[i];
36
+ tplString += String(record.message[i]).replaceAll("%", "%%");
37
+ }
38
+ else {
39
+ const value = inspect(record.message[i]);
40
+ result += value;
41
+ tplString += `%s`;
42
+ tplValues.push(value);
43
+ }
44
+ }
45
+ const paramStr = new String(result);
46
+ paramStr.__sentry_template_string__ = tplString;
47
+ paramStr.__sentry_template_values__ = tplValues;
48
+ return result;
49
+ }
50
+ /**
51
+ * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
52
+ * and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
53
+ * falls back to {@link JSON.stringify}.
54
+ *
55
+ * @param value The value to inspect.
56
+ * @returns The string representation of the value.
57
+ */
58
+ const inspect =
59
+ // @ts-ignore: Deno global
60
+ "Deno" in dntShim.dntGlobalThis && "inspect" in globalThis.Deno &&
61
+ // @ts-ignore: Deno global
62
+ typeof globalThis.Deno.inspect === "function"
63
+ // @ts-ignore: Deno global
64
+ ? globalThis.Deno.inspect
65
+ // @ts-ignore: Node.js global
66
+ : "util" in dntShim.dntGlobalThis && "inspect" in globalThis.util &&
67
+ // @ts-ignore: Node.js global
68
+ globalThis.util.inspect === "function"
69
+ // @ts-ignore: Node.js global
70
+ ? globalThis.util.inspect
71
+ : JSON.stringify;
72
+ /**
73
+ * Gets a LogTape sink that sends logs to Sentry.
74
+ * @param client The Sentry client. If omitted, the global default client is
75
+ * used.
76
+ * @returns A LogTape sink that sends logs to Sentry.
77
+ */
78
+ function getSentrySink(client) {
79
+ return (record) => {
80
+ if (client == null)
81
+ client = (0, core_1.getClient)();
82
+ client?.captureMessage(getParameterizedString(record), record.level, { data: record.properties });
83
+ };
84
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,2 @@
1
+ export declare const dntGlobalThis: Omit<typeof globalThis, never>;
2
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
package/types/mod.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { Sink } from "@logtape/logtape";
2
+ import { type BaseClient } from "@sentry/core";
3
+ import type { ClientOptions } from "@sentry/types";
4
+ /**
5
+ * Gets a LogTape sink that sends logs to Sentry.
6
+ * @param client The Sentry client. If omitted, the global default client is
7
+ * used.
8
+ * @returns A LogTape sink that sends logs to Sentry.
9
+ */
10
+ export declare function getSentrySink(client?: BaseClient<ClientOptions>): Sink;
11
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,UAAU,EAAa,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AAgDxE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,GAAG,IAAI,CAStE"}