@bugwatch/core 0.1.0 → 0.2.1

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 CHANGED
@@ -131,6 +131,16 @@ interface ErrorEvent {
131
131
  */
132
132
  interface Transport {
133
133
  send(event: ErrorEvent): Promise<void>;
134
+ /**
135
+ * Flush any pending events.
136
+ * Ensures all queued events are sent before the promise resolves.
137
+ */
138
+ flush?(): Promise<void>;
139
+ /**
140
+ * Close the transport and release any resources.
141
+ * After calling this method, the transport should not be used again.
142
+ */
143
+ close?(): Promise<void>;
134
144
  }
135
145
  /**
136
146
  * Integration interface for platform-specific functionality
@@ -150,6 +160,16 @@ interface BugwatchClient {
150
160
  setTag(key: string, value: string): void;
151
161
  setExtra(key: string, value: unknown): void;
152
162
  getOptions(): BugwatchOptions;
163
+ /**
164
+ * Flush any pending events.
165
+ * Call this before process exit to ensure no events are lost.
166
+ */
167
+ flush(): Promise<void>;
168
+ /**
169
+ * Close the client and release any resources.
170
+ * This flushes any pending events and closes the transport.
171
+ */
172
+ close(): Promise<void>;
153
173
  }
154
174
 
155
175
  /**
@@ -218,6 +238,17 @@ declare class Bugwatch implements BugwatchClient {
218
238
  * Detect the current platform
219
239
  */
220
240
  private detectPlatform;
241
+ /**
242
+ * Flush any pending events.
243
+ * Call this before process exit to ensure no events are lost.
244
+ */
245
+ flush(): Promise<void>;
246
+ /**
247
+ * Close the client and release any resources.
248
+ * This flushes any pending events and closes the transport.
249
+ * After calling this method, the client should not be used again.
250
+ */
251
+ close(): Promise<void>;
221
252
  }
222
253
 
223
254
  /**
@@ -227,6 +258,7 @@ declare class HttpTransport implements Transport {
227
258
  private endpoint;
228
259
  private apiKey;
229
260
  private debug;
261
+ private timeoutMs;
230
262
  constructor(options: BugwatchOptions);
231
263
  send(event: ErrorEvent): Promise<void>;
232
264
  /**
@@ -263,6 +295,10 @@ declare class BatchTransport implements Transport {
263
295
  flush(): Promise<void>;
264
296
  private startTimer;
265
297
  destroy(): void;
298
+ /**
299
+ * Close the transport, flushing any remaining events and stopping the timer.
300
+ */
301
+ close(): Promise<void>;
266
302
  }
267
303
 
268
304
  /**
@@ -288,36 +324,228 @@ declare function generateFingerprint(errorType: string, message: string, stacktr
288
324
  declare function fingerprintFromException(exception: ExceptionInfo): string;
289
325
 
290
326
  /**
291
- * Initialize the global Bugwatch client
327
+ * Environment variable utilities for Bugwatch SDK.
328
+ *
329
+ * This module provides functions for reading configuration from environment
330
+ * variables and validating API keys.
292
331
  */
293
- declare function init(options: BugwatchOptions): Bugwatch;
332
+
333
+ /**
334
+ * Supported environment variables for Bugwatch configuration.
335
+ */
336
+ declare const ENV_VARS: {
337
+ readonly API_KEY: "BUGWATCH_API_KEY";
338
+ readonly ENVIRONMENT: "BUGWATCH_ENVIRONMENT";
339
+ readonly RELEASE: "BUGWATCH_RELEASE";
340
+ readonly DEBUG: "BUGWATCH_DEBUG";
341
+ readonly ENDPOINT: "BUGWATCH_ENDPOINT";
342
+ };
343
+ /**
344
+ * Read Bugwatch configuration from environment variables.
345
+ *
346
+ * Supported environment variables:
347
+ * - `BUGWATCH_API_KEY` - API key (required unless passed explicitly)
348
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag (e.g., 'production', 'staging')
349
+ * - `BUGWATCH_RELEASE` - Release version
350
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true' to enable)
351
+ * - `BUGWATCH_ENDPOINT` - Custom API endpoint
352
+ *
353
+ * @returns Partial configuration from environment variables
354
+ *
355
+ * @example
356
+ * ```typescript
357
+ * // Set environment variables
358
+ * // BUGWATCH_API_KEY=bw_live_xxxxx
359
+ * // BUGWATCH_ENVIRONMENT=production
360
+ *
361
+ * const envConfig = getEnvConfig();
362
+ * // { apiKey: 'bw_live_xxxxx', environment: 'production' }
363
+ * ```
364
+ */
365
+ declare function getEnvConfig(): Partial<BugwatchOptions>;
366
+ /**
367
+ * Validate an API key and throw a clear error if invalid.
368
+ *
369
+ * @param key - The API key to validate
370
+ * @throws Error if the API key is missing or invalid
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * // Missing API key
375
+ * validateApiKey(undefined);
376
+ * // throws: "Bugwatch: API key required. Set BUGWATCH_API_KEY environment variable or pass { apiKey: '...' }"
377
+ *
378
+ * // Invalid format (logs warning but doesn't throw)
379
+ * validateApiKey("invalid-key");
380
+ * // warns: "Bugwatch: API key should start with 'bw_'. Got 'invali...'"
381
+ * ```
382
+ */
383
+ declare function validateApiKey(key: string | undefined): asserts key is string;
384
+ /**
385
+ * Check if API key is available (either in env or passed explicitly).
386
+ *
387
+ * @param explicitKey - Explicitly provided API key
388
+ * @returns true if an API key is available
389
+ */
390
+ declare function hasApiKey(explicitKey?: string): boolean;
391
+
392
+ /**
393
+ * Request-scoped context using AsyncLocalStorage.
394
+ *
395
+ * This module provides thread-safe, request-isolated context storage
396
+ * for Node.js environments. Each concurrent request gets its own
397
+ * isolated context that won't leak to other requests.
398
+ */
399
+
400
+ /**
401
+ * Request-scoped context that is isolated per request
402
+ */
403
+ interface ScopedContext {
404
+ user: UserContext | null;
405
+ tags: Record<string, string>;
406
+ extra: Record<string, unknown>;
407
+ breadcrumbs: Breadcrumb[];
408
+ }
409
+ /**
410
+ * Create a new empty scoped context
411
+ */
412
+ declare function createScopedContext(): ScopedContext;
413
+ /**
414
+ * Run a function within an isolated context.
415
+ *
416
+ * All context operations (setUser, setTag, etc.) within this function
417
+ * will be scoped to this context and won't affect other concurrent requests.
418
+ *
419
+ * @param context - The initial context for this scope
420
+ * @param fn - The function to run within the context
421
+ * @returns The result of the function
422
+ */
423
+ declare function runWithContext<T>(context: ScopedContext, fn: () => T): T;
424
+ /**
425
+ * Run an async function within an isolated context.
426
+ */
427
+ declare function runWithContextAsync<T>(context: ScopedContext, fn: () => Promise<T>): Promise<T>;
428
+ /**
429
+ * Get the current request-scoped context.
430
+ * Returns undefined if not running within a context scope.
431
+ */
432
+ declare function getRequestContext(): ScopedContext | undefined;
433
+ /**
434
+ * Check if we're currently running within a scoped context
435
+ */
436
+ declare function hasRequestContext(): boolean;
437
+ /**
438
+ * Set user in the current request context (if available)
439
+ * Returns true if the user was set in request context, false otherwise
440
+ */
441
+ declare function setRequestUser(user: UserContext | null): boolean;
442
+ /**
443
+ * Set a tag in the current request context (if available)
444
+ * Returns true if the tag was set in request context, false otherwise
445
+ */
446
+ declare function setRequestTag(key: string, value: string): boolean;
447
+ /**
448
+ * Set extra data in the current request context (if available)
449
+ * Returns true if the extra was set in request context, false otherwise
450
+ */
451
+ declare function setRequestExtra(key: string, value: unknown): boolean;
452
+ /**
453
+ * Add a breadcrumb to the current request context (if available)
454
+ * Returns true if the breadcrumb was added to request context, false otherwise
455
+ */
456
+ declare function addRequestBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): boolean;
457
+ /**
458
+ * Get the merged context from request scope and global scope
459
+ */
460
+ declare function getMergedContext(globalUser: UserContext | null, globalTags: Record<string, string>, globalExtra: Record<string, unknown>, globalBreadcrumbs: Breadcrumb[]): {
461
+ user: UserContext | null;
462
+ tags: Record<string, string>;
463
+ extra: Record<string, unknown>;
464
+ breadcrumbs: Breadcrumb[];
465
+ };
466
+
467
+ /**
468
+ * Initialize the global Bugwatch client.
469
+ *
470
+ * Reads configuration from environment variables if not explicitly provided:
471
+ * - `BUGWATCH_API_KEY` - API key (required)
472
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag
473
+ * - `BUGWATCH_RELEASE` - Release version
474
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true')
475
+ *
476
+ * @param options - Configuration options (optional if BUGWATCH_API_KEY env var is set)
477
+ * @throws Error if no API key is provided and BUGWATCH_API_KEY is not set
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * // With env var BUGWATCH_API_KEY set
482
+ * init();
483
+ *
484
+ * // Or explicit configuration
485
+ * init({ apiKey: "bw_live_xxxxx" });
486
+ *
487
+ * // Mix of env vars and explicit options
488
+ * init({ environment: "staging" }); // Uses BUGWATCH_API_KEY from env
489
+ * ```
490
+ */
491
+ declare function init(options?: Partial<BugwatchOptions>): Bugwatch;
294
492
  /**
295
493
  * Get the global Bugwatch client
296
494
  */
297
495
  declare function getClient(): Bugwatch | null;
298
496
  /**
299
- * Capture an exception using the global client
497
+ * Capture an exception using the global client.
498
+ *
499
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
500
+ * the SDK will auto-initialize before capturing.
300
501
  */
301
502
  declare function captureException(error: Error, context?: Partial<ErrorEvent>): string;
302
503
  /**
303
- * Capture a message using the global client
504
+ * Capture a message using the global client.
505
+ *
506
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
507
+ * the SDK will auto-initialize before capturing.
304
508
  */
305
509
  declare function captureMessage(message: string, level?: ErrorEvent["level"]): string;
306
510
  /**
307
- * Add a breadcrumb using the global client
511
+ * Add a breadcrumb using the global client.
512
+ * If called within a request context, adds to the request-scoped breadcrumbs.
308
513
  */
309
514
  declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
310
515
  /**
311
- * Set user context on the global client
516
+ * Set user context.
517
+ * If called within a request context, sets the request-scoped user.
518
+ * Otherwise sets the global user context.
312
519
  */
313
520
  declare function setUser(user: UserContext | null): void;
314
521
  /**
315
- * Set a tag on the global client
522
+ * Set a tag.
523
+ * If called within a request context, sets the request-scoped tag.
524
+ * Otherwise sets the global tag.
316
525
  */
317
526
  declare function setTag(key: string, value: string): void;
318
527
  /**
319
- * Set extra context on the global client
528
+ * Set extra context.
529
+ * If called within a request context, sets the request-scoped extra.
530
+ * Otherwise sets the global extra context.
320
531
  */
321
532
  declare function setExtra(key: string, value: unknown): void;
533
+ /**
534
+ * Flush any pending events using the global client.
535
+ * Call this before process exit to ensure no events are lost.
536
+ */
537
+ declare function flush(): Promise<void>;
538
+ /**
539
+ * Close the global client and release any resources.
540
+ * This flushes any pending events and closes the transport.
541
+ * After calling this method, the client should not be used again.
542
+ */
543
+ declare function close(): Promise<void>;
544
+ /**
545
+ * Reset the SDK state completely.
546
+ * Use this for testing or to allow re-initialization.
547
+ * Note: This does NOT flush pending events - call close() first if needed.
548
+ */
549
+ declare function reset(): void;
322
550
 
323
- export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, captureException, captureMessage, extractErrorInfo, fingerprintFromException, generateFingerprint, getClient, init, parseStackTrace, setExtra, setTag, setUser };
551
+ export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, ENV_VARS, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type ScopedContext, type SdkInfo, type StackFrame, type Transport, type UserContext, 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 };
package/dist/index.d.ts CHANGED
@@ -131,6 +131,16 @@ interface ErrorEvent {
131
131
  */
132
132
  interface Transport {
133
133
  send(event: ErrorEvent): Promise<void>;
134
+ /**
135
+ * Flush any pending events.
136
+ * Ensures all queued events are sent before the promise resolves.
137
+ */
138
+ flush?(): Promise<void>;
139
+ /**
140
+ * Close the transport and release any resources.
141
+ * After calling this method, the transport should not be used again.
142
+ */
143
+ close?(): Promise<void>;
134
144
  }
135
145
  /**
136
146
  * Integration interface for platform-specific functionality
@@ -150,6 +160,16 @@ interface BugwatchClient {
150
160
  setTag(key: string, value: string): void;
151
161
  setExtra(key: string, value: unknown): void;
152
162
  getOptions(): BugwatchOptions;
163
+ /**
164
+ * Flush any pending events.
165
+ * Call this before process exit to ensure no events are lost.
166
+ */
167
+ flush(): Promise<void>;
168
+ /**
169
+ * Close the client and release any resources.
170
+ * This flushes any pending events and closes the transport.
171
+ */
172
+ close(): Promise<void>;
153
173
  }
154
174
 
155
175
  /**
@@ -218,6 +238,17 @@ declare class Bugwatch implements BugwatchClient {
218
238
  * Detect the current platform
219
239
  */
220
240
  private detectPlatform;
241
+ /**
242
+ * Flush any pending events.
243
+ * Call this before process exit to ensure no events are lost.
244
+ */
245
+ flush(): Promise<void>;
246
+ /**
247
+ * Close the client and release any resources.
248
+ * This flushes any pending events and closes the transport.
249
+ * After calling this method, the client should not be used again.
250
+ */
251
+ close(): Promise<void>;
221
252
  }
222
253
 
223
254
  /**
@@ -227,6 +258,7 @@ declare class HttpTransport implements Transport {
227
258
  private endpoint;
228
259
  private apiKey;
229
260
  private debug;
261
+ private timeoutMs;
230
262
  constructor(options: BugwatchOptions);
231
263
  send(event: ErrorEvent): Promise<void>;
232
264
  /**
@@ -263,6 +295,10 @@ declare class BatchTransport implements Transport {
263
295
  flush(): Promise<void>;
264
296
  private startTimer;
265
297
  destroy(): void;
298
+ /**
299
+ * Close the transport, flushing any remaining events and stopping the timer.
300
+ */
301
+ close(): Promise<void>;
266
302
  }
267
303
 
268
304
  /**
@@ -288,36 +324,228 @@ declare function generateFingerprint(errorType: string, message: string, stacktr
288
324
  declare function fingerprintFromException(exception: ExceptionInfo): string;
289
325
 
290
326
  /**
291
- * Initialize the global Bugwatch client
327
+ * Environment variable utilities for Bugwatch SDK.
328
+ *
329
+ * This module provides functions for reading configuration from environment
330
+ * variables and validating API keys.
292
331
  */
293
- declare function init(options: BugwatchOptions): Bugwatch;
332
+
333
+ /**
334
+ * Supported environment variables for Bugwatch configuration.
335
+ */
336
+ declare const ENV_VARS: {
337
+ readonly API_KEY: "BUGWATCH_API_KEY";
338
+ readonly ENVIRONMENT: "BUGWATCH_ENVIRONMENT";
339
+ readonly RELEASE: "BUGWATCH_RELEASE";
340
+ readonly DEBUG: "BUGWATCH_DEBUG";
341
+ readonly ENDPOINT: "BUGWATCH_ENDPOINT";
342
+ };
343
+ /**
344
+ * Read Bugwatch configuration from environment variables.
345
+ *
346
+ * Supported environment variables:
347
+ * - `BUGWATCH_API_KEY` - API key (required unless passed explicitly)
348
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag (e.g., 'production', 'staging')
349
+ * - `BUGWATCH_RELEASE` - Release version
350
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true' to enable)
351
+ * - `BUGWATCH_ENDPOINT` - Custom API endpoint
352
+ *
353
+ * @returns Partial configuration from environment variables
354
+ *
355
+ * @example
356
+ * ```typescript
357
+ * // Set environment variables
358
+ * // BUGWATCH_API_KEY=bw_live_xxxxx
359
+ * // BUGWATCH_ENVIRONMENT=production
360
+ *
361
+ * const envConfig = getEnvConfig();
362
+ * // { apiKey: 'bw_live_xxxxx', environment: 'production' }
363
+ * ```
364
+ */
365
+ declare function getEnvConfig(): Partial<BugwatchOptions>;
366
+ /**
367
+ * Validate an API key and throw a clear error if invalid.
368
+ *
369
+ * @param key - The API key to validate
370
+ * @throws Error if the API key is missing or invalid
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * // Missing API key
375
+ * validateApiKey(undefined);
376
+ * // throws: "Bugwatch: API key required. Set BUGWATCH_API_KEY environment variable or pass { apiKey: '...' }"
377
+ *
378
+ * // Invalid format (logs warning but doesn't throw)
379
+ * validateApiKey("invalid-key");
380
+ * // warns: "Bugwatch: API key should start with 'bw_'. Got 'invali...'"
381
+ * ```
382
+ */
383
+ declare function validateApiKey(key: string | undefined): asserts key is string;
384
+ /**
385
+ * Check if API key is available (either in env or passed explicitly).
386
+ *
387
+ * @param explicitKey - Explicitly provided API key
388
+ * @returns true if an API key is available
389
+ */
390
+ declare function hasApiKey(explicitKey?: string): boolean;
391
+
392
+ /**
393
+ * Request-scoped context using AsyncLocalStorage.
394
+ *
395
+ * This module provides thread-safe, request-isolated context storage
396
+ * for Node.js environments. Each concurrent request gets its own
397
+ * isolated context that won't leak to other requests.
398
+ */
399
+
400
+ /**
401
+ * Request-scoped context that is isolated per request
402
+ */
403
+ interface ScopedContext {
404
+ user: UserContext | null;
405
+ tags: Record<string, string>;
406
+ extra: Record<string, unknown>;
407
+ breadcrumbs: Breadcrumb[];
408
+ }
409
+ /**
410
+ * Create a new empty scoped context
411
+ */
412
+ declare function createScopedContext(): ScopedContext;
413
+ /**
414
+ * Run a function within an isolated context.
415
+ *
416
+ * All context operations (setUser, setTag, etc.) within this function
417
+ * will be scoped to this context and won't affect other concurrent requests.
418
+ *
419
+ * @param context - The initial context for this scope
420
+ * @param fn - The function to run within the context
421
+ * @returns The result of the function
422
+ */
423
+ declare function runWithContext<T>(context: ScopedContext, fn: () => T): T;
424
+ /**
425
+ * Run an async function within an isolated context.
426
+ */
427
+ declare function runWithContextAsync<T>(context: ScopedContext, fn: () => Promise<T>): Promise<T>;
428
+ /**
429
+ * Get the current request-scoped context.
430
+ * Returns undefined if not running within a context scope.
431
+ */
432
+ declare function getRequestContext(): ScopedContext | undefined;
433
+ /**
434
+ * Check if we're currently running within a scoped context
435
+ */
436
+ declare function hasRequestContext(): boolean;
437
+ /**
438
+ * Set user in the current request context (if available)
439
+ * Returns true if the user was set in request context, false otherwise
440
+ */
441
+ declare function setRequestUser(user: UserContext | null): boolean;
442
+ /**
443
+ * Set a tag in the current request context (if available)
444
+ * Returns true if the tag was set in request context, false otherwise
445
+ */
446
+ declare function setRequestTag(key: string, value: string): boolean;
447
+ /**
448
+ * Set extra data in the current request context (if available)
449
+ * Returns true if the extra was set in request context, false otherwise
450
+ */
451
+ declare function setRequestExtra(key: string, value: unknown): boolean;
452
+ /**
453
+ * Add a breadcrumb to the current request context (if available)
454
+ * Returns true if the breadcrumb was added to request context, false otherwise
455
+ */
456
+ declare function addRequestBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): boolean;
457
+ /**
458
+ * Get the merged context from request scope and global scope
459
+ */
460
+ declare function getMergedContext(globalUser: UserContext | null, globalTags: Record<string, string>, globalExtra: Record<string, unknown>, globalBreadcrumbs: Breadcrumb[]): {
461
+ user: UserContext | null;
462
+ tags: Record<string, string>;
463
+ extra: Record<string, unknown>;
464
+ breadcrumbs: Breadcrumb[];
465
+ };
466
+
467
+ /**
468
+ * Initialize the global Bugwatch client.
469
+ *
470
+ * Reads configuration from environment variables if not explicitly provided:
471
+ * - `BUGWATCH_API_KEY` - API key (required)
472
+ * - `BUGWATCH_ENVIRONMENT` - Environment tag
473
+ * - `BUGWATCH_RELEASE` - Release version
474
+ * - `BUGWATCH_DEBUG` - Enable debug mode ('true')
475
+ *
476
+ * @param options - Configuration options (optional if BUGWATCH_API_KEY env var is set)
477
+ * @throws Error if no API key is provided and BUGWATCH_API_KEY is not set
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * // With env var BUGWATCH_API_KEY set
482
+ * init();
483
+ *
484
+ * // Or explicit configuration
485
+ * init({ apiKey: "bw_live_xxxxx" });
486
+ *
487
+ * // Mix of env vars and explicit options
488
+ * init({ environment: "staging" }); // Uses BUGWATCH_API_KEY from env
489
+ * ```
490
+ */
491
+ declare function init(options?: Partial<BugwatchOptions>): Bugwatch;
294
492
  /**
295
493
  * Get the global Bugwatch client
296
494
  */
297
495
  declare function getClient(): Bugwatch | null;
298
496
  /**
299
- * Capture an exception using the global client
497
+ * Capture an exception using the global client.
498
+ *
499
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
500
+ * the SDK will auto-initialize before capturing.
300
501
  */
301
502
  declare function captureException(error: Error, context?: Partial<ErrorEvent>): string;
302
503
  /**
303
- * Capture a message using the global client
504
+ * Capture a message using the global client.
505
+ *
506
+ * If the SDK is not initialized but BUGWATCH_API_KEY environment variable is set,
507
+ * the SDK will auto-initialize before capturing.
304
508
  */
305
509
  declare function captureMessage(message: string, level?: ErrorEvent["level"]): string;
306
510
  /**
307
- * Add a breadcrumb using the global client
511
+ * Add a breadcrumb using the global client.
512
+ * If called within a request context, adds to the request-scoped breadcrumbs.
308
513
  */
309
514
  declare function addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
310
515
  /**
311
- * Set user context on the global client
516
+ * Set user context.
517
+ * If called within a request context, sets the request-scoped user.
518
+ * Otherwise sets the global user context.
312
519
  */
313
520
  declare function setUser(user: UserContext | null): void;
314
521
  /**
315
- * Set a tag on the global client
522
+ * Set a tag.
523
+ * If called within a request context, sets the request-scoped tag.
524
+ * Otherwise sets the global tag.
316
525
  */
317
526
  declare function setTag(key: string, value: string): void;
318
527
  /**
319
- * Set extra context on the global client
528
+ * Set extra context.
529
+ * If called within a request context, sets the request-scoped extra.
530
+ * Otherwise sets the global extra context.
320
531
  */
321
532
  declare function setExtra(key: string, value: unknown): void;
533
+ /**
534
+ * Flush any pending events using the global client.
535
+ * Call this before process exit to ensure no events are lost.
536
+ */
537
+ declare function flush(): Promise<void>;
538
+ /**
539
+ * Close the global client and release any resources.
540
+ * This flushes any pending events and closes the transport.
541
+ * After calling this method, the client should not be used again.
542
+ */
543
+ declare function close(): Promise<void>;
544
+ /**
545
+ * Reset the SDK state completely.
546
+ * Use this for testing or to allow re-initialization.
547
+ * Note: This does NOT flush pending events - call close() first if needed.
548
+ */
549
+ declare function reset(): void;
322
550
 
323
- export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type SdkInfo, type StackFrame, type Transport, type UserContext, addBreadcrumb, captureException, captureMessage, extractErrorInfo, fingerprintFromException, generateFingerprint, getClient, init, parseStackTrace, setExtra, setTag, setUser };
551
+ export { BatchTransport, type Breadcrumb, Bugwatch, type BugwatchClient, type BugwatchOptions, ConsoleTransport, ENV_VARS, type ErrorEvent, type ExceptionInfo, HttpTransport, type Integration, NoopTransport, type RequestContext, type RuntimeInfo, type ScopedContext, type SdkInfo, type StackFrame, type Transport, type UserContext, 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 };