11import { EventWorker } from '../../../lib/event-worker' ;
22import * as pkg from '../package.json' ;
33import { SentryEventWorkerTask } from '../types/sentry-event-worker-task' ;
4- import { SentryEnvelope , SentryItem } from '../types/sentry-envelope' ;
4+ import { SentryEnvelope , SentryItem , SentryHeader } from '../types/sentry-envelope' ;
55import { DefaultEventWorkerTask } from '../../default/types/default-event-worker-task' ;
66import * as WorkerNames from '../../../lib/workerNames' ;
77
@@ -27,17 +27,40 @@ export default class SentryEventWorker extends EventWorker {
2727 */
2828 this . type = 'errors/sentry' ;
2929
30- const rawEvent = b64decode ( event . payload . envelope ) ;
31- const envelope = this . parseSentryEnvelope ( rawEvent ) ;
32- this . logger . debug ( JSON . stringify ( envelope ) ) ;
30+ try {
31+ const rawEvent = b64decode ( event . payload . envelope ) ;
32+ const envelope = this . parseSentryEnvelope ( rawEvent ) ;
33+ this . logger . debug ( JSON . stringify ( envelope ) ) ;
3334
34- // Todo: For now, we only handle the first item in the envelope
35- const hawkEvent = this . transformToHawkFormat ( envelope . Header , envelope . Items [ 0 ] , event . projectId ) ;
36- this . logger . debug ( JSON . stringify ( hawkEvent ) ) ;
35+ for ( const item of envelope . Items ) {
36+ await this . handleEnvelopeItem ( envelope . Header , item , event . projectId ) ;
37+ }
3738
38- this . validate ( hawkEvent ) ;
39+ this . logger . debug ( 'All envelope items processed successfully.' ) ;
40+ }
41+ catch ( error ) {
42+ this . logger . error ( 'Error handling Sentry event task:' , error ) ;
43+ throw error ;
44+ }
45+ }
3946
40- await this . addTask ( WorkerNames . DEFAULT , hawkEvent as DefaultEventWorkerTask ) ;
47+ /**
48+ * Process the envelope item
49+ *
50+ * @param header - Sentry header
51+ * @param item - Sentry item
52+ * @param projectId - Sentry project ID
53+ */
54+ public async handleEnvelopeItem ( header : SentryHeader , item : SentryItem , projectId : string ) : Promise < void > {
55+ try {
56+ const hawkEvent = this . transformToHawkFormat ( header , item , projectId ) ;
57+ this . validate ( hawkEvent ) ;
58+ await this . addTask ( WorkerNames . DEFAULT , hawkEvent as DefaultEventWorkerTask ) ;
59+ }
60+ catch ( error ) {
61+ this . logger . error ( 'Error handling envelope item:' , JSON . stringify ( item ) , error ) ;
62+ throw error ;
63+ }
4164 }
4265
4366 /**
0 commit comments