sentry-vir 0.0.2 → 0.0.4
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.
|
@@ -5,7 +5,7 @@ import { EventDetails, EventExtraContext } from '../event-context/event-context'
|
|
|
5
5
|
/** The bare minimum Sentry client needed for logging events. */
|
|
6
6
|
export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent'>;
|
|
7
7
|
/** An event that was triggered before setSentryClientForLogging was called. */
|
|
8
|
-
export type PrematureEvent<EntryPointFunction extends AnyFunction> = {
|
|
8
|
+
export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
|
|
9
9
|
entryPoint: EntryPointFunction;
|
|
10
10
|
inputs: Parameters<EntryPointFunction>;
|
|
11
11
|
};
|
|
@@ -13,7 +13,7 @@ export type PrematureEvent<EntryPointFunction extends AnyFunction> = {
|
|
|
13
13
|
* Used to store events before the Sentry client is setup. This is exported for testing purposes
|
|
14
14
|
* only, you don't need to do anything with this.
|
|
15
15
|
*/
|
|
16
|
-
export declare const prematureSentryEvents: PrematureEvent
|
|
16
|
+
export declare const prematureSentryEvents: PrematureEvent[];
|
|
17
17
|
/**
|
|
18
18
|
* Asynchronously set the Sentry client for logging. When this is called, any events that were
|
|
19
19
|
* triggered beforehand are handled. Thus, this set can be done at any time, allowing for
|
|
@@ -30,31 +30,42 @@ async function setSentryClientForLogging(client) {
|
|
|
30
30
|
exports.setSentryClientForLogging = setSentryClientForLogging;
|
|
31
31
|
function sendPrematureEvents() {
|
|
32
32
|
while (exports.prematureSentryEvents.length) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
try {
|
|
34
|
+
const prematureLog = exports.prematureSentryEvents.pop();
|
|
35
|
+
if (!prematureLog) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
prematureLog.entryPoint(...prematureLog.inputs);
|
|
39
|
+
}
|
|
40
|
+
catch (caught) {
|
|
41
|
+
console.error('error while trying to send sentry logs:', caught);
|
|
36
42
|
}
|
|
37
|
-
prematureLog.entryPoint(...prematureLog.inputs);
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
/** Record an error to Sentry without throwing it. */
|
|
41
46
|
function handleError(error, extraContext) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
try {
|
|
48
|
+
if (!sentryClientForLogging) {
|
|
49
|
+
exports.prematureSentryEvents.push({
|
|
50
|
+
entryPoint: handleError,
|
|
51
|
+
inputs: [
|
|
52
|
+
error,
|
|
53
|
+
extraContext,
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)({
|
|
59
|
+
extraContext,
|
|
60
|
+
severity: event_severity_1.EventSeverityEnum.Error,
|
|
49
61
|
});
|
|
62
|
+
const eventId = sentryClientForLogging.captureException(error, scopeContext);
|
|
63
|
+
return eventId;
|
|
64
|
+
}
|
|
65
|
+
catch (caught) {
|
|
66
|
+
console.error('error while trying to handle error:', caught);
|
|
50
67
|
return undefined;
|
|
51
68
|
}
|
|
52
|
-
const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)({
|
|
53
|
-
extraContext,
|
|
54
|
-
severity: event_severity_1.EventSeverityEnum.Error,
|
|
55
|
-
});
|
|
56
|
-
const eventId = sentryClientForLogging.captureException(error, scopeContext);
|
|
57
|
-
return eventId;
|
|
58
69
|
}
|
|
59
70
|
exports.handleError = handleError;
|
|
60
71
|
/** Send non-error events to Sentry. */
|
|
@@ -75,22 +86,28 @@ function wrapLogWithSeverity(severity) {
|
|
|
75
86
|
};
|
|
76
87
|
}
|
|
77
88
|
function sendLogToSentry(logInfo, eventDetails) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
try {
|
|
90
|
+
if (!sentryClientForLogging) {
|
|
91
|
+
exports.prematureSentryEvents.push({
|
|
92
|
+
entryPoint: sendLogToSentry,
|
|
93
|
+
inputs: [
|
|
94
|
+
logInfo,
|
|
95
|
+
eventDetails,
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)(eventDetails);
|
|
101
|
+
const eventId = (0, common_1.isRuntimeTypeOf)(logInfo, 'string')
|
|
102
|
+
? sentryClientForLogging.captureMessage(logInfo, scopeContext)
|
|
103
|
+
: sentryClientForLogging.captureEvent({
|
|
104
|
+
...logInfo,
|
|
105
|
+
...scopeContext,
|
|
106
|
+
});
|
|
107
|
+
return eventId;
|
|
108
|
+
}
|
|
109
|
+
catch (caught) {
|
|
110
|
+
console.error('error while trying to send log:', caught);
|
|
86
111
|
return undefined;
|
|
87
112
|
}
|
|
88
|
-
const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)(eventDetails);
|
|
89
|
-
const eventId = (0, common_1.isRuntimeTypeOf)(logInfo, 'string')
|
|
90
|
-
? sentryClientForLogging.captureMessage(logInfo, scopeContext)
|
|
91
|
-
: sentryClientForLogging.captureEvent({
|
|
92
|
-
...logInfo,
|
|
93
|
-
...scopeContext,
|
|
94
|
-
});
|
|
95
|
-
return eventId;
|
|
96
113
|
}
|
|
@@ -26,31 +26,42 @@ export async function setSentryClientForLogging(client) {
|
|
|
26
26
|
}
|
|
27
27
|
function sendPrematureEvents() {
|
|
28
28
|
while (prematureSentryEvents.length) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
try {
|
|
30
|
+
const prematureLog = prematureSentryEvents.pop();
|
|
31
|
+
if (!prematureLog) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
prematureLog.entryPoint(...prematureLog.inputs);
|
|
35
|
+
}
|
|
36
|
+
catch (caught) {
|
|
37
|
+
console.error('error while trying to send sentry logs:', caught);
|
|
32
38
|
}
|
|
33
|
-
prematureLog.entryPoint(...prematureLog.inputs);
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
/** Record an error to Sentry without throwing it. */
|
|
37
42
|
export function handleError(error, extraContext) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
try {
|
|
44
|
+
if (!sentryClientForLogging) {
|
|
45
|
+
prematureSentryEvents.push({
|
|
46
|
+
entryPoint: handleError,
|
|
47
|
+
inputs: [
|
|
48
|
+
error,
|
|
49
|
+
extraContext,
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const scopeContext = convertEventDetailsToSentryContext({
|
|
55
|
+
extraContext,
|
|
56
|
+
severity: EventSeverityEnum.Error,
|
|
45
57
|
});
|
|
58
|
+
const eventId = sentryClientForLogging.captureException(error, scopeContext);
|
|
59
|
+
return eventId;
|
|
60
|
+
}
|
|
61
|
+
catch (caught) {
|
|
62
|
+
console.error('error while trying to handle error:', caught);
|
|
46
63
|
return undefined;
|
|
47
64
|
}
|
|
48
|
-
const scopeContext = convertEventDetailsToSentryContext({
|
|
49
|
-
extraContext,
|
|
50
|
-
severity: EventSeverityEnum.Error,
|
|
51
|
-
});
|
|
52
|
-
const eventId = sentryClientForLogging.captureException(error, scopeContext);
|
|
53
|
-
return eventId;
|
|
54
65
|
}
|
|
55
66
|
/** Send non-error events to Sentry. */
|
|
56
67
|
export const sendLog = {
|
|
@@ -70,22 +81,28 @@ function wrapLogWithSeverity(severity) {
|
|
|
70
81
|
};
|
|
71
82
|
}
|
|
72
83
|
function sendLogToSentry(logInfo, eventDetails) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
try {
|
|
85
|
+
if (!sentryClientForLogging) {
|
|
86
|
+
prematureSentryEvents.push({
|
|
87
|
+
entryPoint: sendLogToSentry,
|
|
88
|
+
inputs: [
|
|
89
|
+
logInfo,
|
|
90
|
+
eventDetails,
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const scopeContext = convertEventDetailsToSentryContext(eventDetails);
|
|
96
|
+
const eventId = isRuntimeTypeOf(logInfo, 'string')
|
|
97
|
+
? sentryClientForLogging.captureMessage(logInfo, scopeContext)
|
|
98
|
+
: sentryClientForLogging.captureEvent({
|
|
99
|
+
...logInfo,
|
|
100
|
+
...scopeContext,
|
|
101
|
+
});
|
|
102
|
+
return eventId;
|
|
103
|
+
}
|
|
104
|
+
catch (caught) {
|
|
105
|
+
console.error('error while trying to send log:', caught);
|
|
81
106
|
return undefined;
|
|
82
107
|
}
|
|
83
|
-
const scopeContext = convertEventDetailsToSentryContext(eventDetails);
|
|
84
|
-
const eventId = isRuntimeTypeOf(logInfo, 'string')
|
|
85
|
-
? sentryClientForLogging.captureMessage(logInfo, scopeContext)
|
|
86
|
-
: sentryClientForLogging.captureEvent({
|
|
87
|
-
...logInfo,
|
|
88
|
-
...scopeContext,
|
|
89
|
-
});
|
|
90
|
-
return eventId;
|
|
91
108
|
}
|
|
@@ -5,7 +5,7 @@ import { EventDetails, EventExtraContext } from '../event-context/event-context'
|
|
|
5
5
|
/** The bare minimum Sentry client needed for logging events. */
|
|
6
6
|
export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent'>;
|
|
7
7
|
/** An event that was triggered before setSentryClientForLogging was called. */
|
|
8
|
-
export type PrematureEvent<EntryPointFunction extends AnyFunction> = {
|
|
8
|
+
export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
|
|
9
9
|
entryPoint: EntryPointFunction;
|
|
10
10
|
inputs: Parameters<EntryPointFunction>;
|
|
11
11
|
};
|
|
@@ -13,7 +13,7 @@ export type PrematureEvent<EntryPointFunction extends AnyFunction> = {
|
|
|
13
13
|
* Used to store events before the Sentry client is setup. This is exported for testing purposes
|
|
14
14
|
* only, you don't need to do anything with this.
|
|
15
15
|
*/
|
|
16
|
-
export declare const prematureSentryEvents: PrematureEvent
|
|
16
|
+
export declare const prematureSentryEvents: PrematureEvent[];
|
|
17
17
|
/**
|
|
18
18
|
* Asynchronously set the Sentry client for logging. When this is called, any events that were
|
|
19
19
|
* triggered beforehand are handled. Thus, this set can be done at any time, allowing for
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentry-vir",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"config",
|
|
6
6
|
"helper",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"test:types": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@augment-vir/common": "^19.4.
|
|
40
|
+
"@augment-vir/common": "^19.4.2",
|
|
41
41
|
"@sentry/browser": "^7.73.0",
|
|
42
42
|
"@sentry/node": "^7.73.0",
|
|
43
43
|
"type-fest": "^4.3.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/browser-testing": "^19.4.
|
|
46
|
+
"@augment-vir/browser-testing": "^19.4.2",
|
|
47
47
|
"@open-wc/testing": "^3.2.0",
|
|
48
48
|
"@types/mocha": "^10.0.2",
|
|
49
49
|
"@web/dev-server-esbuild": "^0.4.1",
|