@@ -11,6 +11,10 @@ import nodeFs from 'fs';
11
11
import { BacktraceConfiguration , BacktraceSetupConfiguration } from './BacktraceConfiguration.js' ;
12
12
import { BacktraceNodeRequestHandler } from './BacktraceNodeRequestHandler.js' ;
13
13
import { AGENT } from './agentDefinition.js' ;
14
+ import {
15
+ BacktraceFileAttachmentFactory ,
16
+ NodeFsBacktraceFileAttachmentFactory ,
17
+ } from './attachment/BacktraceFileAttachment.js' ;
14
18
import { FileAttachmentsManager } from './attachment/FileAttachmentsManager.js' ;
15
19
import { transformAttachment } from './attachment/transformAttachments.js' ;
16
20
import { FileBreadcrumbsStorage } from './breadcrumbs/FileBreadcrumbsStorage.js' ;
@@ -37,6 +41,7 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
37
41
private _listeners : Record < string , NodeJS . UnhandledRejectionListener | NodeJS . UncaughtExceptionListener > = { } ;
38
42
39
43
protected readonly storageFactory : BacktraceStorageModuleFactory ;
44
+ protected readonly fileAttachmentFactory : BacktraceFileAttachmentFactory ;
40
45
protected readonly fs : typeof nodeFs ;
41
46
42
47
protected get databaseNodeFsStorage ( ) {
@@ -46,6 +51,7 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
46
51
constructor ( clientSetup : BacktraceNodeClientSetup ) {
47
52
const storageFactory = clientSetup . storageFactory ?? new NodeFsBacktraceStorageModuleFactory ( ) ;
48
53
const fs = clientSetup . fs ?? nodeFs ;
54
+ const fileAttachmentFactory = new NodeFsBacktraceFileAttachmentFactory ( fs ) ;
49
55
const storage =
50
56
clientSetup . database ?. storage ??
51
57
( clientSetup . options . database ?. enable
@@ -72,30 +78,33 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
72
78
...clientSetup . database ?. recordSenders ?.( submission ) ,
73
79
} ) ,
74
80
recordSerializers : {
75
- report : new ReportBacktraceDatabaseRecordWithAttachmentsSerializer ( storage ) ,
76
- attachment : new AttachmentBacktraceDatabaseRecordSerializer ( fs ) ,
81
+ report : new ReportBacktraceDatabaseRecordWithAttachmentsSerializer ( fileAttachmentFactory ) ,
82
+ attachment : new AttachmentBacktraceDatabaseRecordSerializer ( fileAttachmentFactory ) ,
77
83
...clientSetup . database ?. recordSerializers ,
78
84
} ,
79
85
}
80
86
: undefined ,
81
87
...clientSetup ,
82
88
options : {
83
89
...clientSetup . options ,
84
- attachments : clientSetup . options . attachments ?. map ( transformAttachment ) ,
90
+ attachments : clientSetup . options . attachments ?. map ( transformAttachment ( fileAttachmentFactory ) ) ,
85
91
} ,
86
92
} ) ;
87
93
88
94
this . storageFactory = storageFactory ;
95
+ this . fileAttachmentFactory = fileAttachmentFactory ;
89
96
this . fs = fs ;
90
97
91
98
const breadcrumbsManager = this . modules . get ( BreadcrumbsManager ) ;
92
99
if ( breadcrumbsManager && this . sessionFiles && storage ) {
93
- breadcrumbsManager . setStorage ( FileBreadcrumbsStorage . factory ( this . sessionFiles , storage ) ) ;
100
+ breadcrumbsManager . setStorage (
101
+ FileBreadcrumbsStorage . factory ( this . sessionFiles , storage , this . fileAttachmentFactory ) ,
102
+ ) ;
94
103
}
95
104
96
105
if ( this . sessionFiles && storage && clientSetup . options . database ?. captureNativeCrashes ) {
97
106
this . addModule ( FileAttributeManager , FileAttributeManager . create ( storage ) ) ;
98
- this . addModule ( FileAttachmentsManager , FileAttachmentsManager . create ( storage ) ) ;
107
+ this . addModule ( FileAttachmentsManager , FileAttachmentsManager . create ( storage , fileAttachmentFactory ) ) ;
99
108
}
100
109
}
101
110
@@ -346,12 +355,18 @@ export class BacktraceClient extends BacktraceCoreClient<BacktraceConfiguration>
346
355
for ( const [ recordName , report , session ] of reports ) {
347
356
try {
348
357
if ( session ) {
349
- report . attachments . push ( ...FileBreadcrumbsStorage . getSessionAttachments ( session , storage ) ) ;
358
+ report . attachments . push (
359
+ ...FileBreadcrumbsStorage . getSessionAttachments ( session , this . fileAttachmentFactory ) ,
360
+ ) ;
350
361
351
362
const fileAttributes = FileAttributeManager . createFromSession ( session , storage ) ;
352
363
Object . assign ( report . attributes , await fileAttributes . get ( ) ) ;
353
364
354
- const fileAttachments = FileAttachmentsManager . createFromSession ( session , storage ) ;
365
+ const fileAttachments = FileAttachmentsManager . createFromSession (
366
+ session ,
367
+ storage ,
368
+ this . fileAttachmentFactory ,
369
+ ) ;
355
370
report . attachments . push ( ...( await fileAttachments . get ( ) ) ) ;
356
371
357
372
report . attributes [ 'application.session' ] = session . sessionId ;
0 commit comments