@temps-sdk/node-sdk 0.0.1-alpha.4 → 0.0.1-alpha.6
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/dist/client/client/client.gen.d.ts +0 -1
- package/dist/client/client/index.d.ts +0 -1
- package/dist/client/client/types.gen.d.ts +0 -1
- package/dist/client/client/utils.gen.d.ts +0 -1
- package/dist/client/client.gen.d.ts +0 -1
- package/dist/client/client.gen.js +3 -1
- package/dist/client/core/auth.gen.d.ts +0 -1
- package/dist/client/core/bodySerializer.gen.d.ts +0 -1
- package/dist/client/core/params.gen.d.ts +0 -1
- package/dist/client/core/pathSerializer.gen.d.ts +0 -1
- package/dist/client/core/serverSentEvents.gen.d.ts +0 -1
- package/dist/client/core/types.gen.d.ts +0 -1
- package/dist/client/core/utils.gen.d.ts +0 -1
- package/dist/client/index.d.ts +0 -1
- package/dist/client/sdk.gen.d.ts +800 -241
- package/dist/client/sdk.gen.js +2537 -1267
- package/dist/client/types.gen.d.ts +11607 -5153
- package/dist/errors/client.d.ts +46 -0
- package/dist/errors/client.js +261 -0
- package/dist/errors/hub.d.ts +22 -0
- package/dist/errors/hub.js +102 -0
- package/dist/errors/index.d.ts +35 -0
- package/dist/errors/index.js +167 -0
- package/dist/errors/scope.d.ts +23 -0
- package/dist/errors/scope.js +82 -0
- package/dist/errors/stacktrace.d.ts +5 -0
- package/dist/errors/stacktrace.js +113 -0
- package/dist/errors/transaction.d.ts +57 -0
- package/dist/errors/transaction.js +163 -0
- package/dist/errors/transport.d.ts +23 -0
- package/dist/errors/transport.js +72 -0
- package/dist/errors/types.d.ts +200 -0
- package/dist/errors/types.js +1 -0
- package/dist/index.d.ts +1727 -798
- package/dist/index.js +371 -280
- package/package.json +6 -4
- package/dist/client/client/client.gen.d.ts.map +0 -1
- package/dist/client/client/index.d.ts.map +0 -1
- package/dist/client/client/types.gen.d.ts.map +0 -1
- package/dist/client/client/utils.gen.d.ts.map +0 -1
- package/dist/client/client.gen.d.ts.map +0 -1
- package/dist/client/core/auth.gen.d.ts.map +0 -1
- package/dist/client/core/bodySerializer.gen.d.ts.map +0 -1
- package/dist/client/core/params.gen.d.ts.map +0 -1
- package/dist/client/core/pathSerializer.gen.d.ts.map +0 -1
- package/dist/client/core/serverSentEvents.gen.d.ts.map +0 -1
- package/dist/client/core/types.gen.d.ts.map +0 -1
- package/dist/client/core/utils.gen.d.ts.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/sdk.gen.d.ts.map +0 -1
- package/dist/client/types.gen.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ErrorTrackingOptions, Event, Breadcrumb, User, CaptureContext, Transaction, TransactionContext, Span, SpanContext } from './types.js';
|
|
2
|
+
import { Scope } from './scope.js';
|
|
3
|
+
export declare class ErrorTrackingClient {
|
|
4
|
+
private options;
|
|
5
|
+
private hub;
|
|
6
|
+
private transport;
|
|
7
|
+
private enabled;
|
|
8
|
+
private currentTransaction;
|
|
9
|
+
private lastEventId;
|
|
10
|
+
constructor(options: ErrorTrackingOptions);
|
|
11
|
+
private setupIntegrations;
|
|
12
|
+
private setupGlobalHandlers;
|
|
13
|
+
captureException(error: unknown, captureContext?: CaptureContext): string;
|
|
14
|
+
captureMessage(message: string, level?: Event['level'], captureContext?: CaptureContext): string;
|
|
15
|
+
captureEvent(event: Event, captureContext?: CaptureContext): string;
|
|
16
|
+
private createEventFromException;
|
|
17
|
+
private processAndSendEvent;
|
|
18
|
+
private shouldIgnoreError;
|
|
19
|
+
private generateEventId;
|
|
20
|
+
setUser(user: User | null): void;
|
|
21
|
+
setTag(key: string, value: string): void;
|
|
22
|
+
setTags(tags: Record<string, string>): void;
|
|
23
|
+
setExtra(key: string, value: any): void;
|
|
24
|
+
setExtras(extras: Record<string, any>): void;
|
|
25
|
+
setContext(key: string, context: Record<string, any> | null): void;
|
|
26
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
27
|
+
clearBreadcrumbs(): void;
|
|
28
|
+
configureScope(callback: (scope: Scope) => void): void;
|
|
29
|
+
withScope(callback: (scope: Scope) => void): void;
|
|
30
|
+
setEnabled(enabled: boolean): void;
|
|
31
|
+
flush(timeout?: number): Promise<boolean>;
|
|
32
|
+
close(timeout?: number): Promise<boolean>;
|
|
33
|
+
startTransaction(context: TransactionContext): Transaction;
|
|
34
|
+
getCurrentTransaction(): Transaction | null;
|
|
35
|
+
getLastEventId(): string | null;
|
|
36
|
+
setLevel(level: Event['level']): void;
|
|
37
|
+
startSpan(spanContext: SpanContext): Span | undefined;
|
|
38
|
+
captureUserFeedback(feedback: {
|
|
39
|
+
event_id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
email: string;
|
|
42
|
+
comments: string;
|
|
43
|
+
}): void;
|
|
44
|
+
isEnabled(): boolean;
|
|
45
|
+
getOptions(): ErrorTrackingOptions;
|
|
46
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { Hub } from './hub.js';
|
|
2
|
+
import { createTransportFromDsn } from './transport.js';
|
|
3
|
+
import { exceptionFromError, extractErrorMessage, isError } from './stacktrace.js';
|
|
4
|
+
import { TransactionImpl } from './transaction.js';
|
|
5
|
+
export class ErrorTrackingClient {
|
|
6
|
+
options;
|
|
7
|
+
hub;
|
|
8
|
+
transport;
|
|
9
|
+
enabled = true;
|
|
10
|
+
currentTransaction = null;
|
|
11
|
+
lastEventId = null;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = {
|
|
14
|
+
environment: 'production',
|
|
15
|
+
sampleRate: 1.0,
|
|
16
|
+
maxBreadcrumbs: 100,
|
|
17
|
+
attachStacktrace: true,
|
|
18
|
+
debug: false,
|
|
19
|
+
...options,
|
|
20
|
+
};
|
|
21
|
+
this.hub = new Hub(this.options.maxBreadcrumbs);
|
|
22
|
+
this.transport = createTransportFromDsn(this.options.dsn, this.options.debug);
|
|
23
|
+
if (this.options.integrations) {
|
|
24
|
+
this.setupIntegrations();
|
|
25
|
+
}
|
|
26
|
+
this.setupGlobalHandlers();
|
|
27
|
+
}
|
|
28
|
+
setupIntegrations() {
|
|
29
|
+
if (this.options.integrations) {
|
|
30
|
+
for (const integration of this.options.integrations) {
|
|
31
|
+
integration.setupOnce();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
setupGlobalHandlers() {
|
|
36
|
+
if (typeof process !== 'undefined' && process.on) {
|
|
37
|
+
process.on('uncaughtException', (error) => {
|
|
38
|
+
this.captureException(error, {
|
|
39
|
+
level: 'fatal',
|
|
40
|
+
tags: { handled: 'false' },
|
|
41
|
+
});
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
|
44
|
+
process.on('unhandledRejection', (reason) => {
|
|
45
|
+
this.captureException(reason instanceof Error ? reason : new Error(String(reason)), {
|
|
46
|
+
level: 'error',
|
|
47
|
+
tags: { handled: 'false', type: 'unhandledRejection' },
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
captureException(error, captureContext) {
|
|
53
|
+
if (!this.enabled) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
if (this.shouldIgnoreError(error)) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const eventId = this.generateEventId();
|
|
60
|
+
const event = this.createEventFromException(error, eventId);
|
|
61
|
+
this.processAndSendEvent(event, captureContext);
|
|
62
|
+
this.lastEventId = eventId;
|
|
63
|
+
return eventId;
|
|
64
|
+
}
|
|
65
|
+
captureMessage(message, level = 'info', captureContext) {
|
|
66
|
+
if (!this.enabled) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
const eventId = this.generateEventId();
|
|
70
|
+
const event = {
|
|
71
|
+
event_id: eventId,
|
|
72
|
+
timestamp: Date.now(),
|
|
73
|
+
level,
|
|
74
|
+
message,
|
|
75
|
+
platform: 'node',
|
|
76
|
+
sdk: {
|
|
77
|
+
name: '@temps-sdk/node-sdk',
|
|
78
|
+
version: '1.0.0',
|
|
79
|
+
},
|
|
80
|
+
environment: this.options.environment,
|
|
81
|
+
release: this.options.release,
|
|
82
|
+
server_name: this.options.serverName,
|
|
83
|
+
};
|
|
84
|
+
this.processAndSendEvent(event, captureContext);
|
|
85
|
+
this.lastEventId = eventId;
|
|
86
|
+
return eventId;
|
|
87
|
+
}
|
|
88
|
+
captureEvent(event, captureContext) {
|
|
89
|
+
if (!this.enabled) {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
const eventId = event.event_id || this.generateEventId();
|
|
93
|
+
const enrichedEvent = {
|
|
94
|
+
...event,
|
|
95
|
+
event_id: eventId,
|
|
96
|
+
timestamp: event.timestamp || Date.now(),
|
|
97
|
+
platform: event.platform || 'node',
|
|
98
|
+
sdk: event.sdk || {
|
|
99
|
+
name: '@temps-sdk/node-sdk',
|
|
100
|
+
version: '1.0.0',
|
|
101
|
+
},
|
|
102
|
+
environment: event.environment || this.options.environment,
|
|
103
|
+
release: event.release || this.options.release,
|
|
104
|
+
server_name: event.server_name || this.options.serverName,
|
|
105
|
+
};
|
|
106
|
+
this.processAndSendEvent(enrichedEvent, captureContext);
|
|
107
|
+
this.lastEventId = eventId;
|
|
108
|
+
return eventId;
|
|
109
|
+
}
|
|
110
|
+
createEventFromException(error, eventId) {
|
|
111
|
+
const event = {
|
|
112
|
+
event_id: eventId,
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
level: 'error',
|
|
115
|
+
platform: 'node',
|
|
116
|
+
sdk: {
|
|
117
|
+
name: '@temps-sdk/node-sdk',
|
|
118
|
+
version: '1.0.0',
|
|
119
|
+
},
|
|
120
|
+
environment: this.options.environment,
|
|
121
|
+
release: this.options.release,
|
|
122
|
+
server_name: this.options.serverName,
|
|
123
|
+
};
|
|
124
|
+
if (isError(error)) {
|
|
125
|
+
event.exception = {
|
|
126
|
+
values: [exceptionFromError(error)],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
event.message = extractErrorMessage(error);
|
|
131
|
+
}
|
|
132
|
+
return event;
|
|
133
|
+
}
|
|
134
|
+
processAndSendEvent(event, captureContext) {
|
|
135
|
+
if (Math.random() > (this.options.sampleRate || 1)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let finalEvent = this.hub.applyToEvent(event, captureContext);
|
|
139
|
+
if (this.options.beforeSend) {
|
|
140
|
+
const processed = this.options.beforeSend(finalEvent);
|
|
141
|
+
if (processed === null) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
finalEvent = processed;
|
|
145
|
+
}
|
|
146
|
+
this.transport.sendEvent(finalEvent).catch(error => {
|
|
147
|
+
if (this.options.debug) {
|
|
148
|
+
console.error('Failed to send event:', error);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
shouldIgnoreError(error) {
|
|
153
|
+
if (!this.options.ignoreErrors || this.options.ignoreErrors.length === 0) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const message = extractErrorMessage(error);
|
|
157
|
+
return this.options.ignoreErrors.some(pattern => {
|
|
158
|
+
if (typeof pattern === 'string') {
|
|
159
|
+
return message.includes(pattern);
|
|
160
|
+
}
|
|
161
|
+
return pattern.test(message);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
generateEventId() {
|
|
165
|
+
return Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join('');
|
|
166
|
+
}
|
|
167
|
+
setUser(user) {
|
|
168
|
+
this.hub.setUser(user);
|
|
169
|
+
}
|
|
170
|
+
setTag(key, value) {
|
|
171
|
+
this.hub.setTag(key, value);
|
|
172
|
+
}
|
|
173
|
+
setTags(tags) {
|
|
174
|
+
this.hub.setTags(tags);
|
|
175
|
+
}
|
|
176
|
+
setExtra(key, value) {
|
|
177
|
+
this.hub.setExtra(key, value);
|
|
178
|
+
}
|
|
179
|
+
setExtras(extras) {
|
|
180
|
+
this.hub.setExtras(extras);
|
|
181
|
+
}
|
|
182
|
+
setContext(key, context) {
|
|
183
|
+
this.hub.setContext(key, context);
|
|
184
|
+
}
|
|
185
|
+
addBreadcrumb(breadcrumb) {
|
|
186
|
+
this.hub.addBreadcrumb(breadcrumb);
|
|
187
|
+
}
|
|
188
|
+
clearBreadcrumbs() {
|
|
189
|
+
this.hub.clearBreadcrumbs();
|
|
190
|
+
}
|
|
191
|
+
configureScope(callback) {
|
|
192
|
+
this.hub.configureScope(callback);
|
|
193
|
+
}
|
|
194
|
+
withScope(callback) {
|
|
195
|
+
this.hub.withScope(callback);
|
|
196
|
+
}
|
|
197
|
+
setEnabled(enabled) {
|
|
198
|
+
this.enabled = enabled;
|
|
199
|
+
}
|
|
200
|
+
flush(timeout = 2000) {
|
|
201
|
+
return new Promise(resolve => {
|
|
202
|
+
setTimeout(() => resolve(true), Math.min(timeout, 100));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
close(timeout = 2000) {
|
|
206
|
+
this.enabled = false;
|
|
207
|
+
return this.flush(timeout);
|
|
208
|
+
}
|
|
209
|
+
startTransaction(context) {
|
|
210
|
+
const transaction = new TransactionImpl(context, (finishedTransaction) => {
|
|
211
|
+
if (this.options.tracesSampleRate && Math.random() <= this.options.tracesSampleRate) {
|
|
212
|
+
const event = finishedTransaction.toEvent();
|
|
213
|
+
this.processAndSendEvent(event);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
this.currentTransaction = transaction;
|
|
217
|
+
return transaction;
|
|
218
|
+
}
|
|
219
|
+
getCurrentTransaction() {
|
|
220
|
+
return this.currentTransaction;
|
|
221
|
+
}
|
|
222
|
+
getLastEventId() {
|
|
223
|
+
return this.lastEventId;
|
|
224
|
+
}
|
|
225
|
+
setLevel(level) {
|
|
226
|
+
this.hub.setLevel(level);
|
|
227
|
+
}
|
|
228
|
+
startSpan(spanContext) {
|
|
229
|
+
if (!this.currentTransaction) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
return this.currentTransaction.startChild(spanContext);
|
|
233
|
+
}
|
|
234
|
+
captureUserFeedback(feedback) {
|
|
235
|
+
const event = {
|
|
236
|
+
event_id: this.generateEventId(),
|
|
237
|
+
timestamp: Date.now(),
|
|
238
|
+
type: 'default',
|
|
239
|
+
user: {
|
|
240
|
+
email: feedback.email,
|
|
241
|
+
username: feedback.name,
|
|
242
|
+
},
|
|
243
|
+
extra: {
|
|
244
|
+
feedback: {
|
|
245
|
+
event_id: feedback.event_id,
|
|
246
|
+
comments: feedback.comments,
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
tags: {
|
|
250
|
+
source: 'user_feedback',
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
this.processAndSendEvent(event);
|
|
254
|
+
}
|
|
255
|
+
isEnabled() {
|
|
256
|
+
return this.enabled;
|
|
257
|
+
}
|
|
258
|
+
getOptions() {
|
|
259
|
+
return { ...this.options };
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Breadcrumb, CaptureContext, Event, User } from './types.js';
|
|
2
|
+
import { Scope } from './scope.js';
|
|
3
|
+
export declare class Hub {
|
|
4
|
+
private scopes;
|
|
5
|
+
private globalScope;
|
|
6
|
+
constructor(maxBreadcrumbs?: number);
|
|
7
|
+
pushScope(): Scope;
|
|
8
|
+
popScope(): void;
|
|
9
|
+
withScope(callback: (scope: Scope) => void): void;
|
|
10
|
+
getScope(): Scope;
|
|
11
|
+
configureScope(callback: (scope: Scope) => void): void;
|
|
12
|
+
setUser(user: User | null): void;
|
|
13
|
+
setTag(key: string, value: string): void;
|
|
14
|
+
setTags(tags: Record<string, string>): void;
|
|
15
|
+
setExtra(key: string, value: any): void;
|
|
16
|
+
setExtras(extras: Record<string, any>): void;
|
|
17
|
+
setContext(key: string, context: Record<string, any> | null): void;
|
|
18
|
+
setLevel(level: Event['level']): void;
|
|
19
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
20
|
+
clearBreadcrumbs(): void;
|
|
21
|
+
applyToEvent(event: Event, captureContext?: CaptureContext): Event;
|
|
22
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Scope } from './scope.js';
|
|
2
|
+
export class Hub {
|
|
3
|
+
scopes = [];
|
|
4
|
+
globalScope;
|
|
5
|
+
constructor(maxBreadcrumbs = 100) {
|
|
6
|
+
this.globalScope = new Scope(maxBreadcrumbs);
|
|
7
|
+
this.scopes.push(this.globalScope);
|
|
8
|
+
}
|
|
9
|
+
pushScope() {
|
|
10
|
+
const scope = this.getScope().clone();
|
|
11
|
+
this.scopes.push(scope);
|
|
12
|
+
return scope;
|
|
13
|
+
}
|
|
14
|
+
popScope() {
|
|
15
|
+
if (this.scopes.length > 1) {
|
|
16
|
+
this.scopes.pop();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
withScope(callback) {
|
|
20
|
+
const scope = this.pushScope();
|
|
21
|
+
try {
|
|
22
|
+
callback(scope);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
this.popScope();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getScope() {
|
|
29
|
+
return this.scopes[this.scopes.length - 1];
|
|
30
|
+
}
|
|
31
|
+
configureScope(callback) {
|
|
32
|
+
const scope = this.getScope();
|
|
33
|
+
callback(scope);
|
|
34
|
+
}
|
|
35
|
+
setUser(user) {
|
|
36
|
+
this.getScope().setUser(user);
|
|
37
|
+
}
|
|
38
|
+
setTag(key, value) {
|
|
39
|
+
this.getScope().setTag(key, value);
|
|
40
|
+
}
|
|
41
|
+
setTags(tags) {
|
|
42
|
+
this.getScope().setTags(tags);
|
|
43
|
+
}
|
|
44
|
+
setExtra(key, value) {
|
|
45
|
+
this.getScope().setExtra(key, value);
|
|
46
|
+
}
|
|
47
|
+
setExtras(extras) {
|
|
48
|
+
this.getScope().setExtras(extras);
|
|
49
|
+
}
|
|
50
|
+
setContext(key, context) {
|
|
51
|
+
this.getScope().setContext(key, context);
|
|
52
|
+
}
|
|
53
|
+
setLevel(level) {
|
|
54
|
+
this.getScope().setLevel(level);
|
|
55
|
+
}
|
|
56
|
+
addBreadcrumb(breadcrumb) {
|
|
57
|
+
this.getScope().addBreadcrumb(breadcrumb);
|
|
58
|
+
}
|
|
59
|
+
clearBreadcrumbs() {
|
|
60
|
+
this.getScope().clearBreadcrumbs();
|
|
61
|
+
}
|
|
62
|
+
applyToEvent(event, captureContext) {
|
|
63
|
+
let finalEvent = event;
|
|
64
|
+
for (const scope of this.scopes) {
|
|
65
|
+
finalEvent = scope.applyToEvent(finalEvent);
|
|
66
|
+
}
|
|
67
|
+
if (captureContext) {
|
|
68
|
+
if (typeof captureContext === 'function') {
|
|
69
|
+
const tempScope = this.getScope().clone();
|
|
70
|
+
captureContext(tempScope);
|
|
71
|
+
finalEvent = tempScope.applyToEvent(finalEvent);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const tempScope = this.getScope().clone();
|
|
75
|
+
const contextScope = captureContext;
|
|
76
|
+
if (contextScope.user !== undefined) {
|
|
77
|
+
tempScope.setUser(contextScope.user);
|
|
78
|
+
}
|
|
79
|
+
if (contextScope.tags) {
|
|
80
|
+
tempScope.setTags(contextScope.tags);
|
|
81
|
+
}
|
|
82
|
+
if (contextScope.extra) {
|
|
83
|
+
tempScope.setExtras(contextScope.extra);
|
|
84
|
+
}
|
|
85
|
+
if (contextScope.contexts) {
|
|
86
|
+
Object.keys(contextScope.contexts).forEach(key => {
|
|
87
|
+
tempScope.setContext(key, contextScope.contexts[key]);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (contextScope.level) {
|
|
91
|
+
tempScope.setLevel(contextScope.level);
|
|
92
|
+
}
|
|
93
|
+
finalEvent = tempScope.applyToEvent(finalEvent);
|
|
94
|
+
// Override level directly if specified in captureContext
|
|
95
|
+
if (contextScope.level) {
|
|
96
|
+
finalEvent.level = contextScope.level;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return finalEvent;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ErrorTrackingClient } from './client.js';
|
|
2
|
+
import type { ErrorTrackingOptions, CaptureContext, User, Breadcrumb, TransactionContext, SpanContext, Transaction, Span } from './types.js';
|
|
3
|
+
export declare function init(options: ErrorTrackingOptions): void;
|
|
4
|
+
export declare function __resetForTesting(): void;
|
|
5
|
+
export declare function captureException(error: unknown, captureContext?: CaptureContext): string;
|
|
6
|
+
export declare function captureMessage(message: string, level?: 'debug' | 'info' | 'warning' | 'error' | 'fatal', captureContext?: CaptureContext): string;
|
|
7
|
+
export declare function captureEvent(event: any, captureContext?: CaptureContext): string;
|
|
8
|
+
export declare function setUser(user: User | null): void;
|
|
9
|
+
export declare function setTag(key: string, value: string): void;
|
|
10
|
+
export declare function setTags(tags: Record<string, string>): void;
|
|
11
|
+
export declare function setExtra(key: string, value: any): void;
|
|
12
|
+
export declare function setExtras(extras: Record<string, any>): void;
|
|
13
|
+
export declare function setContext(key: string, context: Record<string, any> | null): void;
|
|
14
|
+
export declare function addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
15
|
+
export declare function clearBreadcrumbs(): void;
|
|
16
|
+
export declare function configureScope(callback: (scope: any) => void): void;
|
|
17
|
+
export declare function withScope(callback: (scope: any) => void): void;
|
|
18
|
+
export declare function flush(timeout?: number): Promise<boolean>;
|
|
19
|
+
export declare function close(timeout?: number): Promise<boolean>;
|
|
20
|
+
export declare function getCurrentClient(): ErrorTrackingClient | null;
|
|
21
|
+
export declare function startTransaction(context: TransactionContext): Transaction;
|
|
22
|
+
export declare function getCurrentTransaction(): Transaction | null;
|
|
23
|
+
export declare function getLastEventId(): string | null;
|
|
24
|
+
export declare function setLevel(level: 'debug' | 'info' | 'warning' | 'error' | 'fatal'): void;
|
|
25
|
+
export declare function startSpan(spanContext: SpanContext): Span | undefined;
|
|
26
|
+
export declare function captureUserFeedback(feedback: {
|
|
27
|
+
event_id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
email: string;
|
|
30
|
+
comments: string;
|
|
31
|
+
}): void;
|
|
32
|
+
export declare function isEnabled(): boolean;
|
|
33
|
+
export { ErrorTrackingClient } from './client.js';
|
|
34
|
+
export { Scope } from './scope.js';
|
|
35
|
+
export * from './types.js';
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ErrorTrackingClient } from './client.js';
|
|
2
|
+
let globalClient = null;
|
|
3
|
+
export function init(options) {
|
|
4
|
+
globalClient = new ErrorTrackingClient(options);
|
|
5
|
+
}
|
|
6
|
+
// For testing purposes only - not part of public API
|
|
7
|
+
export function __resetForTesting() {
|
|
8
|
+
globalClient = null;
|
|
9
|
+
}
|
|
10
|
+
export function captureException(error, captureContext) {
|
|
11
|
+
if (!globalClient) {
|
|
12
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
return globalClient.captureException(error, captureContext);
|
|
16
|
+
}
|
|
17
|
+
export function captureMessage(message, level, captureContext) {
|
|
18
|
+
if (!globalClient) {
|
|
19
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
return globalClient.captureMessage(message, level, captureContext);
|
|
23
|
+
}
|
|
24
|
+
export function captureEvent(event, captureContext) {
|
|
25
|
+
if (!globalClient) {
|
|
26
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
return globalClient.captureEvent(event, captureContext);
|
|
30
|
+
}
|
|
31
|
+
export function setUser(user) {
|
|
32
|
+
if (!globalClient) {
|
|
33
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
globalClient.setUser(user);
|
|
37
|
+
}
|
|
38
|
+
export function setTag(key, value) {
|
|
39
|
+
if (!globalClient) {
|
|
40
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
globalClient.setTag(key, value);
|
|
44
|
+
}
|
|
45
|
+
export function setTags(tags) {
|
|
46
|
+
if (!globalClient) {
|
|
47
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
globalClient.setTags(tags);
|
|
51
|
+
}
|
|
52
|
+
export function setExtra(key, value) {
|
|
53
|
+
if (!globalClient) {
|
|
54
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
globalClient.setExtra(key, value);
|
|
58
|
+
}
|
|
59
|
+
export function setExtras(extras) {
|
|
60
|
+
if (!globalClient) {
|
|
61
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
globalClient.setExtras(extras);
|
|
65
|
+
}
|
|
66
|
+
export function setContext(key, context) {
|
|
67
|
+
if (!globalClient) {
|
|
68
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
globalClient.setContext(key, context);
|
|
72
|
+
}
|
|
73
|
+
export function addBreadcrumb(breadcrumb) {
|
|
74
|
+
if (!globalClient) {
|
|
75
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
globalClient.addBreadcrumb(breadcrumb);
|
|
79
|
+
}
|
|
80
|
+
export function clearBreadcrumbs() {
|
|
81
|
+
if (!globalClient) {
|
|
82
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
globalClient.clearBreadcrumbs();
|
|
86
|
+
}
|
|
87
|
+
export function configureScope(callback) {
|
|
88
|
+
if (!globalClient) {
|
|
89
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
globalClient.configureScope(callback);
|
|
93
|
+
}
|
|
94
|
+
export function withScope(callback) {
|
|
95
|
+
if (!globalClient) {
|
|
96
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
globalClient.withScope(callback);
|
|
100
|
+
}
|
|
101
|
+
export function flush(timeout) {
|
|
102
|
+
if (!globalClient) {
|
|
103
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
104
|
+
return Promise.resolve(false);
|
|
105
|
+
}
|
|
106
|
+
return globalClient.flush(timeout);
|
|
107
|
+
}
|
|
108
|
+
export function close(timeout) {
|
|
109
|
+
if (!globalClient) {
|
|
110
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
111
|
+
return Promise.resolve(false);
|
|
112
|
+
}
|
|
113
|
+
return globalClient.close(timeout);
|
|
114
|
+
}
|
|
115
|
+
export function getCurrentClient() {
|
|
116
|
+
return globalClient;
|
|
117
|
+
}
|
|
118
|
+
export function startTransaction(context) {
|
|
119
|
+
if (!globalClient) {
|
|
120
|
+
throw new Error('Error tracking client not initialized. Call init() first.');
|
|
121
|
+
}
|
|
122
|
+
return globalClient.startTransaction(context);
|
|
123
|
+
}
|
|
124
|
+
export function getCurrentTransaction() {
|
|
125
|
+
if (!globalClient) {
|
|
126
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return globalClient.getCurrentTransaction();
|
|
130
|
+
}
|
|
131
|
+
export function getLastEventId() {
|
|
132
|
+
if (!globalClient) {
|
|
133
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return globalClient.getLastEventId();
|
|
137
|
+
}
|
|
138
|
+
export function setLevel(level) {
|
|
139
|
+
if (!globalClient) {
|
|
140
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
globalClient.setLevel(level);
|
|
144
|
+
}
|
|
145
|
+
export function startSpan(spanContext) {
|
|
146
|
+
if (!globalClient) {
|
|
147
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
return globalClient.startSpan(spanContext);
|
|
151
|
+
}
|
|
152
|
+
export function captureUserFeedback(feedback) {
|
|
153
|
+
if (!globalClient) {
|
|
154
|
+
console.warn('Error tracking client not initialized. Call init() first.');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
globalClient.captureUserFeedback(feedback);
|
|
158
|
+
}
|
|
159
|
+
export function isEnabled() {
|
|
160
|
+
if (!globalClient) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return globalClient.isEnabled();
|
|
164
|
+
}
|
|
165
|
+
export { ErrorTrackingClient } from './client.js';
|
|
166
|
+
export { Scope } from './scope.js';
|
|
167
|
+
export * from './types.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Breadcrumb, Event, Scope as IScope, User } from './types.js';
|
|
2
|
+
export declare class Scope implements IScope {
|
|
3
|
+
private user;
|
|
4
|
+
private tags;
|
|
5
|
+
private extra;
|
|
6
|
+
private contexts;
|
|
7
|
+
private level;
|
|
8
|
+
private breadcrumbs;
|
|
9
|
+
private maxBreadcrumbs;
|
|
10
|
+
constructor(maxBreadcrumbs?: number);
|
|
11
|
+
setUser(user: User | null): void;
|
|
12
|
+
setTag(key: string, value: string): void;
|
|
13
|
+
setTags(tags: Record<string, string>): void;
|
|
14
|
+
setExtra(key: string, value: any): void;
|
|
15
|
+
setExtras(extras: Record<string, any>): void;
|
|
16
|
+
setContext(key: string, context: Record<string, any> | null): void;
|
|
17
|
+
setLevel(level: Event['level']): void;
|
|
18
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
19
|
+
clearBreadcrumbs(): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
applyToEvent(event: Event): Event;
|
|
22
|
+
clone(): Scope;
|
|
23
|
+
}
|