Skip to content

Commit ac66b5a

Browse files
Bring in the vite-sentry plugin (#660)
* Sentry changes * Update documentation * Changes to include sentry-vite plugin * Docker secret * Disable if mode not production * Remove formatting change * Update docs/monitoring.md Co-authored-by: Kent C. Dodds <[email protected]> * Uncomment plugin * Uncomment commit sha vars * Formatting * Dockerfile * Replace maps * Replace ternary * Vite config update --------- Co-authored-by: Kent C. Dodds <[email protected]>
1 parent 108988f commit ac66b5a

File tree

8 files changed

+266
-184
lines changed

8 files changed

+266
-184
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ jobs:
141141
runs-on: ubuntu-22.04
142142
needs: [lint, typecheck, vitest, playwright]
143143
# only build/deploy branches on pushes
144-
if:
145-
${{ github.event_name == 'push' }}
144+
if: ${{ github.event_name == 'push' }}
146145

147146
steps:
148147
- name: ⬇️ Checkout repo
@@ -176,5 +175,6 @@ jobs:
176175
if: ${{ github.ref == 'refs/heads/main' }}
177176
run:
178177
flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }}
178+
--build-secret SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
179179
env:
180180
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

docs/monitoring.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,41 @@ You can sign up for Sentry and create a Remix project from visiting
2020
[this url](https://sentry.io/signup/?project_platform=javascript-remix) and
2121
filling out the signup form.
2222

23-
## Onboarding
23+
## Setting up the sentry-vite plugin
2424

2525
Once you see the onboarding page which has the DSN, copy that somewhere (this
26-
becomes `SENTRY_DSN`). Then click
27-
[this](https://sentry.io/orgredirect/settings/:orgslug/developer-settings/new-internal/)
28-
to create an internal integration. Give it a name and add the scope for
29-
`Releases:Admin`. Press Save, find the auth token at the bottom of the page
30-
under "Tokens", and copy that to secure location (this becomes
31-
`SENTRY_AUTH_TOKEN`). Then visit the organization settings page and copy that
32-
organization slug (`SENTRY_ORG_SLUG`).
33-
34-
Now, set the secrets in Fly.io:
26+
becomes `SENTRY_DSN`). Now, set the sentry dsn secret in Fly.io to be used as an
27+
env var during runtime:
3528

3629
```sh
37-
fly secrets set SENTRY_DSN=<your_dsn> SENTRY_AUTH_TOKEN=<your_auth_token> SENTRY_ORG=<your_org_slug> SENTRY_PROJECT=javascript-remix
30+
fly secrets set SENTRY_DSN=<your_dsn>
3831
```
3932

40-
Note that `javascript-remix` is the name of the default Remix project in Sentry
41-
and if you use a different project name you'll need to update that value here.
33+
See the guide for the remix
34+
[here](https://docs.sentry.io/platforms/javascript/guides/remix/). Run the
35+
installation wizard but note that some of the steps included already exist in
36+
this codebase so be sure to remove any duplication.
37+
38+
To generate the auth token, click
39+
[this](https://sentry.io/orgredirect/settings/:orgslug/developer-settings/new-internal/)
40+
to create an internal integration (which grants the selected capabilities to the
41+
recipient, similar to how RBAC works). Give it a name and add the scope for
42+
`Releases:Admin`. Press Save, find the auth token at the bottom of the page
43+
under "Tokens", and copy that to secure location (this becomes
44+
`SENTRY_AUTH_TOKEN`). Then visit the organization settings page and copy that
45+
organization slug (`SENTRY_ORG`), and the slug name for your project too
46+
(`SENTRY_PROJECT`).
47+
48+
Uncomment the sentry-vite plugin in `vite.config` and the build command in the
49+
'build' section of the Dockerfile, which shows how to pass the
50+
`SENTRY_AUTH_TOKEN` (below) as a docker secret, so it is available to the vite
51+
config when `npm run build` is run (you will need to do the same for
52+
`SENTRY_ORG` and `SENTRY_PROJECT`). Note that these do not need to be added to
53+
the `env.server` env vars schema, as they are only used during the build and not
54+
the runtime.
55+
56+
The plugin will create sentry releases for you and automatically associate
57+
commits during the vite build once you set the `SENTRY_AUTH_TOKEN` in
58+
[your GitHub action secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).
59+
In this setup we have utilized a simple strategy for naming releases of using
60+
the commit sha, passed in as a build arg via the GitHub action workflow.

fly.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ auto_rollback = true
1212
source = "data"
1313
destination = "/data"
1414

15-
[deploy]
16-
release_command = "node ./other/sentry-create-release"
17-
1815
[[services]]
1916
internal_port = 8080
2017
processes = [ "app" ]

other/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ RUN npm prune --omit=dev
2929
# Build the app
3030
FROM base as build
3131

32+
ARG COMMIT_SHA
33+
ENV COMMIT_SHA=$COMMIT_SHA
34+
3235
WORKDIR /myapp
3336

3437
COPY --from=deps /myapp/node_modules /myapp/node_modules
@@ -37,7 +40,11 @@ ADD prisma .
3740
RUN npx prisma generate
3841

3942
ADD . .
40-
RUN npm run build
43+
44+
# Mount the secret and set it as an environment variable and run the build
45+
RUN --mount=type=secret,id=SENTRY_AUTH_TOKEN \
46+
export SENTRY_AUTH_TOKEN=$(cat /run/secrets/SENTRY_AUTH_TOKEN) && \
47+
npm run build
4148

4249
# Finally, build the production image with minimal footprint
4350
FROM base

other/sentry-create-release.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)