sentry-vir 0.1.2 → 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.
Files changed (50) hide show
  1. package/README.md +5 -17
  2. package/dist/cjs/auto.js +1 -1
  3. package/dist/cjs/browser.js +1 -1
  4. package/dist/cjs/event-context/extra-event-context.d.ts +7 -1
  5. package/dist/cjs/event-context/extra-event-context.js +26 -3
  6. package/dist/cjs/index.d.ts +5 -2
  7. package/dist/cjs/index.js +5 -2
  8. package/dist/cjs/init-sentry/base-sentry-init.d.ts +1 -1
  9. package/dist/cjs/init-sentry/base-sentry-init.js +3 -1
  10. package/dist/cjs/{processing → init-sentry}/sentry-config.js +1 -1
  11. package/dist/cjs/logging/attach-tags.d.ts +5 -0
  12. package/dist/cjs/logging/attach-tags.js +20 -0
  13. package/dist/cjs/logging/handle-error.d.ts +3 -0
  14. package/dist/cjs/logging/handle-error.js +33 -0
  15. package/dist/cjs/logging/premature-events.d.ts +8 -0
  16. package/dist/cjs/logging/premature-events.js +27 -0
  17. package/dist/cjs/logging/send-log.d.ts +13 -0
  18. package/dist/cjs/logging/send-log.js +51 -0
  19. package/dist/cjs/logging/sentry-client-for-logging.d.ts +17 -0
  20. package/dist/cjs/logging/sentry-client-for-logging.js +22 -0
  21. package/dist/cjs/node.js +1 -1
  22. package/dist/cjs/processing/event-processor.js +2 -1
  23. package/dist/esm/auto.js +1 -1
  24. package/dist/esm/browser.js +1 -1
  25. package/dist/esm/event-context/extra-event-context.d.ts +7 -1
  26. package/dist/esm/event-context/extra-event-context.js +24 -2
  27. package/dist/esm/index.d.ts +5 -2
  28. package/dist/esm/index.js +5 -2
  29. package/dist/esm/init-sentry/base-sentry-init.d.ts +1 -1
  30. package/dist/esm/init-sentry/base-sentry-init.js +3 -1
  31. package/dist/esm/{processing → init-sentry}/sentry-config.js +1 -1
  32. package/dist/esm/logging/attach-tags.d.ts +5 -0
  33. package/dist/esm/logging/attach-tags.js +16 -0
  34. package/dist/esm/logging/handle-error.d.ts +3 -0
  35. package/dist/esm/logging/handle-error.js +29 -0
  36. package/dist/esm/logging/premature-events.d.ts +8 -0
  37. package/dist/esm/logging/premature-events.js +22 -0
  38. package/dist/esm/logging/send-log.d.ts +13 -0
  39. package/dist/esm/logging/send-log.js +48 -0
  40. package/dist/esm/logging/sentry-client-for-logging.d.ts +17 -0
  41. package/dist/esm/logging/sentry-client-for-logging.js +20 -0
  42. package/dist/esm/node.js +1 -1
  43. package/dist/esm/processing/event-processor.js +2 -1
  44. package/package.json +11 -7
  45. package/dist/cjs/processing/sentry-logger.d.ts +0 -40
  46. package/dist/cjs/processing/sentry-logger.js +0 -113
  47. package/dist/esm/processing/sentry-logger.d.ts +0 -40
  48. package/dist/esm/processing/sentry-logger.js +0 -108
  49. /package/dist/cjs/{processing → init-sentry}/sentry-config.d.ts +0 -0
  50. /package/dist/esm/{processing → init-sentry}/sentry-config.d.ts +0 -0
package/README.md CHANGED
@@ -14,8 +14,6 @@ Full api reference: https://electrovir.github.io/sentry-vir
14
14
 
15
15
  - Use `initSentry` to initialize Sentry.
16
16
  - Use `sendLog` and `handleError` to send events to Sentry.
17
- - Use `setSentryClientForLogging` once `initSentry` has resolved to enable those events to send to Sentry.
18
- - Note that `sendLog` and `handleError` _can_ be fired before `setSentryClientForLogging` has been called. Once `setSentryClientForLogging` has been called, it will catch up.
19
17
  - Use `throwWithExtraContext` to throw an error while attaching extra event context for Sentry to pick up.
20
18
 
21
19
  ## Basic setup example
@@ -27,8 +25,8 @@ Full api reference: https://electrovir.github.io/sentry-vir
27
25
  * If initializing sentry for node, instead import from 'sentry-vir/dist/esm/node' (for ESM) or
28
26
  * 'sentry-vir/dist/cjs/node' (for CommonJS).
29
27
  */
28
+ import {SentryReleaseEnvEnum} from 'sentry-vir';
30
29
  import {initSentry} from 'sentry-vir/dist/esm/browser';
31
- import {SentryReleaseEnvEnum} from '..';
32
30
 
33
31
  initSentry({
34
32
  dsn: 'Sentry project id provided by Sentry',
@@ -49,20 +47,15 @@ initSentry({
49
47
  <!-- example-link: src/readme-examples/setup-logging.example.ts -->
50
48
 
51
49
  ```TypeScript
50
+ import {SentryReleaseEnvEnum, handleError, sendLog, throwWithExtraContext} from 'sentry-vir';
52
51
  import {initSentry} from 'sentry-vir/dist/esm/browser';
53
- import {
54
- SentryReleaseEnvEnum,
55
- handleError,
56
- sendLog,
57
- setSentryClientForLogging,
58
- throwWithExtraContext,
59
- } from '..';
60
52
 
61
53
  sendLog.info('starting file');
62
54
  /** Extra log context can be added as the second argument to a sendLog method. */
63
55
  sendLog.info('starting file 2', {addExtraContext: 'here'});
64
56
  /** Other severities are covered. */
65
57
  sendLog.debug('debug log');
58
+ /** Logs and errors will be buffered so it's safe to call this before initSentry has been called. */
66
59
  sendLog.warning('warning log');
67
60
 
68
61
  /** Standard init. Note that this returns a promise. */
@@ -76,18 +69,13 @@ initSentry({
76
69
  userTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
77
70
  };
78
71
  },
79
- }).then((sentryClient) => {
80
- /**
81
- * This must be called at some point for all handleError and sendLog events to send to Sentry.
82
- * Note that sendLog and handleError can still be fired before setSentryClientForLogging is
83
- * called. Once setSentryClientForLogging is called, it'll catch up.
84
- */
85
- setSentryClientForLogging(sentryClient);
86
72
  });
87
73
 
88
74
  handleError(new Error('test error'));
89
75
  /** Extra error context can be added as the second argument to handleError. */
90
76
  handleError(new Error('test error 2'), {addExtraContext: 'here'});
77
+ /** These will be included in the Sentry buffer even if initSentry has not been awaited yet. */
78
+ handleError(new Error('test error 2'), {addExtraContext: 'here'});
91
79
 
92
80
  /** Throw an error with extra context attached for Sentry to pick up. */
93
81
  throwWithExtraContext(new Error('final error'), {addExtraContext: 'here'});
package/dist/cjs/auto.js CHANGED
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.autoInitSentry = exports.sentryDepByEnv = void 0;
27
27
  const execution_env_1 = require("./env/execution-env");
28
+ const sentry_config_1 = require("./init-sentry/sentry-config");
28
29
  const event_processor_1 = require("./processing/event-processor");
29
- const sentry_config_1 = require("./processing/sentry-config");
30
30
  /** The sentry dep import for each execution env. */
31
31
  /* c8 ignore next 6 */
32
32
  exports.sentryDepByEnv = {
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.initSentry = void 0;
27
27
  const execution_env_1 = require("./env/execution-env");
28
+ const sentry_config_1 = require("./init-sentry/sentry-config");
28
29
  const event_processor_1 = require("./processing/event-processor");
29
- const sentry_config_1 = require("./processing/sentry-config");
30
30
  /**
31
31
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
32
32
  * with all the default sentry-vir integrations and configs.
@@ -1,3 +1,4 @@
1
+ import { Event, EventHint } from '@sentry/types';
1
2
  import { EventExtraContext } from './event-context';
2
3
  /**
3
4
  * Symbol used to attach extra event context to events. This is particularly useful for errors so
@@ -10,8 +11,13 @@ export type HasExtraContext = {
10
11
  };
11
12
  /** Type guard for whether any given input has extra event context. */
12
13
  export declare function hasExtraEventContext(input: unknown): input is HasExtraContext;
14
+ /**
15
+ * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
16
+ * if so, extracts it.
17
+ */
18
+ export declare function extractExtraContentFromSymbol(input: unknown): EventExtraContext | undefined;
13
19
  /**
14
20
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
15
21
  * no extra event context.
16
22
  */
17
- export declare function extractExtraEventContext(event: unknown): EventExtraContext | undefined;
23
+ export declare function extractExtraEventContext(event: EventHint | Event): EventExtraContext | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractExtraEventContext = exports.hasExtraEventContext = exports.extraEventContextSymbol = void 0;
3
+ exports.extractExtraEventContext = exports.extractExtraContentFromSymbol = exports.hasExtraEventContext = exports.extraEventContextSymbol = void 0;
4
4
  const common_1 = require("@augment-vir/common");
5
5
  /**
6
6
  * Symbol used to attach extra event context to events. This is particularly useful for errors so
@@ -12,13 +12,36 @@ function hasExtraEventContext(input) {
12
12
  return (0, common_1.typedHasProperty)(input, exports.extraEventContextSymbol);
13
13
  }
14
14
  exports.hasExtraEventContext = hasExtraEventContext;
15
+ /**
16
+ * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
17
+ * if so, extracts it.
18
+ */
19
+ function extractExtraContentFromSymbol(input) {
20
+ if (hasExtraEventContext(input)) {
21
+ return input[exports.extraEventContextSymbol];
22
+ }
23
+ else {
24
+ return undefined;
25
+ }
26
+ }
27
+ exports.extractExtraContentFromSymbol = extractExtraContentFromSymbol;
15
28
  /**
16
29
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
17
30
  * no extra event context.
18
31
  */
19
32
  function extractExtraEventContext(event) {
20
- if (hasExtraEventContext(event)) {
21
- return event[exports.extraEventContextSymbol];
33
+ const fromRootSymbol = extractExtraContentFromSymbol(event);
34
+ const fromSubSymbol = 'originalException' in event
35
+ ? extractExtraContentFromSymbol(event.originalException)
36
+ : undefined;
37
+ const fromCapture = 'captureContext' in event ? event.captureContext : undefined;
38
+ const combined = {
39
+ ...fromRootSymbol,
40
+ ...fromSubSymbol,
41
+ ...fromCapture,
42
+ };
43
+ if (Object.keys(combined).length) {
44
+ return combined;
22
45
  }
23
46
  else {
24
47
  return undefined;
@@ -5,7 +5,10 @@ export * from './event-context/event-severity';
5
5
  export * from './event-context/extra-context.error';
6
6
  export * from './event-context/extra-event-context';
7
7
  export * from './init-sentry/base-sentry-init';
8
+ export * from './init-sentry/sentry-config';
9
+ export * from './logging/attach-tags';
10
+ export * from './logging/handle-error';
11
+ export * from './logging/send-log';
12
+ export * from './logging/sentry-client-for-logging';
8
13
  export * from './processing/event-processor';
9
14
  export * from './processing/handle-sentry-send';
10
- export * from './processing/sentry-config';
11
- export * from './processing/sentry-logger';
package/dist/cjs/index.js CHANGED
@@ -21,7 +21,10 @@ __exportStar(require("./event-context/event-severity"), exports);
21
21
  __exportStar(require("./event-context/extra-context.error"), exports);
22
22
  __exportStar(require("./event-context/extra-event-context"), exports);
23
23
  __exportStar(require("./init-sentry/base-sentry-init"), exports);
24
+ __exportStar(require("./init-sentry/sentry-config"), exports);
25
+ __exportStar(require("./logging/attach-tags"), exports);
26
+ __exportStar(require("./logging/handle-error"), exports);
27
+ __exportStar(require("./logging/send-log"), exports);
28
+ __exportStar(require("./logging/sentry-client-for-logging"), exports);
24
29
  __exportStar(require("./processing/event-processor"), exports);
25
30
  __exportStar(require("./processing/handle-sentry-send"), exports);
26
- __exportStar(require("./processing/sentry-config"), exports);
27
- __exportStar(require("./processing/sentry-logger"), exports);
@@ -2,7 +2,7 @@ import type { Options } from '@sentry/types';
2
2
  import { SentryDep, SentryExecutionEnvEnum } from '../env/execution-env';
3
3
  import { SentryReleaseEnvEnum } from '../env/release-env';
4
4
  import { EventExtraContextCreator } from '../event-context/event-context';
5
- import { UserOverrides } from '../processing/sentry-config';
5
+ import { UserOverrides } from './sentry-config';
6
6
  /** Configuration for initializing Sentry. */
7
7
  export type InitSentryInput = {
8
8
  /**
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.baseInitSentry = void 0;
4
+ const sentry_client_for_logging_1 = require("../logging/sentry-client-for-logging");
4
5
  const event_processor_1 = require("../processing/event-processor");
5
- const sentry_config_1 = require("../processing/sentry-config");
6
+ const sentry_config_1 = require("./sentry-config");
6
7
  /**
7
8
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
8
9
  * with all the default sentry-vir integrations and configs.
@@ -18,6 +19,7 @@ async function baseInitSentry({ dsn, releaseEnv, releaseName, sentryConfigOverri
18
19
  }, sentryConfigOverrides, releaseEnv);
19
20
  sentryDep.init(finalSentryConfig);
20
21
  sentryDep.addGlobalEventProcessor((event, hint) => (0, event_processor_1.processSentryEvent)(event, hint, createUniversalContext));
22
+ (0, sentry_client_for_logging_1.setSentryClientForLogging)(sentryDep);
21
23
  return sentryDep;
22
24
  }
23
25
  exports.baseInitSentry = baseInitSentry;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSentryConfig = void 0;
4
4
  const common_1 = require("@augment-vir/common");
5
5
  const execution_env_1 = require("../env/execution-env");
6
- const handle_sentry_send_1 = require("./handle-sentry-send");
6
+ const handle_sentry_send_1 = require("../processing/handle-sentry-send");
7
7
  /** Creates the sentry config used internally by sentry-vir. */
8
8
  // can't test config creation because it depends on execution environment
9
9
  /* c8 ignore next 60 */
@@ -0,0 +1,5 @@
1
+ import type { setTags } from '@sentry/core';
2
+ /** A list of tag names as keys and their values. Set a tag to undefined to clear it. */
3
+ export type SentryTags = Parameters<typeof setTags>[0];
4
+ /** Set tags for all future Sentry event handling (errors and logs). */
5
+ export declare function attachSentryTags(tags: SentryTags): undefined;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attachSentryTags = void 0;
4
+ const premature_events_1 = require("./premature-events");
5
+ const sentry_client_for_logging_1 = require("./sentry-client-for-logging");
6
+ /** Set tags for all future Sentry event handling (errors and logs). */
7
+ function attachSentryTags(tags) {
8
+ try {
9
+ if (!sentry_client_for_logging_1.sentryClientForLogging) {
10
+ (0, premature_events_1.addPrematureEvent)({ callback: attachSentryTags, inputs: [tags] });
11
+ return;
12
+ }
13
+ sentry_client_for_logging_1.sentryClientForLogging.setTags(tags);
14
+ }
15
+ catch (caught) {
16
+ console.error('Error while trying to attach Sentry tags:', caught);
17
+ return undefined;
18
+ }
19
+ }
20
+ exports.attachSentryTags = attachSentryTags;
@@ -0,0 +1,3 @@
1
+ import { EventExtraContext } from '../event-context/event-context';
2
+ /** Record an error to Sentry without throwing it. */
3
+ export declare function handleError(error: unknown, extraContext?: EventExtraContext): string | undefined;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleError = void 0;
4
+ const event_context_1 = require("../event-context/event-context");
5
+ const event_severity_1 = require("../event-context/event-severity");
6
+ const premature_events_1 = require("./premature-events");
7
+ const sentry_client_for_logging_1 = require("./sentry-client-for-logging");
8
+ /** Record an error to Sentry without throwing it. */
9
+ function handleError(error, extraContext) {
10
+ try {
11
+ if (!sentry_client_for_logging_1.sentryClientForLogging) {
12
+ (0, premature_events_1.addPrematureEvent)({
13
+ callback: handleError,
14
+ inputs: [
15
+ error,
16
+ extraContext,
17
+ ],
18
+ });
19
+ return undefined;
20
+ }
21
+ const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)({
22
+ extraContext,
23
+ severity: event_severity_1.EventSeverityEnum.Error,
24
+ });
25
+ const eventId = sentry_client_for_logging_1.sentryClientForLogging.captureException(error, scopeContext);
26
+ return eventId;
27
+ }
28
+ catch (caught) {
29
+ console.error('Error while trying to handle error with Sentry:', caught);
30
+ return undefined;
31
+ }
32
+ }
33
+ exports.handleError = handleError;
@@ -0,0 +1,8 @@
1
+ import { AnyFunction } from '@augment-vir/common';
2
+ /** An event that was triggered before setSentryClientForLogging was called. */
3
+ export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
4
+ callback: EntryPointFunction;
5
+ inputs: Parameters<EntryPointFunction>;
6
+ };
7
+ export declare function sendPrematureEvents(): void;
8
+ export declare function addPrematureEvent(prematureEvent: PrematureEvent): void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPrematureEvent = exports.sendPrematureEvents = void 0;
4
+ /**
5
+ * Used to store events before the Sentry client is setup. This is exported for testing purposes
6
+ * only, you don't need to do anything with this.
7
+ */
8
+ const prematureSentryEvents = [];
9
+ function sendPrematureEvents() {
10
+ while (prematureSentryEvents.length) {
11
+ try {
12
+ const prematureEvent = prematureSentryEvents.pop();
13
+ if (!prematureEvent) {
14
+ return;
15
+ }
16
+ prematureEvent.callback(...prematureEvent.inputs);
17
+ }
18
+ catch (caught) {
19
+ console.error('error while trying to send premature sentry events:', caught);
20
+ }
21
+ }
22
+ }
23
+ exports.sendPrematureEvents = sendPrematureEvents;
24
+ function addPrematureEvent(prematureEvent) {
25
+ prematureSentryEvents.push(prematureEvent);
26
+ }
27
+ exports.addPrematureEvent = addPrematureEvent;
@@ -0,0 +1,13 @@
1
+ import { Event as SentryEvent } from '@sentry/types';
2
+ import { EventDetails, EventExtraContext } from '../event-context/event-context';
3
+ /** Send non-error events to Sentry. */
4
+ export declare const sendLog: {
5
+ /** Sends an even to Sentry with debug severity. */
6
+ readonly debug: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
7
+ /** Sends an even to Sentry with info severity. */
8
+ readonly info: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
9
+ /** Sends an even to Sentry with warning severity. */
10
+ readonly warning: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
11
+ };
12
+ declare function sendLogToSentry(logInfo: string | Omit<SentryEvent, 'extra' | 'level'>, eventDetails: EventDetails): string | undefined;
13
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendLog = void 0;
4
+ const common_1 = require("@augment-vir/common");
5
+ const event_context_1 = require("../event-context/event-context");
6
+ const event_severity_1 = require("../event-context/event-severity");
7
+ const premature_events_1 = require("./premature-events");
8
+ const sentry_client_for_logging_1 = require("./sentry-client-for-logging");
9
+ /** Send non-error events to Sentry. */
10
+ exports.sendLog = {
11
+ /** Sends an even to Sentry with debug severity. */
12
+ [event_severity_1.EventSeverityEnum.Debug]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Debug),
13
+ /** Sends an even to Sentry with info severity. */
14
+ [event_severity_1.EventSeverityEnum.Info]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Info),
15
+ /** Sends an even to Sentry with warning severity. */
16
+ [event_severity_1.EventSeverityEnum.Warning]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Warning),
17
+ };
18
+ function wrapLogWithSeverity(severity) {
19
+ return (info, extraContext) => {
20
+ return sendLogToSentry(info, {
21
+ extraContext,
22
+ severity,
23
+ });
24
+ };
25
+ }
26
+ function sendLogToSentry(logInfo, eventDetails) {
27
+ try {
28
+ if (!sentry_client_for_logging_1.sentryClientForLogging) {
29
+ (0, premature_events_1.addPrematureEvent)({
30
+ callback: sendLogToSentry,
31
+ inputs: [
32
+ logInfo,
33
+ eventDetails,
34
+ ],
35
+ });
36
+ return undefined;
37
+ }
38
+ const scopeContext = (0, event_context_1.convertEventDetailsToSentryContext)(eventDetails);
39
+ const eventId = (0, common_1.isRuntimeTypeOf)(logInfo, 'string')
40
+ ? sentry_client_for_logging_1.sentryClientForLogging.captureMessage(logInfo, scopeContext)
41
+ : sentry_client_for_logging_1.sentryClientForLogging.captureEvent({
42
+ ...logInfo,
43
+ ...scopeContext,
44
+ });
45
+ return eventId;
46
+ }
47
+ catch (caught) {
48
+ console.error('Error while trying to send Sentry log:', caught);
49
+ return undefined;
50
+ }
51
+ }
@@ -0,0 +1,17 @@
1
+ import { MaybePromise } from '@augment-vir/common';
2
+ import { SentryDep } from '../env/execution-env';
3
+ /** The bare minimum Sentry client needed for logging events. */
4
+ export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent' | 'setTags'>;
5
+ /** Internal sentry client used for logging. */
6
+ export declare let sentryClientForLogging: SentryClientForLogging | undefined;
7
+ /**
8
+ * Asynchronously set the Sentry client for logging. When this is called, any events that were
9
+ * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
10
+ * asynchronous Sentry client setup but synchronous log and error handling.
11
+ *
12
+ * This should be called as soon as possible after you have a return value from initSentry.
13
+ *
14
+ * This can be safely called multiple times (to overwrite the previously set Sentry client) because
15
+ * previous events won't be handled multiple times.
16
+ */
17
+ export declare function setSentryClientForLogging(client: MaybePromise<SentryClientForLogging>): Promise<void>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSentryClientForLogging = exports.sentryClientForLogging = void 0;
4
+ const premature_events_1 = require("./premature-events");
5
+ /**
6
+ * Asynchronously set the Sentry client for logging. When this is called, any events that were
7
+ * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
8
+ * asynchronous Sentry client setup but synchronous log and error handling.
9
+ *
10
+ * This should be called as soon as possible after you have a return value from initSentry.
11
+ *
12
+ * This can be safely called multiple times (to overwrite the previously set Sentry client) because
13
+ * previous events won't be handled multiple times.
14
+ */
15
+ async function setSentryClientForLogging(client) {
16
+ const hadClientBefore = !!exports.sentryClientForLogging;
17
+ exports.sentryClientForLogging = await client;
18
+ if (!hadClientBefore) {
19
+ (0, premature_events_1.sendPrematureEvents)();
20
+ }
21
+ }
22
+ exports.setSentryClientForLogging = setSentryClientForLogging;
package/dist/cjs/node.js CHANGED
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.initSentry = void 0;
27
27
  const execution_env_1 = require("./env/execution-env");
28
+ const sentry_config_1 = require("./init-sentry/sentry-config");
28
29
  const event_processor_1 = require("./processing/event-processor");
29
- const sentry_config_1 = require("./processing/sentry-config");
30
30
  /**
31
31
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
32
32
  * with all the default sentry-vir integrations and configs.
@@ -14,7 +14,8 @@ hint,
14
14
  /** Optional callback for creating extra event context. */
15
15
  createUniversalContext) {
16
16
  const extraContext = {
17
- ...(0, extra_event_context_1.extractExtraEventContext)(hint.originalException),
17
+ ...(0, extra_event_context_1.extractExtraEventContext)(hint),
18
+ ...(0, extra_event_context_1.extractExtraEventContext)(event),
18
19
  ...createUniversalContext?.(),
19
20
  originalFullMessage: event.message || (0, common_1.extractErrorMessage)(hint.originalException),
20
21
  };
package/dist/esm/auto.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SentryExecutionEnvEnum } from './env/execution-env';
2
+ import { createSentryConfig } from './init-sentry/sentry-config';
2
3
  import { processSentryEvent } from './processing/event-processor';
3
- import { createSentryConfig } from './processing/sentry-config';
4
4
  /** The sentry dep import for each execution env. */
5
5
  /* c8 ignore next 6 */
6
6
  export const sentryDepByEnv = {
@@ -1,6 +1,6 @@
1
1
  import { SentryExecutionEnvEnum } from './env/execution-env';
2
+ import { createSentryConfig } from './init-sentry/sentry-config';
2
3
  import { processSentryEvent } from './processing/event-processor';
3
- import { createSentryConfig } from './processing/sentry-config';
4
4
  /**
5
5
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
6
6
  * with all the default sentry-vir integrations and configs.
@@ -1,3 +1,4 @@
1
+ import { Event, EventHint } from '@sentry/types';
1
2
  import { EventExtraContext } from './event-context';
2
3
  /**
3
4
  * Symbol used to attach extra event context to events. This is particularly useful for errors so
@@ -10,8 +11,13 @@ export type HasExtraContext = {
10
11
  };
11
12
  /** Type guard for whether any given input has extra event context. */
12
13
  export declare function hasExtraEventContext(input: unknown): input is HasExtraContext;
14
+ /**
15
+ * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
16
+ * if so, extracts it.
17
+ */
18
+ export declare function extractExtraContentFromSymbol(input: unknown): EventExtraContext | undefined;
13
19
  /**
14
20
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
15
21
  * no extra event context.
16
22
  */
17
- export declare function extractExtraEventContext(event: unknown): EventExtraContext | undefined;
23
+ export declare function extractExtraEventContext(event: EventHint | Event): EventExtraContext | undefined;
@@ -8,13 +8,35 @@ export const extraEventContextSymbol = Symbol('extra-event-context');
8
8
  export function hasExtraEventContext(input) {
9
9
  return typedHasProperty(input, extraEventContextSymbol);
10
10
  }
11
+ /**
12
+ * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
13
+ * if so, extracts it.
14
+ */
15
+ export function extractExtraContentFromSymbol(input) {
16
+ if (hasExtraEventContext(input)) {
17
+ return input[extraEventContextSymbol];
18
+ }
19
+ else {
20
+ return undefined;
21
+ }
22
+ }
11
23
  /**
12
24
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
13
25
  * no extra event context.
14
26
  */
15
27
  export function extractExtraEventContext(event) {
16
- if (hasExtraEventContext(event)) {
17
- return event[extraEventContextSymbol];
28
+ const fromRootSymbol = extractExtraContentFromSymbol(event);
29
+ const fromSubSymbol = 'originalException' in event
30
+ ? extractExtraContentFromSymbol(event.originalException)
31
+ : undefined;
32
+ const fromCapture = 'captureContext' in event ? event.captureContext : undefined;
33
+ const combined = {
34
+ ...fromRootSymbol,
35
+ ...fromSubSymbol,
36
+ ...fromCapture,
37
+ };
38
+ if (Object.keys(combined).length) {
39
+ return combined;
18
40
  }
19
41
  else {
20
42
  return undefined;
@@ -5,7 +5,10 @@ export * from './event-context/event-severity';
5
5
  export * from './event-context/extra-context.error';
6
6
  export * from './event-context/extra-event-context';
7
7
  export * from './init-sentry/base-sentry-init';
8
+ export * from './init-sentry/sentry-config';
9
+ export * from './logging/attach-tags';
10
+ export * from './logging/handle-error';
11
+ export * from './logging/send-log';
12
+ export * from './logging/sentry-client-for-logging';
8
13
  export * from './processing/event-processor';
9
14
  export * from './processing/handle-sentry-send';
10
- export * from './processing/sentry-config';
11
- export * from './processing/sentry-logger';
package/dist/esm/index.js CHANGED
@@ -5,7 +5,10 @@ export * from './event-context/event-severity';
5
5
  export * from './event-context/extra-context.error';
6
6
  export * from './event-context/extra-event-context';
7
7
  export * from './init-sentry/base-sentry-init';
8
+ export * from './init-sentry/sentry-config';
9
+ export * from './logging/attach-tags';
10
+ export * from './logging/handle-error';
11
+ export * from './logging/send-log';
12
+ export * from './logging/sentry-client-for-logging';
8
13
  export * from './processing/event-processor';
9
14
  export * from './processing/handle-sentry-send';
10
- export * from './processing/sentry-config';
11
- export * from './processing/sentry-logger';
@@ -2,7 +2,7 @@ import type { Options } from '@sentry/types';
2
2
  import { SentryDep, SentryExecutionEnvEnum } from '../env/execution-env';
3
3
  import { SentryReleaseEnvEnum } from '../env/release-env';
4
4
  import { EventExtraContextCreator } from '../event-context/event-context';
5
- import { UserOverrides } from '../processing/sentry-config';
5
+ import { UserOverrides } from './sentry-config';
6
6
  /** Configuration for initializing Sentry. */
7
7
  export type InitSentryInput = {
8
8
  /**
@@ -1,5 +1,6 @@
1
+ import { setSentryClientForLogging } from '../logging/sentry-client-for-logging';
1
2
  import { processSentryEvent } from '../processing/event-processor';
2
- import { createSentryConfig } from '../processing/sentry-config';
3
+ import { createSentryConfig } from './sentry-config';
3
4
  /**
4
5
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
5
6
  * with all the default sentry-vir integrations and configs.
@@ -15,5 +16,6 @@ export async function baseInitSentry({ dsn, releaseEnv, releaseName, sentryConfi
15
16
  }, sentryConfigOverrides, releaseEnv);
16
17
  sentryDep.init(finalSentryConfig);
17
18
  sentryDep.addGlobalEventProcessor((event, hint) => processSentryEvent(event, hint, createUniversalContext));
19
+ setSentryClientForLogging(sentryDep);
18
20
  return sentryDep;
19
21
  }
@@ -1,6 +1,6 @@
1
1
  import { mergeDeep } from '@augment-vir/common';
2
2
  import { SentryExecutionEnvEnum, } from '../env/execution-env';
3
- import { createSentryHandler } from './handle-sentry-send';
3
+ import { createSentryHandler } from '../processing/handle-sentry-send';
4
4
  /** Creates the sentry config used internally by sentry-vir. */
5
5
  // can't test config creation because it depends on execution environment
6
6
  /* c8 ignore next 60 */
@@ -0,0 +1,5 @@
1
+ import type { setTags } from '@sentry/core';
2
+ /** A list of tag names as keys and their values. Set a tag to undefined to clear it. */
3
+ export type SentryTags = Parameters<typeof setTags>[0];
4
+ /** Set tags for all future Sentry event handling (errors and logs). */
5
+ export declare function attachSentryTags(tags: SentryTags): undefined;
@@ -0,0 +1,16 @@
1
+ import { addPrematureEvent } from './premature-events';
2
+ import { sentryClientForLogging } from './sentry-client-for-logging';
3
+ /** Set tags for all future Sentry event handling (errors and logs). */
4
+ export function attachSentryTags(tags) {
5
+ try {
6
+ if (!sentryClientForLogging) {
7
+ addPrematureEvent({ callback: attachSentryTags, inputs: [tags] });
8
+ return;
9
+ }
10
+ sentryClientForLogging.setTags(tags);
11
+ }
12
+ catch (caught) {
13
+ console.error('Error while trying to attach Sentry tags:', caught);
14
+ return undefined;
15
+ }
16
+ }
@@ -0,0 +1,3 @@
1
+ import { EventExtraContext } from '../event-context/event-context';
2
+ /** Record an error to Sentry without throwing it. */
3
+ export declare function handleError(error: unknown, extraContext?: EventExtraContext): string | undefined;
@@ -0,0 +1,29 @@
1
+ import { convertEventDetailsToSentryContext, } from '../event-context/event-context';
2
+ import { EventSeverityEnum } from '../event-context/event-severity';
3
+ import { addPrematureEvent } from './premature-events';
4
+ import { sentryClientForLogging } from './sentry-client-for-logging';
5
+ /** Record an error to Sentry without throwing it. */
6
+ export function handleError(error, extraContext) {
7
+ try {
8
+ if (!sentryClientForLogging) {
9
+ addPrematureEvent({
10
+ callback: handleError,
11
+ inputs: [
12
+ error,
13
+ extraContext,
14
+ ],
15
+ });
16
+ return undefined;
17
+ }
18
+ const scopeContext = convertEventDetailsToSentryContext({
19
+ extraContext,
20
+ severity: EventSeverityEnum.Error,
21
+ });
22
+ const eventId = sentryClientForLogging.captureException(error, scopeContext);
23
+ return eventId;
24
+ }
25
+ catch (caught) {
26
+ console.error('Error while trying to handle error with Sentry:', caught);
27
+ return undefined;
28
+ }
29
+ }
@@ -0,0 +1,8 @@
1
+ import { AnyFunction } from '@augment-vir/common';
2
+ /** An event that was triggered before setSentryClientForLogging was called. */
3
+ export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
4
+ callback: EntryPointFunction;
5
+ inputs: Parameters<EntryPointFunction>;
6
+ };
7
+ export declare function sendPrematureEvents(): void;
8
+ export declare function addPrematureEvent(prematureEvent: PrematureEvent): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Used to store events before the Sentry client is setup. This is exported for testing purposes
3
+ * only, you don't need to do anything with this.
4
+ */
5
+ const prematureSentryEvents = [];
6
+ export function sendPrematureEvents() {
7
+ while (prematureSentryEvents.length) {
8
+ try {
9
+ const prematureEvent = prematureSentryEvents.pop();
10
+ if (!prematureEvent) {
11
+ return;
12
+ }
13
+ prematureEvent.callback(...prematureEvent.inputs);
14
+ }
15
+ catch (caught) {
16
+ console.error('error while trying to send premature sentry events:', caught);
17
+ }
18
+ }
19
+ }
20
+ export function addPrematureEvent(prematureEvent) {
21
+ prematureSentryEvents.push(prematureEvent);
22
+ }
@@ -0,0 +1,13 @@
1
+ import { Event as SentryEvent } from '@sentry/types';
2
+ import { EventDetails, EventExtraContext } from '../event-context/event-context';
3
+ /** Send non-error events to Sentry. */
4
+ export declare const sendLog: {
5
+ /** Sends an even to Sentry with debug severity. */
6
+ readonly debug: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
7
+ /** Sends an even to Sentry with info severity. */
8
+ readonly info: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
9
+ /** Sends an even to Sentry with warning severity. */
10
+ readonly warning: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
11
+ };
12
+ declare function sendLogToSentry(logInfo: string | Omit<SentryEvent, 'extra' | 'level'>, eventDetails: EventDetails): string | undefined;
13
+ export {};
@@ -0,0 +1,48 @@
1
+ import { isRuntimeTypeOf } from '@augment-vir/common';
2
+ import { convertEventDetailsToSentryContext, } from '../event-context/event-context';
3
+ import { EventSeverityEnum } from '../event-context/event-severity';
4
+ import { addPrematureEvent } from './premature-events';
5
+ import { sentryClientForLogging } from './sentry-client-for-logging';
6
+ /** Send non-error events to Sentry. */
7
+ export const sendLog = {
8
+ /** Sends an even to Sentry with debug severity. */
9
+ [EventSeverityEnum.Debug]: wrapLogWithSeverity(EventSeverityEnum.Debug),
10
+ /** Sends an even to Sentry with info severity. */
11
+ [EventSeverityEnum.Info]: wrapLogWithSeverity(EventSeverityEnum.Info),
12
+ /** Sends an even to Sentry with warning severity. */
13
+ [EventSeverityEnum.Warning]: wrapLogWithSeverity(EventSeverityEnum.Warning),
14
+ };
15
+ function wrapLogWithSeverity(severity) {
16
+ return (info, extraContext) => {
17
+ return sendLogToSentry(info, {
18
+ extraContext,
19
+ severity,
20
+ });
21
+ };
22
+ }
23
+ function sendLogToSentry(logInfo, eventDetails) {
24
+ try {
25
+ if (!sentryClientForLogging) {
26
+ addPrematureEvent({
27
+ callback: sendLogToSentry,
28
+ inputs: [
29
+ logInfo,
30
+ eventDetails,
31
+ ],
32
+ });
33
+ return undefined;
34
+ }
35
+ const scopeContext = convertEventDetailsToSentryContext(eventDetails);
36
+ const eventId = isRuntimeTypeOf(logInfo, 'string')
37
+ ? sentryClientForLogging.captureMessage(logInfo, scopeContext)
38
+ : sentryClientForLogging.captureEvent({
39
+ ...logInfo,
40
+ ...scopeContext,
41
+ });
42
+ return eventId;
43
+ }
44
+ catch (caught) {
45
+ console.error('Error while trying to send Sentry log:', caught);
46
+ return undefined;
47
+ }
48
+ }
@@ -0,0 +1,17 @@
1
+ import { MaybePromise } from '@augment-vir/common';
2
+ import { SentryDep } from '../env/execution-env';
3
+ /** The bare minimum Sentry client needed for logging events. */
4
+ export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent' | 'setTags'>;
5
+ /** Internal sentry client used for logging. */
6
+ export declare let sentryClientForLogging: SentryClientForLogging | undefined;
7
+ /**
8
+ * Asynchronously set the Sentry client for logging. When this is called, any events that were
9
+ * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
10
+ * asynchronous Sentry client setup but synchronous log and error handling.
11
+ *
12
+ * This should be called as soon as possible after you have a return value from initSentry.
13
+ *
14
+ * This can be safely called multiple times (to overwrite the previously set Sentry client) because
15
+ * previous events won't be handled multiple times.
16
+ */
17
+ export declare function setSentryClientForLogging(client: MaybePromise<SentryClientForLogging>): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { sendPrematureEvents } from './premature-events';
2
+ /** Internal sentry client used for logging. */
3
+ export let sentryClientForLogging;
4
+ /**
5
+ * Asynchronously set the Sentry client for logging. When this is called, any events that were
6
+ * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
7
+ * asynchronous Sentry client setup but synchronous log and error handling.
8
+ *
9
+ * This should be called as soon as possible after you have a return value from initSentry.
10
+ *
11
+ * This can be safely called multiple times (to overwrite the previously set Sentry client) because
12
+ * previous events won't be handled multiple times.
13
+ */
14
+ export async function setSentryClientForLogging(client) {
15
+ const hadClientBefore = !!sentryClientForLogging;
16
+ sentryClientForLogging = await client;
17
+ if (!hadClientBefore) {
18
+ sendPrematureEvents();
19
+ }
20
+ }
package/dist/esm/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SentryExecutionEnvEnum } from './env/execution-env';
2
+ import { createSentryConfig } from './init-sentry/sentry-config';
2
3
  import { processSentryEvent } from './processing/event-processor';
3
- import { createSentryConfig } from './processing/sentry-config';
4
4
  /**
5
5
  * Base Sentry init. Requires the Sentry module to already have been imported. Setup a sentry client
6
6
  * with all the default sentry-vir integrations and configs.
@@ -11,7 +11,8 @@ hint,
11
11
  /** Optional callback for creating extra event context. */
12
12
  createUniversalContext) {
13
13
  const extraContext = {
14
- ...extractExtraEventContext(hint.originalException),
14
+ ...extractExtraEventContext(hint),
15
+ ...extractExtraEventContext(event),
15
16
  ...createUniversalContext?.(),
16
17
  originalFullMessage: event.message || extractErrorMessage(hint.originalException),
17
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sentry-vir",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "keywords": [
5
5
  "config",
6
6
  "helper",
@@ -29,21 +29,24 @@
29
29
  "format": "virmator format",
30
30
  "publish": "virmator publish \"npm run compile && npm run test:all\"",
31
31
  "test": "virmator test-web",
32
- "test:all": "concurrently --colors --kill-others-on-fail -c auto --names types,tests,spelling,format,docs \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\"",
32
+ "test:all": "concurrently --colors --kill-others-on-fail -c auto --names types,tests,spelling,format,docs,deps \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\"",
33
33
  "test:coverage": "npm run test coverage",
34
+ "test:deps": "virmator deps check",
34
35
  "test:docs": "virmator docs check",
35
36
  "test:format": "virmator format check",
36
37
  "test:spelling": "virmator spellcheck",
37
38
  "test:types": "tsc --noEmit"
38
39
  },
39
40
  "dependencies": {
40
- "@augment-vir/common": "^19.4.2",
41
+ "@augment-vir/common": "^20.0.1",
41
42
  "@sentry/browser": "^7.73.0",
43
+ "@sentry/core": "^7.73.0",
42
44
  "@sentry/node": "^7.73.0",
43
- "type-fest": "^4.3.3"
45
+ "@sentry/types": "^7.73.0",
46
+ "type-fest": "^4.4.0"
44
47
  },
45
48
  "devDependencies": {
46
- "@augment-vir/browser-testing": "^19.4.2",
49
+ "@augment-vir/browser-testing": "^20.0.1",
47
50
  "@open-wc/testing": "^3.2.0",
48
51
  "@types/mocha": "^10.0.2",
49
52
  "@web/dev-server-esbuild": "^0.4.1",
@@ -52,6 +55,7 @@
52
55
  "@web/test-runner-playwright": "^0.10.1",
53
56
  "@web/test-runner-visual-regression": "^0.8.2",
54
57
  "cspell": "^7.3.7",
58
+ "dependency-cruiser": "^14.1.1",
55
59
  "esbuild": "^0.19.4",
56
60
  "istanbul-smart-text-reporter": "^1.1.2",
57
61
  "markdown-code-example-inserter": "^0.3.2",
@@ -64,7 +68,7 @@
64
68
  "prettier-plugin-packagejson": "^2.4.6",
65
69
  "prettier-plugin-sort-json": "^2.0.0",
66
70
  "prettier-plugin-toml": "^0.3.5",
67
- "typedoc": "^0.25.1",
68
- "virmator": "^8.0.5"
71
+ "typedoc": "^0.25.2",
72
+ "virmator": "^9.1.1"
69
73
  }
70
74
  }
@@ -1,40 +0,0 @@
1
- import { AnyFunction, MaybePromise } from '@augment-vir/common';
2
- import type { Event as SentryEvent } from '@sentry/types';
3
- import type { SentryDep } from '../env/execution-env';
4
- import { EventDetails, EventExtraContext } from '../event-context/event-context';
5
- /** The bare minimum Sentry client needed for logging events. */
6
- export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent'>;
7
- /** An event that was triggered before setSentryClientForLogging was called. */
8
- export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
9
- entryPoint: EntryPointFunction;
10
- inputs: Parameters<EntryPointFunction>;
11
- };
12
- /**
13
- * Used to store events before the Sentry client is setup. This is exported for testing purposes
14
- * only, you don't need to do anything with this.
15
- */
16
- export declare const prematureSentryEvents: PrematureEvent[];
17
- /**
18
- * Asynchronously set the Sentry client for logging. When this is called, any events that were
19
- * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
20
- * asynchronous Sentry client setup but synchronous log and error handling.
21
- *
22
- * This should be called as soon as possible after you have a return value from initSentry.
23
- *
24
- * This can be safely called multiple times (to overwrite the previously set Sentry client) because
25
- * previous events won't be handled multiple times.
26
- */
27
- export declare function setSentryClientForLogging(client: MaybePromise<SentryClientForLogging>): Promise<void>;
28
- /** Record an error to Sentry without throwing it. */
29
- export declare function handleError(error: unknown, extraContext?: EventExtraContext): string | undefined;
30
- /** Send non-error events to Sentry. */
31
- export declare const sendLog: {
32
- /** Sends an even to Sentry with debug severity. */
33
- readonly debug: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
34
- /** Sends an even to Sentry with info severity. */
35
- readonly info: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
36
- /** Sends an even to Sentry with warning severity. */
37
- readonly warning: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
38
- };
39
- declare function sendLogToSentry(logInfo: string | Omit<SentryEvent, 'extra' | 'level'>, eventDetails: EventDetails): string | undefined;
40
- export {};
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendLog = exports.handleError = exports.setSentryClientForLogging = exports.prematureSentryEvents = void 0;
4
- const common_1 = require("@augment-vir/common");
5
- const event_context_1 = require("../event-context/event-context");
6
- const event_severity_1 = require("../event-context/event-severity");
7
- let sentryClientForLogging;
8
- /**
9
- * Used to store events before the Sentry client is setup. This is exported for testing purposes
10
- * only, you don't need to do anything with this.
11
- */
12
- exports.prematureSentryEvents = [];
13
- /**
14
- * Asynchronously set the Sentry client for logging. When this is called, any events that were
15
- * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
16
- * asynchronous Sentry client setup but synchronous log and error handling.
17
- *
18
- * This should be called as soon as possible after you have a return value from initSentry.
19
- *
20
- * This can be safely called multiple times (to overwrite the previously set Sentry client) because
21
- * previous events won't be handled multiple times.
22
- */
23
- async function setSentryClientForLogging(client) {
24
- const hadClientBefore = !!sentryClientForLogging;
25
- sentryClientForLogging = await client;
26
- if (!hadClientBefore) {
27
- sendPrematureEvents();
28
- }
29
- }
30
- exports.setSentryClientForLogging = setSentryClientForLogging;
31
- function sendPrematureEvents() {
32
- while (exports.prematureSentryEvents.length) {
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);
42
- }
43
- }
44
- }
45
- /** Record an error to Sentry without throwing it. */
46
- function handleError(error, extraContext) {
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,
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);
67
- return undefined;
68
- }
69
- }
70
- exports.handleError = handleError;
71
- /** Send non-error events to Sentry. */
72
- exports.sendLog = {
73
- /** Sends an even to Sentry with debug severity. */
74
- [event_severity_1.EventSeverityEnum.Debug]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Debug),
75
- /** Sends an even to Sentry with info severity. */
76
- [event_severity_1.EventSeverityEnum.Info]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Info),
77
- /** Sends an even to Sentry with warning severity. */
78
- [event_severity_1.EventSeverityEnum.Warning]: wrapLogWithSeverity(event_severity_1.EventSeverityEnum.Warning),
79
- };
80
- function wrapLogWithSeverity(severity) {
81
- return (info, extraContext) => {
82
- return sendLogToSentry(info, {
83
- extraContext,
84
- severity,
85
- });
86
- };
87
- }
88
- function sendLogToSentry(logInfo, eventDetails) {
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);
111
- return undefined;
112
- }
113
- }
@@ -1,40 +0,0 @@
1
- import { AnyFunction, MaybePromise } from '@augment-vir/common';
2
- import type { Event as SentryEvent } from '@sentry/types';
3
- import type { SentryDep } from '../env/execution-env';
4
- import { EventDetails, EventExtraContext } from '../event-context/event-context';
5
- /** The bare minimum Sentry client needed for logging events. */
6
- export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent'>;
7
- /** An event that was triggered before setSentryClientForLogging was called. */
8
- export type PrematureEvent<EntryPointFunction extends AnyFunction = AnyFunction> = {
9
- entryPoint: EntryPointFunction;
10
- inputs: Parameters<EntryPointFunction>;
11
- };
12
- /**
13
- * Used to store events before the Sentry client is setup. This is exported for testing purposes
14
- * only, you don't need to do anything with this.
15
- */
16
- export declare const prematureSentryEvents: PrematureEvent[];
17
- /**
18
- * Asynchronously set the Sentry client for logging. When this is called, any events that were
19
- * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
20
- * asynchronous Sentry client setup but synchronous log and error handling.
21
- *
22
- * This should be called as soon as possible after you have a return value from initSentry.
23
- *
24
- * This can be safely called multiple times (to overwrite the previously set Sentry client) because
25
- * previous events won't be handled multiple times.
26
- */
27
- export declare function setSentryClientForLogging(client: MaybePromise<SentryClientForLogging>): Promise<void>;
28
- /** Record an error to Sentry without throwing it. */
29
- export declare function handleError(error: unknown, extraContext?: EventExtraContext): string | undefined;
30
- /** Send non-error events to Sentry. */
31
- export declare const sendLog: {
32
- /** Sends an even to Sentry with debug severity. */
33
- readonly debug: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
34
- /** Sends an even to Sentry with info severity. */
35
- readonly info: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
36
- /** Sends an even to Sentry with warning severity. */
37
- readonly warning: (info: Parameters<typeof sendLogToSentry>[0], extraContext?: EventExtraContext) => string | undefined;
38
- };
39
- declare function sendLogToSentry(logInfo: string | Omit<SentryEvent, 'extra' | 'level'>, eventDetails: EventDetails): string | undefined;
40
- export {};
@@ -1,108 +0,0 @@
1
- import { isRuntimeTypeOf } from '@augment-vir/common';
2
- import { convertEventDetailsToSentryContext, } from '../event-context/event-context';
3
- import { EventSeverityEnum } from '../event-context/event-severity';
4
- let sentryClientForLogging;
5
- /**
6
- * Used to store events before the Sentry client is setup. This is exported for testing purposes
7
- * only, you don't need to do anything with this.
8
- */
9
- export const prematureSentryEvents = [];
10
- /**
11
- * Asynchronously set the Sentry client for logging. When this is called, any events that were
12
- * triggered beforehand are handled. Thus, this set can be done at any time, allowing for
13
- * asynchronous Sentry client setup but synchronous log and error handling.
14
- *
15
- * This should be called as soon as possible after you have a return value from initSentry.
16
- *
17
- * This can be safely called multiple times (to overwrite the previously set Sentry client) because
18
- * previous events won't be handled multiple times.
19
- */
20
- export async function setSentryClientForLogging(client) {
21
- const hadClientBefore = !!sentryClientForLogging;
22
- sentryClientForLogging = await client;
23
- if (!hadClientBefore) {
24
- sendPrematureEvents();
25
- }
26
- }
27
- function sendPrematureEvents() {
28
- while (prematureSentryEvents.length) {
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);
38
- }
39
- }
40
- }
41
- /** Record an error to Sentry without throwing it. */
42
- export function handleError(error, extraContext) {
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,
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);
63
- return undefined;
64
- }
65
- }
66
- /** Send non-error events to Sentry. */
67
- export const sendLog = {
68
- /** Sends an even to Sentry with debug severity. */
69
- [EventSeverityEnum.Debug]: wrapLogWithSeverity(EventSeverityEnum.Debug),
70
- /** Sends an even to Sentry with info severity. */
71
- [EventSeverityEnum.Info]: wrapLogWithSeverity(EventSeverityEnum.Info),
72
- /** Sends an even to Sentry with warning severity. */
73
- [EventSeverityEnum.Warning]: wrapLogWithSeverity(EventSeverityEnum.Warning),
74
- };
75
- function wrapLogWithSeverity(severity) {
76
- return (info, extraContext) => {
77
- return sendLogToSentry(info, {
78
- extraContext,
79
- severity,
80
- });
81
- };
82
- }
83
- function sendLogToSentry(logInfo, eventDetails) {
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);
106
- return undefined;
107
- }
108
- }