sentry-vir 4.0.3 → 4.1.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.
@@ -1,6 +1,7 @@
1
1
  import { type JsonCompatibleObject, type PartialWithUndefined } from '@augment-vir/common';
2
- import { type ScopeContext, type setTags } from '@sentry/core';
2
+ import { type Attachment, type ScopeContext, type setTags } from '@sentry/core';
3
3
  import { type EventSeverityEnum } from './event-severity.js';
4
+ export type { Attachment } from '@sentry/core';
4
5
  /**
5
6
  * Used for all extra context types. While keys must be strings, values can be whatever but must be
6
7
  * JSON compatible.
@@ -9,12 +10,13 @@ export type EventExtraContext = JsonCompatibleObject;
9
10
  /** Allowed tag value types for Sentry event tags. */
10
11
  export type EventTags = Parameters<typeof setTags>[0];
11
12
  /**
12
- * Combined context and tags parameter used for event logging functions. Both properties are
13
- * optional.
13
+ * Combined context, tags, and attachments parameter used for event logging functions. All
14
+ * properties are optional.
14
15
  */
15
16
  export type EventContextAndTags = PartialWithUndefined<{
16
17
  context: EventExtraContext;
17
18
  tags: EventTags;
19
+ attachments: ReadonlyArray<Attachment>;
18
20
  }>;
19
21
  /** Function that generates extra event context. */
20
22
  export type EventExtraContextCreator = () => EventExtraContext;
@@ -22,6 +24,7 @@ export type EventExtraContextCreator = () => EventExtraContext;
22
24
  export type EventDetails = {
23
25
  extraContext?: EventExtraContext | undefined;
24
26
  tags?: EventTags | undefined;
27
+ attachments?: ReadonlyArray<Attachment> | undefined;
25
28
  severity: EventSeverityEnum;
26
29
  };
27
30
  /** Options for creating contexts. Used internally. */
@@ -1,5 +1,6 @@
1
+ import { type Attachment } from '@sentry/core';
1
2
  import { type EventContextAndTags, type EventExtraContext, type EventTags } from './event-context.js';
2
- import { extraEventContextSymbol, extraEventTagsSymbol } from './extra-event-context.js';
3
+ import { extraEventAttachmentsSymbol, extraEventContextSymbol, extraEventTagsSymbol } from './extra-event-context.js';
3
4
  /**
4
5
  * Constructs an error with extra event context attached to it in the same way that
5
6
  * throwWithExtraContext attaches data.
@@ -14,6 +15,7 @@ import { extraEventContextSymbol, extraEventTagsSymbol } from './extra-event-con
14
15
  export declare class ExtraContextError extends Error {
15
16
  readonly [extraEventContextSymbol]: EventExtraContext | undefined;
16
17
  readonly [extraEventTagsSymbol]: EventTags | undefined;
18
+ readonly [extraEventAttachmentsSymbol]: ReadonlyArray<Attachment> | undefined;
17
19
  constructor(message: string, extraData: EventContextAndTags);
18
20
  }
19
21
  /**
@@ -1,5 +1,5 @@
1
1
  import { ensureError } from '@augment-vir/common';
2
- import { extraEventContextSymbol, extraEventTagsSymbol, } from './extra-event-context.js';
2
+ import { extraEventAttachmentsSymbol, extraEventContextSymbol, extraEventTagsSymbol, } from './extra-event-context.js';
3
3
  /**
4
4
  * Constructs an error with extra event context attached to it in the same way that
5
5
  * throwWithExtraContext attaches data.
@@ -14,6 +14,7 @@ import { extraEventContextSymbol, extraEventTagsSymbol, } from './extra-event-co
14
14
  export class ExtraContextError extends Error {
15
15
  [extraEventContextSymbol];
16
16
  [extraEventTagsSymbol];
17
+ [extraEventAttachmentsSymbol];
17
18
  constructor(message, extraData) {
18
19
  super(message);
19
20
  if (extraData.context) {
@@ -22,6 +23,9 @@ export class ExtraContextError extends Error {
22
23
  if (extraData.tags) {
23
24
  this[extraEventTagsSymbol] = extraData.tags;
24
25
  }
26
+ if (extraData.attachments) {
27
+ this[extraEventAttachmentsSymbol] = extraData.attachments;
28
+ }
25
29
  }
26
30
  }
27
31
  /**
@@ -36,5 +40,8 @@ export function throwWithExtraContext(originalError, extraData) {
36
40
  if (extraData.tags) {
37
41
  error[extraEventTagsSymbol] = extraData.tags;
38
42
  }
43
+ if (extraData.attachments) {
44
+ error[extraEventAttachmentsSymbol] = extraData.attachments;
45
+ }
39
46
  throw error;
40
47
  }
@@ -1,4 +1,4 @@
1
- import { type Event, type EventHint } from '@sentry/core';
1
+ import { type Attachment, type Event, type EventHint } from '@sentry/core';
2
2
  import { type EventExtraContext, type EventTags } from './event-context.js';
3
3
  /**
4
4
  * Symbol used to attach extra event context to events. This is particularly useful for errors so
@@ -10,6 +10,11 @@ export declare const extraEventContextSymbol: unique symbol;
10
10
  * attaching tag data to thrown errors.
11
11
  */
12
12
  export declare const extraEventTagsSymbol: unique symbol;
13
+ /**
14
+ * Symbol used to attach extra event attachments to events. Used alongside extraEventContextSymbol
15
+ * for attaching file data to thrown errors.
16
+ */
17
+ export declare const extraEventAttachmentsSymbol: unique symbol;
13
18
  /** Simply describes an object that has extra event context. */
14
19
  export type HasExtraContext = {
15
20
  [extraEventContextSymbol]: EventExtraContext;
@@ -18,10 +23,16 @@ export type HasExtraContext = {
18
23
  export type HasExtraTags = {
19
24
  [extraEventTagsSymbol]: EventTags;
20
25
  };
26
+ /** Simply describes an object that has extra event attachments. */
27
+ export type HasExtraAttachments = {
28
+ [extraEventAttachmentsSymbol]: ReadonlyArray<Attachment>;
29
+ };
21
30
  /** Type guard for whether any given input has extra event context. */
22
31
  export declare function hasExtraEventContext(input: unknown): input is HasExtraContext;
23
32
  /** Type guard for whether any given input has extra event tags. */
24
33
  export declare function hasExtraEventTags(input: unknown): input is HasExtraTags;
34
+ /** Type guard for whether any given input has extra event attachments. */
35
+ export declare function hasExtraEventAttachments(input: unknown): input is HasExtraAttachments;
25
36
  /**
26
37
  * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
27
38
  * if so, extracts it.
@@ -32,6 +43,11 @@ export declare function extractExtraContentFromSymbol(input: unknown): EventExtr
32
43
  * extracts them.
33
44
  */
34
45
  export declare function extractExtraTagsFromSymbol(input: unknown): EventTags | undefined;
46
+ /**
47
+ * Checks if extra event attachments have been injected into the input via
48
+ * extraEventAttachmentsSymbol and, if so, extracts them.
49
+ */
50
+ export declare function extractExtraAttachmentsFromSymbol(input: unknown): ReadonlyArray<Attachment> | undefined;
35
51
  /**
36
52
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
37
53
  * no extra event context.
@@ -42,3 +58,8 @@ export declare function extractExtraEventContext(event: EventHint | Event): Even
42
58
  * extra event tags.
43
59
  */
44
60
  export declare function extractExtraEventTags(event: EventHint | Event): EventTags | undefined;
61
+ /**
62
+ * Tries to extract extra event attachments via extraEventAttachmentsSymbol. Returns undefined if
63
+ * there are no extra event attachments.
64
+ */
65
+ export declare function extractExtraEventAttachments(event: EventHint | Event): ReadonlyArray<Attachment> | undefined;
@@ -9,6 +9,11 @@ export const extraEventContextSymbol = Symbol('extra-event-context');
9
9
  * attaching tag data to thrown errors.
10
10
  */
11
11
  export const extraEventTagsSymbol = Symbol('extra-event-tags');
12
+ /**
13
+ * Symbol used to attach extra event attachments to events. Used alongside extraEventContextSymbol
14
+ * for attaching file data to thrown errors.
15
+ */
16
+ export const extraEventAttachmentsSymbol = Symbol('extra-event-attachments');
12
17
  /** Type guard for whether any given input has extra event context. */
13
18
  export function hasExtraEventContext(input) {
14
19
  return check.hasKey(input, extraEventContextSymbol) && !!input[extraEventContextSymbol];
@@ -17,6 +22,10 @@ export function hasExtraEventContext(input) {
17
22
  export function hasExtraEventTags(input) {
18
23
  return check.hasKey(input, extraEventTagsSymbol) && !!input[extraEventTagsSymbol];
19
24
  }
25
+ /** Type guard for whether any given input has extra event attachments. */
26
+ export function hasExtraEventAttachments(input) {
27
+ return check.hasKey(input, extraEventAttachmentsSymbol) && !!input[extraEventAttachmentsSymbol];
28
+ }
20
29
  /**
21
30
  * Checks if extra event context has been injected into the input via extraEventContextSymbol and,
22
31
  * if so, extracts it.
@@ -39,6 +48,16 @@ export function extractExtraTagsFromSymbol(input) {
39
48
  }
40
49
  return undefined;
41
50
  }
51
+ /**
52
+ * Checks if extra event attachments have been injected into the input via
53
+ * extraEventAttachmentsSymbol and, if so, extracts them.
54
+ */
55
+ export function extractExtraAttachmentsFromSymbol(input) {
56
+ if (hasExtraEventAttachments(input)) {
57
+ return input[extraEventAttachmentsSymbol];
58
+ }
59
+ return undefined;
60
+ }
42
61
  /**
43
62
  * Tries to extract extra event context via extraEventContextSymbol. Returns undefined if there is
44
63
  * no extra event context.
@@ -83,3 +102,23 @@ export function extractExtraEventTags(event) {
83
102
  return undefined;
84
103
  }
85
104
  }
105
+ /**
106
+ * Tries to extract extra event attachments via extraEventAttachmentsSymbol. Returns undefined if
107
+ * there are no extra event attachments.
108
+ */
109
+ export function extractExtraEventAttachments(event) {
110
+ const fromRootSymbol = extractExtraAttachmentsFromSymbol(event);
111
+ const fromSubSymbol = 'originalException' in event
112
+ ? extractExtraAttachmentsFromSymbol(event.originalException)
113
+ : undefined;
114
+ const combined = [
115
+ ...(fromRootSymbol || []),
116
+ ...(fromSubSymbol || []),
117
+ ];
118
+ if (combined.length) {
119
+ return combined;
120
+ }
121
+ else {
122
+ return undefined;
123
+ }
124
+ }
@@ -1,6 +1,7 @@
1
1
  import { extractErrorMessage } from '@augment-vir/common';
2
2
  import { convertEventDetailsToSentryContext, } from '../event-context/event-context.js';
3
3
  import { EventSeverityEnum } from '../event-context/event-severity.js';
4
+ import { extractExtraAttachmentsFromSymbol } from '../event-context/extra-event-context.js';
4
5
  import { LoggingState, logToConsoleWithoutSentry } from '../processing/log-to-console.js';
5
6
  import { addPrematureEvent } from './premature-events.js';
6
7
  import { sentryClientForLogging } from './sentry-client-for-logging.js';
@@ -34,7 +35,19 @@ function internalHandleError(error, eventOptions, options) {
34
35
  tags: eventOptions?.tags,
35
36
  severity: EventSeverityEnum.Error,
36
37
  }, options);
37
- const eventId = sentryClientForLogging.captureException(error, scopeContext);
38
+ const client = sentryClientForLogging;
39
+ const allAttachments = [
40
+ ...(eventOptions?.attachments || []),
41
+ ...(extractExtraAttachmentsFromSymbol(error) || []),
42
+ ];
43
+ const eventId = allAttachments.length
44
+ ? client.withScope((scope) => {
45
+ allAttachments.forEach((attachment) => {
46
+ scope.addAttachment(attachment);
47
+ });
48
+ return client.captureException(error, scopeContext);
49
+ })
50
+ : client.captureException(error, scopeContext);
38
51
  return eventId;
39
52
  }
40
53
  catch (caught) {
@@ -20,6 +20,7 @@ function wrapLogWithSeverity(severity) {
20
20
  return sendLogToSentry(info, {
21
21
  extraContext: eventOptions?.context,
22
22
  tags: eventOptions?.tags,
23
+ attachments: eventOptions?.attachments,
23
24
  severity,
24
25
  }, {
25
26
  wasSentPrematurely: false,
@@ -54,12 +55,23 @@ function sendLogToSentry(logInfo, eventDetails, options) {
54
55
  return undefined;
55
56
  }
56
57
  const scopeContext = convertEventDetailsToSentryContext(eventDetails, options);
57
- const eventId = check.isString(resolvedLogInfo)
58
- ? sentryClientForLogging.captureMessage(resolvedLogInfo, scopeContext)
59
- : sentryClientForLogging.captureEvent({
60
- ...resolvedLogInfo,
61
- ...scopeContext,
62
- });
58
+ const client = sentryClientForLogging;
59
+ function captureWithClient() {
60
+ return check.isString(resolvedLogInfo)
61
+ ? client.captureMessage(resolvedLogInfo, scopeContext)
62
+ : client.captureEvent({
63
+ ...resolvedLogInfo,
64
+ ...scopeContext,
65
+ });
66
+ }
67
+ const eventId = eventDetails.attachments?.length
68
+ ? client.withScope((scope) => {
69
+ eventDetails.attachments?.forEach((attachment) => {
70
+ scope.addAttachment(attachment);
71
+ });
72
+ return captureWithClient();
73
+ })
74
+ : captureWithClient();
63
75
  return eventId;
64
76
  }
65
77
  catch (caught) {
@@ -1,7 +1,7 @@
1
1
  import { type MaybePromise } from '@augment-vir/common';
2
2
  import { type SentryDep } from '../env/execution-env.js';
3
3
  /** The bare minimum Sentry client needed for logging events. */
4
- export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent' | 'setTags'>;
4
+ export type SentryClientForLogging = Pick<SentryDep, 'captureMessage' | 'captureException' | 'captureEvent' | 'setTags' | 'withScope'>;
5
5
  /** Internal sentry client used for logging. */
6
6
  export declare let sentryClientForLogging: SentryClientForLogging | undefined;
7
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sentry-vir",
3
- "version": "4.0.3",
3
+ "version": "4.1.0",
4
4
  "description": "Easily use Sentry.",
5
5
  "keywords": [
6
6
  "config",
@@ -44,55 +44,55 @@
44
44
  "test:update": "npm test update"
45
45
  },
46
46
  "dependencies": {
47
- "@augment-vir/assert": "^31.68.1",
48
- "@augment-vir/common": "^31.68.1",
49
- "@sentry/browser": "^10.42.0",
50
- "@sentry/core": "^10.42.0",
51
- "@sentry/node": "^10.42.0",
52
- "date-vir": "^8.2.0",
53
- "type-fest": "^5.4.4"
47
+ "@augment-vir/assert": "^31.68.2",
48
+ "@augment-vir/common": "^31.68.2",
49
+ "@sentry/browser": "^10.46.0",
50
+ "@sentry/core": "^10.46.0",
51
+ "@sentry/node": "^10.46.0",
52
+ "date-vir": "^8.2.1",
53
+ "type-fest": "^5.5.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@augment-vir/test": "^31.68.1",
57
- "@eslint/eslintrc": "^3.3.4",
56
+ "@augment-vir/test": "^31.68.2",
57
+ "@eslint/eslintrc": "^3.3.5",
58
58
  "@eslint/js": "^9.39.2",
59
59
  "@stylistic/eslint-plugin": "^5.10.0",
60
60
  "@stylistic/eslint-plugin-ts": "^4.4.1",
61
- "@typescript-eslint/eslint-plugin": "^8.56.1",
61
+ "@typescript-eslint/eslint-plugin": "^8.57.2",
62
62
  "@web/dev-server-esbuild": "^1.0.5",
63
63
  "@web/test-runner": "^0.20.2",
64
64
  "@web/test-runner-commands": "^0.9.0",
65
65
  "@web/test-runner-playwright": "^0.11.1",
66
66
  "@web/test-runner-visual-regression": "^0.10.0",
67
67
  "cspell": "^9.7.0",
68
- "dependency-cruiser": "^17.3.8",
69
- "esbuild": "^0.27.3",
68
+ "dependency-cruiser": "^17.3.10",
69
+ "esbuild": "^0.27.4",
70
70
  "eslint": "^9.39.2",
71
71
  "eslint-config-prettier": "^10.1.8",
72
- "eslint-plugin-jsdoc": "^62.7.1",
72
+ "eslint-plugin-jsdoc": "^62.8.1",
73
73
  "eslint-plugin-monorepo-cop": "^1.0.2",
74
- "eslint-plugin-playwright": "^2.9.0",
74
+ "eslint-plugin-playwright": "^2.10.1",
75
75
  "eslint-plugin-prettier": "^5.5.5",
76
76
  "eslint-plugin-require-extensions": "^0.1.3",
77
- "eslint-plugin-sonarjs": "^4.0.1",
78
- "eslint-plugin-unicorn": "^63.0.0",
77
+ "eslint-plugin-sonarjs": "^4.0.2",
78
+ "eslint-plugin-unicorn": "^64.0.0",
79
79
  "istanbul-smart-text-reporter": "^1.1.5",
80
80
  "markdown-code-example-inserter": "^3.0.3",
81
- "npm-check-updates": "^19.6.3",
81
+ "npm-check-updates": "^19.6.6",
82
82
  "prettier": "~3.3.3",
83
83
  "prettier-plugin-interpolated-html-tags": "^2.0.1",
84
84
  "prettier-plugin-jsdoc": "^1.8.0",
85
- "prettier-plugin-multiline-arrays": "^4.1.4",
85
+ "prettier-plugin-multiline-arrays": "^4.1.5",
86
86
  "prettier-plugin-organize-imports": "^4.3.0",
87
87
  "prettier-plugin-packagejson": "^3.0.2",
88
88
  "prettier-plugin-sort-json": "^4.2.0",
89
89
  "prettier-plugin-toml": "^2.0.6",
90
90
  "runstorm": "^1.0.0",
91
- "typedoc": "^0.28.17",
91
+ "typedoc": "^0.28.18",
92
92
  "typescript": "^5.9.3",
93
- "typescript-eslint": "^8.56.1",
94
- "virmator": "^14.8.3",
95
- "vite": "^7.3.1"
93
+ "typescript-eslint": "^8.57.1",
94
+ "virmator": "^14.10.3",
95
+ "vite": "^8.0.3"
96
96
  },
97
97
  "engines": {
98
98
  "node": ">=22"