Skip to content

Commit 2e85356

Browse files
committed
Remove node attachment loading special case
1 parent 6c404f1 commit 2e85356

File tree

6 files changed

+11
-67
lines changed

6 files changed

+11
-67
lines changed

packages/core/src/baseclient.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
630630
this._updateSessionFromEvent(session, processedEvent);
631631
}
632632

633-
this.sendEvent(processedEvent, this._attachmentsFromScope(scope));
633+
this.sendEvent(processedEvent, scope?.getAttachments() || []);
634634
return processedEvent;
635635
})
636636
.then(null, reason => {
@@ -667,21 +667,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
667667
);
668668
}
669669

670-
/**
671-
* Loads attachments from scope
672-
*/
673-
protected _attachmentsFromScope(scope: Scope | undefined): Attachment[] {
674-
return (
675-
scope?.getAttachments()?.reduce((acc, attachment) => {
676-
if ('data' in attachment) {
677-
acc.push(attachment);
678-
}
679-
680-
return acc;
681-
}, [] as Attachment[]) || []
682-
);
683-
}
684-
685670
/**
686671
* @inheritdoc
687672
*/

packages/hub/src/scope.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import {
3-
AttachmentOptions,
3+
Attachment,
44
Breadcrumb,
55
CaptureContext,
66
Context,
@@ -87,7 +87,7 @@ export class Scope implements ScopeInterface {
8787
protected _requestSession?: RequestSession;
8888

8989
/** Attachments */
90-
protected _attachments: AttachmentOptions[] = [];
90+
protected _attachments: Attachment[] = [];
9191

9292
/**
9393
* A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
@@ -407,15 +407,15 @@ export class Scope implements ScopeInterface {
407407
/**
408408
* @inheritDoc
409409
*/
410-
public addAttachment(attachment: AttachmentOptions): this {
410+
public addAttachment(attachment: Attachment): this {
411411
this._attachments.push(attachment);
412412
return this;
413413
}
414414

415415
/**
416416
* @inheritDoc
417417
*/
418-
public getAttachments(): AttachmentOptions[] {
418+
public getAttachments(): Attachment[] {
419419
return this._attachments;
420420
}
421421

packages/node/src/client.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { SessionFlusher } from '@sentry/hub';
3-
import { Attachment, Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
4-
import { basename, logger, resolvedSyncPromise } from '@sentry/utils';
5-
import { existsSync, readFileSync } from 'fs';
3+
import { Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
4+
import { logger, resolvedSyncPromise } from '@sentry/utils';
65
import { TextEncoder } from 'util';
76

87
import { eventFromMessage, eventFromUnknownInput } from './eventbuilder';
@@ -158,35 +157,4 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
158157
this._sessionFlusher.incrementSessionStatusCount();
159158
}
160159
}
161-
162-
/**
163-
* @inheritDoc
164-
*/
165-
protected _attachmentsFromScope(scope: Scope | undefined): Attachment[] {
166-
return (
167-
scope?.getAttachments()?.map(attachment => {
168-
if ('path' in attachment && !('data' in attachment)) {
169-
if (existsSync(attachment.path)) {
170-
return {
171-
filename: attachment.filename || basename(attachment.path),
172-
data: readFileSync(attachment.path),
173-
contentType: attachment.contentType,
174-
attachmentType: attachment.attachmentType,
175-
};
176-
} else {
177-
const msg = `Missing attachment - file not found: ${attachment.path}`;
178-
logger.warn(msg);
179-
180-
return {
181-
filename: attachment.filename || basename(attachment.path),
182-
data: msg,
183-
contentType: 'text/plain',
184-
};
185-
}
186-
}
187-
188-
return attachment;
189-
}) || []
190-
);
191-
}
192160
}

packages/types/src/attachment.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
export type AttachmentOptions = Attachment | AttachmentFromPath;
2-
31
export interface Attachment {
42
data: string | Uint8Array;
53
filename: string;
64
contentType?: string;
75
attachmentType?: string;
86
}
9-
10-
interface AttachmentFromPath {
11-
path: string;
12-
filename?: string;
13-
contentType?: string;
14-
attachmentType?: string;
15-
}

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type { Attachment, AttachmentOptions } from './attachment';
1+
export type { Attachment } from './attachment';
22
export type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
33
export type { Client } from './client';
44
export type { ClientReport, Outcome, EventDropReason } from './clientreport';

packages/types/src/scope.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AttachmentOptions } from './attachment';
1+
import { Attachment } from './attachment';
22
import { Breadcrumb } from './breadcrumb';
33
import { Context, Contexts } from './context';
44
import { EventProcessor } from './eventprocessor';
@@ -164,12 +164,12 @@ export interface Scope {
164164
* Adds an attachment to the scope
165165
* @param attachment Attachment options
166166
*/
167-
addAttachment(attachment: AttachmentOptions): this;
167+
addAttachment(attachment: Attachment): this;
168168

169169
/**
170170
* Returns an array of attachments on the scope
171171
*/
172-
getAttachments(): AttachmentOptions[];
172+
getAttachments(): Attachment[];
173173

174174
/**
175175
* Clears attachments from the scope

0 commit comments

Comments
 (0)