Skip to content

Commit

Permalink
Add sentry error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Holi0317 committed Feb 17, 2024
1 parent 20b0b62 commit c4971eb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"wrangler": "^3.0.0"
},
"dependencies": {
"@cfworker/sentry": "^2.0.0",
"@octokit/auth-app": "^6.0.3",
"octokit": "^3.1.2"
}
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type IRequestStrict, Router, error, text } from "itty-router";
import { captureError } from "@cfworker/sentry";
import { useOctoApp } from "./octo";
import { unwrap } from "./utils";

Expand Down Expand Up @@ -39,6 +40,20 @@ export default {
return await router.handle(request, env, ctx);
} catch (error) {
console.error("Router raised exception", error);

if (env.SENTRY_DSN) {
const { posted } = captureError({
sentryDsn: env.SENTRY_DSN,
environment: "prod",
release: "release",
err: error,
request,
user: "",
});

ctx.waitUntil(posted);
}

return text("Internal server error", { status: 500 });
}
},
Expand Down
5 changes: 5 additions & 0 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ interface Env {
*/
GH_PRIVATE_KEY: string;

/**
* Sentry DSN. Optional and might not be configured
*/
SENTRY_DSN?: string;

// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
//
Expand Down

0 comments on commit c4971eb

Please sign in to comment.