Skip to content

Commit ccfd78e

Browse files
committed
Fix sentry
1 parent 8bce870 commit ccfd78e

23 files changed

Lines changed: 1642 additions & 1124 deletions

.github/workflows/deploy.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ jobs:
4949

5050
steps:
5151
- uses: actions/checkout@v6
52+
with:
53+
fetch-depth: 0
5254
- name: Install pnpm
5355
uses: pnpm/action-setup@v6
5456
with:
55-
version: 10
57+
version: 11.5.2
5658
- name: Use Node.js
5759
uses: actions/setup-node@v6
5860
with:
@@ -97,13 +99,16 @@ jobs:
9799
if: ${{ github.event.inputs.deploy-web == 'true' }}
98100
env:
99101
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
102+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
103+
SENTRY_BROWSER_DSN: ${{ secrets.SENTRY_BROWSER_DSN }}
100104
MAXMIND_ACCOUNT_ID: ${{ secrets.MAXMIND_ACCOUNT_ID }}
101105
MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }}
102106
- name: Deploy worker
103107
run: pnpm run deploy:worker
104108
if: ${{ github.event.inputs.deploy-worker == 'true' }}
105109
env:
106110
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
111+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
107112
- name: Save GeoIP cache
108113
if: always()
109114
uses: actions/cache/save@v5

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: Install pnpm
5757
uses: pnpm/action-setup@v6
5858
with:
59-
version: 10
59+
version: 11.5.2
6060
- name: Use Node.js
6161
uses: actions/setup-node@v6
6262
with:
@@ -116,13 +116,16 @@ jobs:
116116
if: ${{ github.event.inputs.deploy-web == 'true' }}
117117
env:
118118
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
119+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
120+
SENTRY_BROWSER_DSN: ${{ secrets.SENTRY_BROWSER_DSN }}
119121
MAXMIND_ACCOUNT_ID: ${{ secrets.MAXMIND_ACCOUNT_ID }}
120122
MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }}
121123
- name: Deploy worker
122124
run: pnpm run deploy:worker
123125
if: ${{ github.event.inputs.deploy-worker == 'true' }}
124126
env:
125127
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
128+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
126129
- name: Save GeoIP cache
127130
if: always()
128131
uses: actions/cache/save@v5

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ ARG ENV=production
77
ARG HOST=localhost:3000
88
ARG NODE_ENV=production
99
ARG NODE_VERSION=24
10+
ARG SENTRY_BROWSER_DSN=
11+
ARG SENTRY_RELEASE=development
1012
ARG TRANSPORT=https
1113

12-
FROM alpine:3.23 AS base
14+
FROM alpine:3.24 AS base
1315

1416
LABEL maintainer="HifiWifi LLC"
1517
LABEL fly_launch_runtime="Fastify"
@@ -27,6 +29,8 @@ ARG ENV=production
2729
ARG HOST=localhost:3000
2830
ARG NODE_ENV=production
2931
ARG NODE_VERSION
32+
ARG SENTRY_BROWSER_DSN=
33+
ARG SENTRY_RELEASE=development
3034
ARG TRANSPORT=https
3135

3236
# RUN echo "@testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
@@ -54,6 +58,9 @@ RUN pnpm --filter=@breadcrum/web deploy --prod ./deploy/web
5458
# Final stage for app image
5559
FROM base
5660

61+
ARG SENTRY_RELEASE=development
62+
ENV SENTRY_RELEASE=${SENTRY_RELEASE}
63+
5764
# Copy built application from deploy directory
5865
COPY --from=build /usr/src/app/deploy/web /usr/src/app
5966

packages/web/client/globals/global.client.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
/// <reference lib="dom" />
22

3+
import * as Sentry from '@sentry/browser'
34
// @ts-expect-error - No type definitions available for mine.css
45
import { toggleTheme } from 'mine.css'
56
import 'fragmentions'
67
import { html } from 'htm/preact'
78
import { render } from 'preact'
89
import { Header } from '../components/header/index.js'
910

11+
const sentryDsn = process.env['SENTRY_BROWSER_DSN']
12+
13+
if (sentryDsn) {
14+
Sentry.init({
15+
dsn: sentryDsn,
16+
environment: process.env['SENTRY_ENVIRONMENT'] || undefined,
17+
release: process.env['SENTRY_RELEASE'] || undefined,
18+
dataCollection: {
19+
// userInfo: false,
20+
// httpBodies: [],
21+
},
22+
})
23+
}
24+
1025
// @ts-expect-error - Adding toggleTheme to global window object
1126
window.toggleTheme = toggleTheme
1227

packages/web/client/globals/global.vars.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ const host = process.env['HOST'] ?? 'localhost:3000'
5757
/** @type {string} */
5858
const baseUrl = `${transport}://${host}`
5959
/** @type {string} */
60+
const sentryEnvironment = process.env['SENTRY_ENVIRONMENT'] ?? process.env['ENV'] ?? process.env['NODE_ENV'] ?? 'development'
61+
/** @type {string} */
6062
/** @type {Record<string, string>} */
6163
export const browser = {
6264
'process.env.TRANSPORT': transport,
6365
'process.env.HOST': host,
66+
'process.env.SENTRY_BROWSER_DSN': process.env['SENTRY_BROWSER_DSN'] ?? '',
67+
'process.env.SENTRY_ENVIRONMENT': sentryEnvironment,
68+
'process.env.SENTRY_RELEASE': process.env['SENTRY_RELEASE'] ?? '',
6469
}
6570

6671
/** @type {() => Promise<GlobalVars>} */

packages/web/config/env-schema.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ 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_BROWSER_DSN: {
104+
type: 'string',
105+
},
106+
SENTRY_RELEASE: {
107+
type: 'string',
108+
},
100109
MAXMIND_ACCOUNT_ID: {
101110
type: 'string',
102111
},

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 --run migrate -- --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'

0 commit comments

Comments
 (0)