Skip to content

Commit

Permalink
Add code to test Sentry in CF pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Jan 24, 2025
1 parent 7a63d30 commit 6e91c66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions functions/_common/reusableHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export async function handleThumbnailRequest(
ctx: EventContext<unknown, any, Record<string, unknown>>,
extension: "png" | "svg"
) {
setTimeout(() => {
throw new Error("Testing Sentry from Cloudflare Functions")
})

const url = new URL(env.url)
const shouldCache = !url.searchParams.has("nocache")

Expand Down
19 changes: 14 additions & 5 deletions functions/_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ import { Env } from "./_common/env.js"

export const onRequest = [
// Make sure Sentry is the first middleware.
Sentry.sentryPagesPlugin<Env>((context) => ({
dsn: context.env.SENTRY_DSN,
environment: context.env.ENV,
tracesSampleRate: 0.01,
})),
Sentry.sentryPagesPlugin<Env>((context) => {
console.log(context.env.SENTRY_DSN)
console.log(context.env.ENV)
return {
debug: true,
beforeSend(event) {
console.log("Sending event to Sentry:", event)
return event
},
dsn: context.env.SENTRY_DSN,
environment: context.env.ENV,
tracesSampleRate: 0.01,
}
}),
]
1 change: 1 addition & 0 deletions functions/deleted/[slug].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Env } from "../_common/env.js"

/** Return a 404 status for tombstones of deleted pages. */
export const onRequestGet: PagesFunction<Env> = async ({ env, request }) => {
throw new Error("Testing Sentry from Cloudflare Functions")
const response = await env.ASSETS.fetch(request)
if (response.redirected || response.status !== 200) return response
return new Response(response.body, {
Expand Down

0 comments on commit 6e91c66

Please sign in to comment.