File tree Expand file tree Collapse file tree 7 files changed +39
-26
lines changed Expand file tree Collapse file tree 7 files changed +39
-26
lines changed Original file line number Diff line number Diff line change @@ -620,7 +620,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
620
620
this . _updateSessionFromEvent ( session , processedEvent ) ;
621
621
}
622
622
623
- this . _sendEvent ( processedEvent , this . _getAttachments ( scope ) ) ;
623
+ this . _sendEvent ( processedEvent , this . _attachmentsFromScope ( scope ) ) ;
624
624
return processedEvent ;
625
625
} )
626
626
. then ( null , reason => {
@@ -657,8 +657,10 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
657
657
) ;
658
658
}
659
659
660
- /** */
661
- protected _getAttachments ( scope : Scope | undefined ) : AttachmentItem [ ] | undefined {
660
+ /**
661
+ * Loads attachment items from scope
662
+ */
663
+ protected _attachmentsFromScope ( scope : Scope | undefined ) : AttachmentItem [ ] | undefined {
662
664
return scope ?. getAttachments ( ) ?. map ( a => createAttachmentEnvelopeItem ( a ) ) ;
663
665
}
664
666
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
155
155
/**
156
156
* @inheritDoc
157
157
*/
158
- protected _getAttachments ( scope : Scope | undefined ) : AttachmentItem [ ] | undefined {
158
+ protected _attachmentsFromScope ( scope : Scope | undefined ) : AttachmentItem [ ] | undefined {
159
159
return scope ?. getAttachments ( ) ?. map ( attachment => {
160
160
let [ pathOrData , options ] = attachment ;
161
161
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ const GZIP_THRESHOLD = 1024 * 32;
30
30
31
31
/**
32
32
* Gets a stream from a Uint8Array or string
33
- * We don't have Readable.from in earlier versions of node
33
+ * Readable.from was added in node.sj v12.3.0, v10.17.0
34
34
*/
35
35
function streamFromBody ( body : Uint8Array | string ) : Readable {
36
36
return new Readable ( {
Original file line number Diff line number Diff line change @@ -160,9 +160,20 @@ export interface Scope {
160
160
*/
161
161
clearBreadcrumbs ( ) : this;
162
162
163
+ /**
164
+ * Adds an attachment to the scope
165
+ * @param pathOrData A Uint8Array containing the attachment bytes
166
+ * @param options Attachment options
167
+ */
163
168
addAttachment ( pathOrData : string | Uint8Array , options ?: AttachmentOptions ) : this;
164
169
170
+ /**
171
+ * Returns an array of attachments on the scope
172
+ */
165
173
getAttachments ( ) : Attachment [ ] ;
166
174
175
+ /**
176
+ * Clears attachments from the scope
177
+ */
167
178
clearAttachments ( ) : this;
168
179
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- import { Envelope } from '@sentry/types' ;
1
+ import { Attachment , AttachmentItem , Envelope } from '@sentry/types' ;
2
2
3
3
import { isPrimitive } from './is' ;
4
4
@@ -98,3 +98,23 @@ function concatBuffers(buffers: Uint8Array[]): Uint8Array {
98
98
99
99
return merged ;
100
100
}
101
+
102
+ /**
103
+ * Creates attachment envelope items
104
+ */
105
+ export function createAttachmentEnvelopeItem ( attachment : Attachment ) : AttachmentItem {
106
+ const [ pathOrData , options ] = attachment ;
107
+
108
+ const buffer = typeof pathOrData === 'string' ? new TextEncoder ( ) . encode ( pathOrData ) : pathOrData ;
109
+
110
+ return [
111
+ {
112
+ type : 'attachment' ,
113
+ length : buffer . length ,
114
+ filename : options ?. filename || 'No filename' ,
115
+ content_type : options ?. contentType ,
116
+ attachment_type : options ?. attachmentType ,
117
+ } ,
118
+ buffer ,
119
+ ] ;
120
+ }
Original file line number Diff line number Diff line change @@ -23,4 +23,3 @@ export * from './env';
23
23
export * from './envelope' ;
24
24
export * from './clientreport' ;
25
25
export * from './ratelimit' ;
26
- export * from './attachment' ;
You can’t perform that action at this time.
0 commit comments