|
1 | 1 | import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
|
2 | 2 | import { SessionFlusher } from '@sentry/hub';
|
3 | 3 | import { AttachmentItem, Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
|
4 |
| -import { createAttachmentEnvelopeItem, logger, resolvedSyncPromise } from '@sentry/utils'; |
| 4 | +import { basename, createAttachmentEnvelopeItem, logger, resolvedSyncPromise } from '@sentry/utils'; |
| 5 | +import { existsSync, readFileSync } from 'fs'; |
5 | 6 |
|
6 | 7 | import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
|
7 | 8 | import { IS_DEBUG_BUILD } from './flags';
|
@@ -154,8 +155,17 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
|
154 | 155 | /**
|
155 | 156 | * @inheritDoc
|
156 | 157 | */
|
157 |
| - protected _getAttachments(scope: Scope | undefined): AttachmentItem[] { |
158 |
| - // TODO: load any attachments from paths... |
159 |
| - return (scope?.getAttachments() || []).map(a => createAttachmentEnvelopeItem(a)); |
| 158 | + protected _getAttachments(scope: Scope | undefined): AttachmentItem[] | undefined { |
| 159 | + return scope?.getAttachments()?.map(attachment => { |
| 160 | + let [pathOrData, options] = attachment; |
| 161 | + |
| 162 | + if (typeof pathOrData === 'string' && existsSync(pathOrData)) { |
| 163 | + options = options || {}; |
| 164 | + options.filename = basename(pathOrData); |
| 165 | + pathOrData = readFileSync(pathOrData); |
| 166 | + } |
| 167 | + |
| 168 | + return createAttachmentEnvelopeItem([pathOrData, options]); |
| 169 | + }); |
160 | 170 | }
|
161 | 171 | }
|
0 commit comments