Skip to content

Commit

Permalink
✨ pomelo: add sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalat committed Dec 29, 2023
1 parent 6c6c97a commit 8822a0f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pomelo/api/transactions/v1/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { VercelRequest, VercelResponse } from "@vercel/node";

import buffer from "../../../utils/buffer.js";
import { sendPushNotification } from "../../../utils/notifications.js";
import { captureException } from "../../../utils/sentry.js";
import { notificationRequest } from "../../../utils/types.js";
import { signResponse, verifySignature } from "../../../utils/verify.js";

Expand Down Expand Up @@ -40,8 +41,8 @@ export default async function notifications(request: VercelRequest, response: Ve
},
});
return signResponse(request, response.status(200), JSON.stringify(true));
} catch {
// TODO(jg): log errors..
} catch (error: unknown) {
captureException(error, { request, message: "failed to send notification to user" });
return response.status(500).end("internal server error");
}
} else {
Expand Down
25 changes: 25 additions & 0 deletions pomelo/utils/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as Sentry from "@sentry/node";
import type { VercelRequest } from "@vercel/node";

Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.ENV === "development" ? "development" : "production",
tracesSampleRate: 1,
attachStacktrace: true,
autoSessionTracking: true,
});

type ExceptionProperties = {
request: VercelRequest;
message: string;
};

export function captureException(error: unknown, { request: { url }, message }: ExceptionProperties) {
try {
Sentry.captureException(error, { tags: { url, message } });
} catch {
// ignore
}
}

export default Sentry;

0 comments on commit 8822a0f

Please sign in to comment.