Skip to content

Commit

Permalink
fix: sentry source maps for worker.mjs (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 21, 2022
1 parent 101bbac commit 8100aa3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/edge-gateway/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "IPFS edge gateway for nft.storage",
"private": true,
"type": "module",
"module": "./dist/worker.mjs",
"main": "./dist/worker.mjs",
"scripts": {
"build": "node scripts/cli.js build",
"dev": "miniflare --watch --debug",
Expand Down
3 changes: 2 additions & 1 deletion packages/edge-gateway/scripts/cli.js
Expand Up @@ -56,6 +56,7 @@ async function buildCmd(opts) {
outfile: path.join(__dirname, '..', 'dist', 'worker.mjs'),
legalComments: 'external',
define: {
SENTRY_RELEASE: JSON.stringify(sentryRelease),
VERSION: JSON.stringify(pkg.version),
COMMITHASH: JSON.stringify(git.long(__dirname)),
BRANCH: JSON.stringify(git.branch(__dirname)),
Expand All @@ -81,7 +82,7 @@ async function buildCmd(opts) {
ignoreMissing: true,
})
await cli.releases.uploadSourceMaps(sentryRelease, {
include: ['./dist'],
include: [path.join(__dirname, '..', 'dist')],
ext: ['map', 'mjs'],
})
await cli.releases.finalize(sentryRelease)
Expand Down
11 changes: 7 additions & 4 deletions packages/edge-gateway/src/env.js
Expand Up @@ -6,7 +6,8 @@ import { Logging } from './logs.js'
* @typedef {Object} EnvInput
* @property {string} IPFS_GATEWAYS
* @property {string} GATEWAY_HOSTNAME
* @property {string} VERSION
* @property {string} SENTRY_RELEASE
* @property {string} VERSION SENTRY_RELEASE
* @property {string} COMMITHASH
* @property {string} BRANCH
* @property {string} DEBUG
Expand Down Expand Up @@ -43,7 +44,7 @@ import { Logging } from './logs.js'
* @param {import('.').Ctx} ctx
*/
export function envAll(request, env, ctx) {
env.sentry = getSentry(request, env)
env.sentry = getSentry(request, env, ctx)
env.ipfsGateways = JSON.parse(env.IPFS_GATEWAYS)
env.gatewayMetricsDurable = env.GATEWAYMETRICS
env.summaryMetricsDurable = env.SUMMARYMETRICS
Expand All @@ -63,15 +64,17 @@ export function envAll(request, env, ctx) {
*
* @param {Request} request
* @param {Env} env
* @param {import('.').Ctx} ctx
*/
function getSentry(request, env) {
function getSentry(request, env, ctx) {
if (!env.SENTRY_DSN) {
return
}

return new Toucan({
request,
dsn: env.SENTRY_DSN,
context: ctx,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
debug: false,
Expand All @@ -83,7 +86,7 @@ function getSentry(request, env) {
filename: frame.filename.substring(1),
}),
},
release: env.VERSION,
release: env.SENTRY_RELEASE,
pkg,
})
}
Expand Down

0 comments on commit 8100aa3

Please sign in to comment.