Skip to content

Commit 77d999b

Browse files
committed
feat: add sentry error monitoring
1 parent b81db8e commit 77d999b

6 files changed

Lines changed: 25 additions & 1 deletion

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ RPC_URL_8453=https://example-rpc
1212
RPC_URL_42161=https://example-rpc
1313
RPC_URL_80094=https://example-rpc
1414
RPC_URL_747474=https://example-rpc
15+
# Sentry (error monitoring). Leave unset to disable.
16+
SENTRY_DSN=

bun.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@neondatabase/serverless": "0.10.4",
20+
"@sentry/cloudflare": "10.57.0",
2021
"dotenv": "16.6.1",
2122
"viem": "2.47.6"
2223
},

src/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as Sentry from '@sentry/cloudflare'
12
import { authenticateRequest } from './auth'
23
import { CACHE_CONTROL_NO_STORE } from './cache'
34
import { createPool } from './db'
@@ -52,7 +53,7 @@ async function routePriceRequest(request: Request, env: Env, pathname: string):
5253
throw new ApiError('NOT_FOUND', 'Route not found')
5354
}
5455

55-
export default {
56+
const worker = {
5657
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
5758
if (request.method === 'OPTIONS') {
5859
return optionsResponse()
@@ -110,7 +111,18 @@ export default {
110111
error: error instanceof Error ? error.message : String(error),
111112
}),
112113
)
114+
Sentry.captureException(error)
113115
return jsonError(new ApiError('INTERNAL_ERROR', 'Unexpected internal error'), withCors({ 'cache-control': CACHE_CONTROL_NO_STORE }))
114116
}
115117
},
116118
}
119+
120+
export default Sentry.withSentry(
121+
(env: Env) => ({
122+
dsn: env.SENTRY_DSN,
123+
enabled: Boolean(env.SENTRY_DSN),
124+
// Performance tracing is sampled; error capture is always on.
125+
tracesSampleRate: 0.1,
126+
}),
127+
worker,
128+
)

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type PriceSource = (typeof SOURCE_PRIORITY)[number]
1111
export interface Env {
1212
DATABASE_URL: string
1313
ENSO_API_KEY?: string
14+
SENTRY_DSN?: string
1415
[key: string]: string | undefined
1516
}
1617

wrangler.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name = "yearn-prices"
22
main = "src/index.ts"
33
compatibility_date = "2026-03-30"
4+
compatibility_flags = ["nodejs_compat"]
45

56
[observability.logs]
67
enabled = true

0 commit comments

Comments
 (0)