Skip to content

Commit 7d18396

Browse files
committed
Fix sentry
1 parent 8bce870 commit 7d18396

18 files changed

Lines changed: 1526 additions & 1122 deletions

knip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ignore": [],
3-
"ignoreBinaries": ["flyctl", "eslint"],
3+
"ignoreBinaries": ["eslint"],
44
"ignoreUnresolved": ["spec", "lcov"],
55
"ignoreDependencies": [],
66
"ignoreWorkspaces": [],

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"node": ">=24.0.0"
1212
},
1313
"devDependencies": {
14-
"releasearoni": "^0.1.0",
14+
"@sentry/cli": "^3.5.1",
1515
"knip": "^6.7.0",
1616
"neostandard": "^0.12.0",
17-
"npm-run-all2": "^8.0.1"
17+
"npm-run-all2": "^8.0.1",
18+
"releasearoni": "^0.1.0"
1819
},
1920
"funding": {
2021
"type": "individual",
@@ -46,9 +47,10 @@
4647
"build": "pnpm run -r build",
4748
"migrate": "pnpm run -r migrate",
4849
"start": "pnpm run watch",
49-
"deploy": "run-s deploy:*",
50-
"deploy:web": "flyctl deploy --config ./packages/web/fly.toml --dockerfile ./packages/web/Dockerfile",
51-
"deploy:worker": "flyctl deploy --config ./packages/worker/fly.toml --dockerfile ./packages/worker/Dockerfile",
50+
"deploy-all": "run-s deploy:*",
51+
"deploy:web": "./scripts/deploy-with-sentry.sh ./packages/web/fly.toml ./packages/web/Dockerfile",
52+
"deploy:worker": "./scripts/deploy-with-sentry.sh ./packages/worker/fly.toml ./packages/worker/Dockerfile",
53+
"sentry:login": "sentry-cli login",
5254
"knip": "knip --dependencies",
5355
"new-blogpost": "node scripts/create-blogpost.js --title",
5456
"publish-draft": "node scripts/publish-blogpost.js",

packages/web/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ ARG ENV=production
77
ARG HOST=localhost:3000
88
ARG NODE_ENV=production
99
ARG NODE_VERSION=24
10+
ARG SENTRY_RELEASE=development
1011
ARG TRANSPORT=https
1112

12-
FROM alpine:3.23 AS base
13+
FROM alpine:3.24 AS base
1314

1415
LABEL maintainer="HifiWifi LLC"
1516
LABEL fly_launch_runtime="Fastify"
@@ -54,6 +55,9 @@ RUN pnpm --filter=@breadcrum/web deploy --prod ./deploy/web
5455
# Final stage for app image
5556
FROM base
5657

58+
ARG SENTRY_RELEASE=development
59+
ENV SENTRY_RELEASE=${SENTRY_RELEASE}
60+
5761
# Copy built application from deploy directory
5862
COPY --from=build /usr/src/app/deploy/web /usr/src/app
5963

packages/web/config/env-schema.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export const envSchema = /** @type {const} @satisfies {JSONSchema} */ ({
9797
type: 'string',
9898
default: 'deployment.environment=development',
9999
},
100+
SENTRY_DSN: {
101+
type: 'string',
102+
},
103+
SENTRY_RELEASE: {
104+
type: 'string',
105+
},
100106
MAXMIND_ACCOUNT_ID: {
101107
type: 'string',
102108
},

packages/web/fly.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ swap_size_mb = 1024
2222
NODE_VERSION = "24"
2323

2424
[deploy]
25-
release_command = "pnpm run migrate --no-config"
25+
release_command = "./node_modules/.bin/postgrator --no-config"
2626

2727
[env]
2828
ENV = "production"
@@ -62,7 +62,7 @@ swap_size_mb = 1024
6262
[[services.tcp_checks]]
6363
interval = "15s"
6464
timeout = "2s"
65-
grace_period = "1s"
65+
grace_period = "15s"
6666
restart_limit = 0
6767

6868
[[services.http_checks]]

packages/web/otel.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import { RuntimeNodeInstrumentation } from '@opentelemetry/instrumentation-runti
77
import { HostMetrics } from '@opentelemetry/host-metrics'
88
import { metrics } from '@opentelemetry/api'
99

10+
const sentryDsn = process.env['SENTRY_DSN']
11+
const sentryEnvironment = process.env['SENTRY_ENVIRONMENT'] ?? process.env['ENV'] ?? process.env['NODE_ENV']
12+
const sentryRelease = process.env['SENTRY_RELEASE']
13+
14+
if (sentryDsn) {
15+
const Sentry = await import('@sentry/node')
16+
Sentry.init({
17+
dsn: sentryDsn,
18+
environment: sentryEnvironment,
19+
release: sentryRelease,
20+
skipOpenTelemetrySetup: true,
21+
})
22+
}
23+
1024
/*
1125
// Tracing boilerplate.
1226
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'

packages/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@opentelemetry/sdk-node": "catalog:",
3838
"@passwordless-id/webauthn": "^2.3.1",
3939
"@preact/signals": "^2.3.2",
40+
"@sentry/node": "catalog:",
4041
"@tanstack/preact-query": "^5.100.5",
4142
"abstract-cache-redis": "catalog:",
4243
"clean-deep": "^3.4.0",

packages/web/plugins/sentry.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import fp from 'fastify-plugin'
2+
3+
export default fp(async function sentryPlugin (fastify) {
4+
if (!fastify.config.SENTRY_DSN) return
5+
6+
const Sentry = await import('@sentry/node')
7+
Sentry.setupFastifyErrorHandler(fastify)
8+
}, {
9+
name: 'sentry',
10+
dependencies: ['env'],
11+
})

packages/worker/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
ARG ENV=production
77
ARG NODE_ENV=production
88
ARG NODE_VERSION=24
9+
ARG SENTRY_RELEASE=development
910

10-
FROM alpine:3.23 AS base
11+
FROM alpine:3.24 AS base
1112

1213
LABEL maintainer="HifiWifi"
1314
LABEL fly_launch_runtime="Fastify"
@@ -47,6 +48,9 @@ RUN pnpm --filter=@breadcrum/worker deploy --prod ./deploy/worker
4748
# Final stage for app image
4849
FROM base
4950

51+
ARG SENTRY_RELEASE=development
52+
ENV SENTRY_RELEASE=${SENTRY_RELEASE}
53+
5054
# Copy the worker package from the build image to the final image
5155
COPY --from=build /usr/src/app/deploy/worker /usr/src/app
5256

packages/worker/config/env-schema.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export const envSchema = /** @type {const} @satisfies {JSONSchema} */ ({
5151
type: 'string',
5252
default: 'deployment.environment=development',
5353
},
54+
SENTRY_DSN: {
55+
type: 'string',
56+
},
57+
SENTRY_RELEASE: {
58+
type: 'string',
59+
},
5460
EPISODE_WORKER_CONCURRENCY: {
5561
type: 'integer',
5662
default: 2,

0 commit comments

Comments
 (0)