-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
48 lines (38 loc) · 952 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import Sentry, { SeverityLevel } from "@sentry/node";
export interface Input {
dsn: string;
event: Event;
}
export interface Event {
message: string;
level: string;
tags?: Tags;
errors?: (Error)[] | null;
}
export interface Tags {
[key: string]: string;
}
export interface Error {
type: string;
path: string;
details: string;
}
export const handler = async (
event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
let body = JSON.parse(event.body ?? "") as Input
// construct a sentry message
Sentry.init({ dsn: body.dsn })
let captureContext = {
level: body.event.level as SeverityLevel,
tags: body.event.tags ?? {},
errors: body.event.errors ?? [],
}
let response = Sentry.captureMessage(body.event.message, captureContext)
await Sentry.close(2000)
return {
statusCode: 200,
body: response,
}
}