Skip to content

Commit 301bff5

Browse files
n0strn0str
authored andcommitted
update types, add try/catch and support many envelope items
1 parent 830458f commit 301bff5

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

workers/sentry/src/index.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventWorker } from '../../../lib/event-worker';
22
import * as pkg from '../package.json';
33
import { SentryEventWorkerTask } from '../types/sentry-event-worker-task';
4-
import { SentryEnvelope, SentryItem } from '../types/sentry-envelope';
4+
import { SentryEnvelope, SentryItem, SentryHeader } from '../types/sentry-envelope';
55
import { DefaultEventWorkerTask } from '../../default/types/default-event-worker-task';
66
import * 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
/**

workers/sentry/types/sentry-envelope.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
* Structures for Sentry envelope
33
*/
44
export interface SentryEnvelope {
5-
Header: Record<string, any>;
5+
Header: SentryHeader;
66
Items: SentryItem[];
77
}
88

99
export interface SentryItem {
1010
Header: Record<string, any>;
1111
Payload: Record<string, any>;
12-
}
12+
}
13+
14+
export type SentryHeader = Record<string, any>;

0 commit comments

Comments
 (0)