@logtape/sentry 1.2.2 → 1.2.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/package.json +5 -2
- package/deno.json +0 -14
- package/src/mod.ts +0 -96
- package/tsdown.config.ts +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/sentry",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "LogTape Sentry sink",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"LogTape",
|
|
@@ -40,8 +40,11 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/"
|
|
45
|
+
],
|
|
43
46
|
"peerDependencies": {
|
|
44
|
-
"@logtape/logtape": "^1.2.
|
|
47
|
+
"@logtape/logtape": "^1.2.3"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"@sentry/core": "^9.28.1"
|
package/deno.json
DELETED
package/src/mod.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { LogRecord, Sink } from "@logtape/logtape";
|
|
2
|
-
import {
|
|
3
|
-
type EventHint,
|
|
4
|
-
getClient,
|
|
5
|
-
type ParameterizedString,
|
|
6
|
-
type Scope,
|
|
7
|
-
type SeverityLevel,
|
|
8
|
-
} from "@sentry/core";
|
|
9
|
-
|
|
10
|
-
function getParameterizedString(record: LogRecord): ParameterizedString {
|
|
11
|
-
let result = "";
|
|
12
|
-
let tplString = "";
|
|
13
|
-
const tplValues: string[] = [];
|
|
14
|
-
for (let i = 0; i < record.message.length; i++) {
|
|
15
|
-
if (i % 2 === 0) {
|
|
16
|
-
result += record.message[i];
|
|
17
|
-
tplString += String(record.message[i]).replaceAll("%", "%%");
|
|
18
|
-
} else {
|
|
19
|
-
const value = inspect(record.message[i]);
|
|
20
|
-
result += value;
|
|
21
|
-
tplString += `%s`;
|
|
22
|
-
tplValues.push(value);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
const paramStr = new String(result) as ParameterizedString;
|
|
26
|
-
paramStr.__sentry_template_string__ = tplString;
|
|
27
|
-
paramStr.__sentry_template_values__ = tplValues;
|
|
28
|
-
return paramStr;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
|
|
33
|
-
* and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
|
|
34
|
-
* falls back to {@link JSON.stringify}.
|
|
35
|
-
*
|
|
36
|
-
* @param value The value to inspect.
|
|
37
|
-
* @returns The string representation of the value.
|
|
38
|
-
*/
|
|
39
|
-
const inspect: (value: unknown) => string =
|
|
40
|
-
// @ts-ignore: Deno global
|
|
41
|
-
"Deno" in globalThis && "inspect" in globalThis.Deno &&
|
|
42
|
-
// @ts-ignore: Deno global
|
|
43
|
-
typeof globalThis.Deno.inspect === "function"
|
|
44
|
-
// @ts-ignore: Deno global
|
|
45
|
-
? globalThis.Deno.inspect
|
|
46
|
-
// @ts-ignore: Node.js global
|
|
47
|
-
: "util" in globalThis && "inspect" in globalThis.util &&
|
|
48
|
-
// @ts-ignore: Node.js global
|
|
49
|
-
globalThis.util.inspect === "function"
|
|
50
|
-
// @ts-ignore: Node.js global
|
|
51
|
-
? globalThis.util.inspect
|
|
52
|
-
: JSON.stringify;
|
|
53
|
-
|
|
54
|
-
interface SentryClientLike {
|
|
55
|
-
captureException: (
|
|
56
|
-
exception: unknown,
|
|
57
|
-
hint?: EventHint,
|
|
58
|
-
scope?: Scope,
|
|
59
|
-
) => string;
|
|
60
|
-
captureMessage: (
|
|
61
|
-
message: ParameterizedString,
|
|
62
|
-
level?: SeverityLevel,
|
|
63
|
-
hint?: EventHint,
|
|
64
|
-
scope?: Scope,
|
|
65
|
-
) => string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets a LogTape sink that sends logs to Sentry.
|
|
70
|
-
* @param client The Sentry client. If omitted, the global default client is
|
|
71
|
-
* used.
|
|
72
|
-
* @returns A LogTape sink that sends logs to Sentry.
|
|
73
|
-
*/
|
|
74
|
-
export function getSentrySink(client?: SentryClientLike): Sink {
|
|
75
|
-
return (record: LogRecord) => {
|
|
76
|
-
const message = getParameterizedString(record);
|
|
77
|
-
if (client == null) client = getClient();
|
|
78
|
-
if (record.level === "error" && record.properties.error instanceof Error) {
|
|
79
|
-
const { error, ...rest } = record.properties;
|
|
80
|
-
client?.captureException(error, {
|
|
81
|
-
data: {
|
|
82
|
-
message,
|
|
83
|
-
...rest,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
client?.captureMessage(
|
|
88
|
-
message,
|
|
89
|
-
record.level === "trace" ? "debug" : record.level,
|
|
90
|
-
{
|
|
91
|
-
data: record.properties,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|