Skip to content

Commit

Permalink
Add Sentry. Closes #2 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber authored Nov 5, 2023
1 parent 6a1b01a commit 2589794
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ WORKDIR /app

# Set production environment
ENV NODE_ENV="production"
ENV SENTRY_ENVIRONMENT="production"

# Throw-away build stage to reduce size of final image
FROM base as build
Expand Down
21 changes: 20 additions & 1 deletion bin/station-wallet-screening.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@ import http from 'node:http'
import { once } from 'node:events'
import { createHandler } from '../index.js'
import assert from 'node:assert'
import Sentry from '@sentry/node'
import fs from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

const {
PORT = 3000,
CHAINALYSIS_API_KEY
CHAINALYSIS_API_KEY,
SENTRY_ENVIRONMENT = 'development'
} = process.env

const pkg = JSON.parse(
await fs.readFile(
fileURLToPath(new URL('../package.json', import.meta.url)),
'utf8'
)
)

Sentry.init({
dsn: 'https://a12a79e133de58d233f796c6ce0a5072@o1408530.ingest.sentry.io/4506173874307072',
release: pkg.version,
environment: SENTRY_ENVIRONMENT,
tracesSampleRate: 0.1
})

assert(CHAINALYSIS_API_KEY)

const server = http.createServer(createHandler({
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { STATUS_CODES } from 'node:http'
import assert from 'node:assert'
import Sentry from '@sentry/node'

const handler = async (req, res, apiKey, fetch, log) => {
const address = req.url.split('/')[1].trim()
Expand All @@ -25,6 +26,7 @@ export const createHandler = ({
}) => (req, res) => {
handler(req, res, apiKey, fetch, log).catch(err => {
log(err)
Sentry.captureException(err)
res.statusCode = 500
res.end('Internal Server Error')
})
Expand Down
89 changes: 86 additions & 3 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
"@flydotio/dockerfile": "^0.4.10",
"mocha": "^10.2.0",
"standard": "^17.1.0"
},
"dependencies": {
"@sentry/node": "^7.77.0"
}
}

0 comments on commit 2589794

Please sign in to comment.