@bugwatch/core 0.1.0 → 0.2.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/dist/index.d.mts +236 -9
- package/dist/index.d.ts +236 -9
- package/dist/index.js +391 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +376 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,12 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
+
}) : x)(function(x) {
|
|
8
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
5
11
|
var __esm = (fn, res) => function __init() {
|
|
6
12
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
13
|
};
|
|
@@ -43,7 +49,7 @@ var init_transport = __esm({
|
|
|
43
49
|
method: "POST",
|
|
44
50
|
headers: {
|
|
45
51
|
"Content-Type": "application/json",
|
|
46
|
-
"
|
|
52
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
47
53
|
"X-Bugwatch-SDK": event.sdk?.name || "bugwatch-core",
|
|
48
54
|
"X-Bugwatch-SDK-Version": event.sdk?.version || "0.1.0"
|
|
49
55
|
},
|
|
@@ -132,6 +138,13 @@ var init_transport = __esm({
|
|
|
132
138
|
this.timer = null;
|
|
133
139
|
}
|
|
134
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Close the transport, flushing any remaining events and stopping the timer.
|
|
143
|
+
*/
|
|
144
|
+
async close() {
|
|
145
|
+
await this.flush();
|
|
146
|
+
this.destroy();
|
|
147
|
+
}
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
});
|
|
@@ -280,6 +293,126 @@ var init_fingerprint = __esm({
|
|
|
280
293
|
}
|
|
281
294
|
});
|
|
282
295
|
|
|
296
|
+
// src/context.ts
|
|
297
|
+
var context_exports = {};
|
|
298
|
+
__export(context_exports, {
|
|
299
|
+
addRequestBreadcrumb: () => addRequestBreadcrumb,
|
|
300
|
+
createScopedContext: () => createScopedContext,
|
|
301
|
+
getMergedContext: () => getMergedContext,
|
|
302
|
+
getRequestContext: () => getRequestContext,
|
|
303
|
+
hasRequestContext: () => hasRequestContext,
|
|
304
|
+
runWithContext: () => runWithContext,
|
|
305
|
+
runWithContextAsync: () => runWithContextAsync,
|
|
306
|
+
setRequestExtra: () => setRequestExtra,
|
|
307
|
+
setRequestTag: () => setRequestTag,
|
|
308
|
+
setRequestUser: () => setRequestUser
|
|
309
|
+
});
|
|
310
|
+
function createScopedContext() {
|
|
311
|
+
return {
|
|
312
|
+
user: null,
|
|
313
|
+
tags: {},
|
|
314
|
+
extra: {},
|
|
315
|
+
breadcrumbs: []
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function isNodeEnvironment() {
|
|
319
|
+
return typeof process !== "undefined" && process.versions?.node !== void 0 && typeof __require !== "undefined";
|
|
320
|
+
}
|
|
321
|
+
function getAsyncLocalStorage() {
|
|
322
|
+
if (asyncLocalStorage) {
|
|
323
|
+
return asyncLocalStorage;
|
|
324
|
+
}
|
|
325
|
+
if (!isNodeEnvironment()) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
const asyncHooks = __require("async_hooks");
|
|
330
|
+
asyncLocalStorage = new asyncHooks.AsyncLocalStorage();
|
|
331
|
+
return asyncLocalStorage;
|
|
332
|
+
} catch {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function runWithContext(context, fn) {
|
|
337
|
+
const storage = getAsyncLocalStorage();
|
|
338
|
+
if (storage) {
|
|
339
|
+
return storage.run(context, fn);
|
|
340
|
+
}
|
|
341
|
+
return fn();
|
|
342
|
+
}
|
|
343
|
+
async function runWithContextAsync(context, fn) {
|
|
344
|
+
const storage = getAsyncLocalStorage();
|
|
345
|
+
if (storage) {
|
|
346
|
+
return storage.run(context, fn);
|
|
347
|
+
}
|
|
348
|
+
return fn();
|
|
349
|
+
}
|
|
350
|
+
function getRequestContext() {
|
|
351
|
+
const storage = getAsyncLocalStorage();
|
|
352
|
+
return storage?.getStore();
|
|
353
|
+
}
|
|
354
|
+
function hasRequestContext() {
|
|
355
|
+
return getRequestContext() !== void 0;
|
|
356
|
+
}
|
|
357
|
+
function setRequestUser(user) {
|
|
358
|
+
const ctx = getRequestContext();
|
|
359
|
+
if (ctx) {
|
|
360
|
+
ctx.user = user;
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
function setRequestTag(key, value) {
|
|
366
|
+
const ctx = getRequestContext();
|
|
367
|
+
if (ctx) {
|
|
368
|
+
ctx.tags[key] = value;
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
function setRequestExtra(key, value) {
|
|
374
|
+
const ctx = getRequestContext();
|
|
375
|
+
if (ctx) {
|
|
376
|
+
ctx.extra[key] = value;
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
function addRequestBreadcrumb(breadcrumb, maxBreadcrumbs = 100) {
|
|
382
|
+
const ctx = getRequestContext();
|
|
383
|
+
if (ctx) {
|
|
384
|
+
ctx.breadcrumbs.push(breadcrumb);
|
|
385
|
+
if (ctx.breadcrumbs.length > maxBreadcrumbs) {
|
|
386
|
+
ctx.breadcrumbs = ctx.breadcrumbs.slice(-maxBreadcrumbs);
|
|
387
|
+
}
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
function getMergedContext(globalUser, globalTags, globalExtra, globalBreadcrumbs) {
|
|
393
|
+
const reqCtx = getRequestContext();
|
|
394
|
+
if (!reqCtx) {
|
|
395
|
+
return {
|
|
396
|
+
user: globalUser,
|
|
397
|
+
tags: globalTags,
|
|
398
|
+
extra: globalExtra,
|
|
399
|
+
breadcrumbs: globalBreadcrumbs
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
user: reqCtx.user || globalUser,
|
|
404
|
+
tags: { ...globalTags, ...reqCtx.tags },
|
|
405
|
+
extra: { ...globalExtra, ...reqCtx.extra },
|
|
406
|
+
breadcrumbs: [...globalBreadcrumbs, ...reqCtx.breadcrumbs]
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
var asyncLocalStorage;
|
|
410
|
+
var init_context = __esm({
|
|
411
|
+
"src/context.ts"() {
|
|
412
|
+
asyncLocalStorage = null;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
283
416
|
// src/client.ts
|
|
284
417
|
var client_exports = {};
|
|
285
418
|
__export(client_exports, {
|
|
@@ -290,12 +423,52 @@ function generateEventId() {
|
|
|
290
423
|
const random = Math.random().toString(36).substring(2, 10);
|
|
291
424
|
return `${timestamp}${random}`;
|
|
292
425
|
}
|
|
293
|
-
var SDK_NAME, SDK_VERSION, DEFAULT_OPTIONS, Bugwatch;
|
|
426
|
+
var RingBuffer, SDK_NAME, SDK_VERSION, DEFAULT_OPTIONS, Bugwatch;
|
|
294
427
|
var init_client = __esm({
|
|
295
428
|
"src/client.ts"() {
|
|
296
429
|
init_transport();
|
|
297
430
|
init_stacktrace();
|
|
298
431
|
init_fingerprint();
|
|
432
|
+
init_context();
|
|
433
|
+
RingBuffer = class {
|
|
434
|
+
constructor(maxSize) {
|
|
435
|
+
this.maxSize = maxSize;
|
|
436
|
+
this.buffer = new Array(maxSize);
|
|
437
|
+
}
|
|
438
|
+
buffer;
|
|
439
|
+
head = 0;
|
|
440
|
+
count = 0;
|
|
441
|
+
push(item) {
|
|
442
|
+
this.buffer[this.head] = item;
|
|
443
|
+
this.head = (this.head + 1) % this.maxSize;
|
|
444
|
+
if (this.count < this.maxSize) {
|
|
445
|
+
this.count++;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
toArray() {
|
|
449
|
+
if (this.count === 0) {
|
|
450
|
+
return [];
|
|
451
|
+
}
|
|
452
|
+
const result = [];
|
|
453
|
+
const start = this.count < this.maxSize ? 0 : this.head;
|
|
454
|
+
for (let i = 0; i < this.count; i++) {
|
|
455
|
+
const index = (start + i) % this.maxSize;
|
|
456
|
+
const item = this.buffer[index];
|
|
457
|
+
if (item !== void 0) {
|
|
458
|
+
result.push(item);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
clear() {
|
|
464
|
+
this.buffer = new Array(this.maxSize);
|
|
465
|
+
this.head = 0;
|
|
466
|
+
this.count = 0;
|
|
467
|
+
}
|
|
468
|
+
get length() {
|
|
469
|
+
return this.count;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
299
472
|
SDK_NAME = "@bugwatch/core";
|
|
300
473
|
SDK_VERSION = "0.1.0";
|
|
301
474
|
DEFAULT_OPTIONS = {
|
|
@@ -308,7 +481,7 @@ var init_client = __esm({
|
|
|
308
481
|
Bugwatch = class {
|
|
309
482
|
options;
|
|
310
483
|
transport;
|
|
311
|
-
breadcrumbs
|
|
484
|
+
breadcrumbs;
|
|
312
485
|
tags = {};
|
|
313
486
|
extra = {};
|
|
314
487
|
user = null;
|
|
@@ -317,6 +490,7 @@ var init_client = __esm({
|
|
|
317
490
|
constructor(options) {
|
|
318
491
|
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
319
492
|
this.transport = this.createTransport();
|
|
493
|
+
this.breadcrumbs = new RingBuffer(this.options.maxBreadcrumbs || 100);
|
|
320
494
|
if (options.tags) {
|
|
321
495
|
this.tags = { ...options.tags };
|
|
322
496
|
}
|
|
@@ -362,7 +536,17 @@ var init_client = __esm({
|
|
|
362
536
|
return "";
|
|
363
537
|
}
|
|
364
538
|
const event = this.createEventFromError(error, context);
|
|
365
|
-
|
|
539
|
+
let processedEvent = event;
|
|
540
|
+
if (this.options.beforeSend) {
|
|
541
|
+
try {
|
|
542
|
+
processedEvent = this.options.beforeSend(event);
|
|
543
|
+
} catch (err) {
|
|
544
|
+
if (this.options.debug) {
|
|
545
|
+
console.error("[Bugwatch] beforeSend threw an error:", err);
|
|
546
|
+
}
|
|
547
|
+
processedEvent = event;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
366
550
|
if (!processedEvent) {
|
|
367
551
|
if (this.options.debug) {
|
|
368
552
|
console.log("[Bugwatch] Event dropped by beforeSend");
|
|
@@ -384,7 +568,17 @@ var init_client = __esm({
|
|
|
384
568
|
message,
|
|
385
569
|
level
|
|
386
570
|
});
|
|
387
|
-
|
|
571
|
+
let processedEvent = event;
|
|
572
|
+
if (this.options.beforeSend) {
|
|
573
|
+
try {
|
|
574
|
+
processedEvent = this.options.beforeSend(event);
|
|
575
|
+
} catch (err) {
|
|
576
|
+
if (this.options.debug) {
|
|
577
|
+
console.error("[Bugwatch] beforeSend threw an error:", err);
|
|
578
|
+
}
|
|
579
|
+
processedEvent = event;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
388
582
|
if (!processedEvent) {
|
|
389
583
|
return "";
|
|
390
584
|
}
|
|
@@ -401,10 +595,6 @@ var init_client = __esm({
|
|
|
401
595
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
402
596
|
};
|
|
403
597
|
this.breadcrumbs.push(crumb);
|
|
404
|
-
const max = this.options.maxBreadcrumbs || 100;
|
|
405
|
-
if (this.breadcrumbs.length > max) {
|
|
406
|
-
this.breadcrumbs = this.breadcrumbs.slice(-max);
|
|
407
|
-
}
|
|
408
598
|
}
|
|
409
599
|
/**
|
|
410
600
|
* Set user context
|
|
@@ -428,7 +618,7 @@ var init_client = __esm({
|
|
|
428
618
|
* Clear breadcrumbs
|
|
429
619
|
*/
|
|
430
620
|
clearBreadcrumbs() {
|
|
431
|
-
this.breadcrumbs
|
|
621
|
+
this.breadcrumbs.clear();
|
|
432
622
|
}
|
|
433
623
|
/**
|
|
434
624
|
* Create an event from an Error object
|
|
@@ -452,6 +642,12 @@ var init_client = __esm({
|
|
|
452
642
|
* Create a base event
|
|
453
643
|
*/
|
|
454
644
|
createEvent(partial) {
|
|
645
|
+
const mergedContext = getMergedContext(
|
|
646
|
+
this.user,
|
|
647
|
+
this.tags,
|
|
648
|
+
this.extra,
|
|
649
|
+
this.breadcrumbs.toArray()
|
|
650
|
+
);
|
|
455
651
|
const event = {
|
|
456
652
|
event_id: generateEventId(),
|
|
457
653
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -460,17 +656,17 @@ var init_client = __esm({
|
|
|
460
656
|
message: partial.message || "",
|
|
461
657
|
environment: this.options.environment,
|
|
462
658
|
release: this.options.release,
|
|
463
|
-
tags: { ...
|
|
464
|
-
extra: { ...
|
|
465
|
-
breadcrumbs:
|
|
659
|
+
tags: { ...mergedContext.tags, ...partial.tags },
|
|
660
|
+
extra: { ...mergedContext.extra, ...partial.extra },
|
|
661
|
+
breadcrumbs: mergedContext.breadcrumbs,
|
|
466
662
|
sdk: {
|
|
467
663
|
name: SDK_NAME,
|
|
468
664
|
version: SDK_VERSION
|
|
469
665
|
},
|
|
470
666
|
...partial
|
|
471
667
|
};
|
|
472
|
-
if (
|
|
473
|
-
event.user = { ...
|
|
668
|
+
if (mergedContext.user || partial.user) {
|
|
669
|
+
event.user = { ...mergedContext.user, ...partial.user };
|
|
474
670
|
}
|
|
475
671
|
if (event.exception) {
|
|
476
672
|
const fingerprint = fingerprintFromException(event.exception);
|
|
@@ -514,6 +710,95 @@ var init_client = __esm({
|
|
|
514
710
|
}
|
|
515
711
|
return "javascript";
|
|
516
712
|
}
|
|
713
|
+
/**
|
|
714
|
+
* Flush any pending events.
|
|
715
|
+
* Call this before process exit to ensure no events are lost.
|
|
716
|
+
*/
|
|
717
|
+
async flush() {
|
|
718
|
+
if (this.transport.flush) {
|
|
719
|
+
await this.transport.flush();
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Close the client and release any resources.
|
|
724
|
+
* This flushes any pending events and closes the transport.
|
|
725
|
+
* After calling this method, the client should not be used again.
|
|
726
|
+
*/
|
|
727
|
+
async close() {
|
|
728
|
+
if (this.transport.close) {
|
|
729
|
+
await this.transport.close();
|
|
730
|
+
} else {
|
|
731
|
+
await this.flush();
|
|
732
|
+
}
|
|
733
|
+
this.initialized = false;
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// src/env.ts
|
|
740
|
+
var env_exports = {};
|
|
741
|
+
__export(env_exports, {
|
|
742
|
+
ENV_VARS: () => ENV_VARS,
|
|
743
|
+
getEnvConfig: () => getEnvConfig,
|
|
744
|
+
hasApiKey: () => hasApiKey,
|
|
745
|
+
validateApiKey: () => validateApiKey
|
|
746
|
+
});
|
|
747
|
+
function getEnvVar(name) {
|
|
748
|
+
if (typeof process !== "undefined" && process.env) {
|
|
749
|
+
return process.env[name];
|
|
750
|
+
}
|
|
751
|
+
return void 0;
|
|
752
|
+
}
|
|
753
|
+
function getEnvConfig() {
|
|
754
|
+
const config = {};
|
|
755
|
+
const apiKey = getEnvVar(ENV_VARS.API_KEY);
|
|
756
|
+
if (apiKey) {
|
|
757
|
+
config.apiKey = apiKey;
|
|
758
|
+
}
|
|
759
|
+
const environment = getEnvVar(ENV_VARS.ENVIRONMENT);
|
|
760
|
+
if (environment) {
|
|
761
|
+
config.environment = environment;
|
|
762
|
+
}
|
|
763
|
+
const release = getEnvVar(ENV_VARS.RELEASE);
|
|
764
|
+
if (release) {
|
|
765
|
+
config.release = release;
|
|
766
|
+
}
|
|
767
|
+
const debug = getEnvVar(ENV_VARS.DEBUG);
|
|
768
|
+
if (debug === "true") {
|
|
769
|
+
config.debug = true;
|
|
770
|
+
}
|
|
771
|
+
const endpoint = getEnvVar(ENV_VARS.ENDPOINT);
|
|
772
|
+
if (endpoint) {
|
|
773
|
+
config.endpoint = endpoint;
|
|
774
|
+
}
|
|
775
|
+
return config;
|
|
776
|
+
}
|
|
777
|
+
function validateApiKey(key) {
|
|
778
|
+
if (!key) {
|
|
779
|
+
throw new Error(
|
|
780
|
+
"Bugwatch: API key required. Set BUGWATCH_API_KEY environment variable or pass { apiKey: '...' }"
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
if (!key.startsWith("bw_")) {
|
|
784
|
+
const preview = key.length > 10 ? `${key.slice(0, 6)}...` : "[hidden]";
|
|
785
|
+
console.warn(
|
|
786
|
+
`Bugwatch: API key should start with 'bw_'. Got '${preview}'`
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function hasApiKey(explicitKey) {
|
|
791
|
+
return Boolean(explicitKey || getEnvVar(ENV_VARS.API_KEY));
|
|
792
|
+
}
|
|
793
|
+
var ENV_VARS;
|
|
794
|
+
var init_env = __esm({
|
|
795
|
+
"src/env.ts"() {
|
|
796
|
+
ENV_VARS = {
|
|
797
|
+
API_KEY: "BUGWATCH_API_KEY",
|
|
798
|
+
ENVIRONMENT: "BUGWATCH_ENVIRONMENT",
|
|
799
|
+
RELEASE: "BUGWATCH_RELEASE",
|
|
800
|
+
DEBUG: "BUGWATCH_DEBUG",
|
|
801
|
+
ENDPOINT: "BUGWATCH_ENDPOINT"
|
|
517
802
|
};
|
|
518
803
|
}
|
|
519
804
|
});
|
|
@@ -523,26 +808,57 @@ init_client();
|
|
|
523
808
|
init_transport();
|
|
524
809
|
init_stacktrace();
|
|
525
810
|
init_fingerprint();
|
|
811
|
+
init_env();
|
|
812
|
+
init_context();
|
|
526
813
|
var globalClient = null;
|
|
814
|
+
var lazyInitWarned = false;
|
|
527
815
|
function init(options) {
|
|
528
816
|
const { Bugwatch: Bugwatch2 } = (init_client(), __toCommonJS(client_exports));
|
|
529
|
-
const
|
|
817
|
+
const { getEnvConfig: getEnvConfig2, validateApiKey: validateApiKey2 } = (init_env(), __toCommonJS(env_exports));
|
|
818
|
+
const envConfig = getEnvConfig2();
|
|
819
|
+
const mergedOptions = { ...envConfig, ...options };
|
|
820
|
+
validateApiKey2(mergedOptions.apiKey);
|
|
821
|
+
const client = new Bugwatch2(mergedOptions);
|
|
530
822
|
globalClient = client;
|
|
823
|
+
lazyInitWarned = false;
|
|
531
824
|
return client;
|
|
532
825
|
}
|
|
533
826
|
function getClient() {
|
|
534
827
|
return globalClient;
|
|
535
828
|
}
|
|
829
|
+
function tryLazyInit() {
|
|
830
|
+
if (globalClient) return true;
|
|
831
|
+
const { getEnvConfig: getEnvConfig2, hasApiKey: hasApiKey2 } = (init_env(), __toCommonJS(env_exports));
|
|
832
|
+
if (!hasApiKey2()) {
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
try {
|
|
836
|
+
const { Bugwatch: Bugwatch2 } = (init_client(), __toCommonJS(client_exports));
|
|
837
|
+
const envConfig = getEnvConfig2();
|
|
838
|
+
if (!envConfig.apiKey) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
const client = new Bugwatch2(envConfig);
|
|
842
|
+
globalClient = client;
|
|
843
|
+
if (envConfig.debug && !lazyInitWarned) {
|
|
844
|
+
console.warn("[Bugwatch] Auto-initialized from BUGWATCH_API_KEY environment variable");
|
|
845
|
+
lazyInitWarned = true;
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
848
|
+
} catch {
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
536
852
|
function captureException(error, context) {
|
|
537
|
-
if (!globalClient) {
|
|
538
|
-
console.warn("[Bugwatch] SDK not initialized. Call init() first.");
|
|
853
|
+
if (!globalClient && !tryLazyInit()) {
|
|
854
|
+
console.warn("[Bugwatch] SDK not initialized. Call init() first or set BUGWATCH_API_KEY environment variable.");
|
|
539
855
|
return "";
|
|
540
856
|
}
|
|
541
857
|
return globalClient.captureException(error, context);
|
|
542
858
|
}
|
|
543
859
|
function captureMessage(message, level) {
|
|
544
|
-
if (!globalClient) {
|
|
545
|
-
console.warn("[Bugwatch] SDK not initialized. Call init() first.");
|
|
860
|
+
if (!globalClient && !tryLazyInit()) {
|
|
861
|
+
console.warn("[Bugwatch] SDK not initialized. Call init() first or set BUGWATCH_API_KEY environment variable.");
|
|
546
862
|
return "";
|
|
547
863
|
}
|
|
548
864
|
return globalClient.captureMessage(message, level);
|
|
@@ -551,27 +867,66 @@ function addBreadcrumb(breadcrumb) {
|
|
|
551
867
|
if (!globalClient) {
|
|
552
868
|
return;
|
|
553
869
|
}
|
|
870
|
+
const { addRequestBreadcrumb: addRequestBreadcrumb2 } = (init_context(), __toCommonJS(context_exports));
|
|
871
|
+
const crumb = {
|
|
872
|
+
...breadcrumb,
|
|
873
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
874
|
+
};
|
|
875
|
+
if (addRequestBreadcrumb2(crumb, globalClient.getOptions().maxBreadcrumbs || 100)) {
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
554
878
|
globalClient.addBreadcrumb(breadcrumb);
|
|
555
879
|
}
|
|
556
880
|
function setUser(user) {
|
|
557
881
|
if (!globalClient) {
|
|
558
882
|
return;
|
|
559
883
|
}
|
|
884
|
+
const { setRequestUser: setRequestUser2 } = (init_context(), __toCommonJS(context_exports));
|
|
885
|
+
if (setRequestUser2(user)) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
560
888
|
globalClient.setUser(user);
|
|
561
889
|
}
|
|
562
890
|
function setTag(key, value) {
|
|
563
891
|
if (!globalClient) {
|
|
564
892
|
return;
|
|
565
893
|
}
|
|
894
|
+
const { setRequestTag: setRequestTag2 } = (init_context(), __toCommonJS(context_exports));
|
|
895
|
+
if (setRequestTag2(key, value)) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
566
898
|
globalClient.setTag(key, value);
|
|
567
899
|
}
|
|
568
900
|
function setExtra(key, value) {
|
|
569
901
|
if (!globalClient) {
|
|
570
902
|
return;
|
|
571
903
|
}
|
|
904
|
+
const { setRequestExtra: setRequestExtra2 } = (init_context(), __toCommonJS(context_exports));
|
|
905
|
+
if (setRequestExtra2(key, value)) {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
572
908
|
globalClient.setExtra(key, value);
|
|
573
909
|
}
|
|
910
|
+
async function flush() {
|
|
911
|
+
if (!globalClient) {
|
|
912
|
+
console.warn("[Bugwatch] SDK not initialized. Call init() first.");
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
await globalClient.flush();
|
|
916
|
+
}
|
|
917
|
+
async function close() {
|
|
918
|
+
if (!globalClient) {
|
|
919
|
+
console.warn("[Bugwatch] SDK not initialized. Call init() first.");
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
await globalClient.close();
|
|
923
|
+
globalClient = null;
|
|
924
|
+
}
|
|
925
|
+
function reset() {
|
|
926
|
+
globalClient = null;
|
|
927
|
+
lazyInitWarned = false;
|
|
928
|
+
}
|
|
574
929
|
|
|
575
|
-
export { BatchTransport, Bugwatch, ConsoleTransport, HttpTransport, NoopTransport, addBreadcrumb, captureException, captureMessage, extractErrorInfo, fingerprintFromException, generateFingerprint, getClient, init, parseStackTrace, setExtra, setTag, setUser };
|
|
930
|
+
export { BatchTransport, Bugwatch, ConsoleTransport, ENV_VARS, HttpTransport, NoopTransport, addBreadcrumb, addRequestBreadcrumb, captureException, captureMessage, close, createScopedContext, extractErrorInfo, fingerprintFromException, flush, generateFingerprint, getClient, getEnvConfig, getMergedContext, getRequestContext, hasApiKey, hasRequestContext, init, parseStackTrace, reset, runWithContext, runWithContextAsync, setExtra, setRequestExtra, setRequestTag, setRequestUser, setTag, setUser, validateApiKey };
|
|
576
931
|
//# sourceMappingURL=index.mjs.map
|
|
577
932
|
//# sourceMappingURL=index.mjs.map
|