Skip to content

Commit 74e2982

Browse files
s1gr1dandreiborza
andauthored
feat(solidstart)!: Default to --import setup and add autoInjectServerSentry (#14862)
This PR adds a `withSentry` wrapper for SolidStart's config to build and place `instrument.server.ts` alongside the server build output so that it doesn't have to be placed in `/public` anymore to be discoverable. The setup is changed to be aligned with Nuxt. First, the `instrument.server.ts` file is added to the build output (the sentry release injection file needs to be copied as well - this is not ideal at the moment as there **could** be other imports as well, but it's okay for now) Then, there are two options to set up the SDK: 1. Users provide an `--import` CLI flag to their start command like this: ```node --import ./.output/server/instrument.server.mjs .output/server/index.mjs``` 2. Users can add `autoInjectServerSentry: 'top-level-import'` and the Sentry config will be imported at the top of the server entry ```typescript // app.config.ts import { defineConfig } from '@solidjs/start/config'; import { withSentry } from '@sentry/solidstart'; export default defineConfig(withSentry( { /* ... */ }, { autoInjectServerSentry: 'top-level-import' // optional }) ); ``` --- builds on top of the idea in this PR: #13784 --------- Co-authored-by: Andrei Borza <andrei.borza@sentry.io>
1 parent e8e84ea commit 74e2982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1752
-64
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,50 @@
1212

1313
Work in this release was contributed by @aloisklink, @arturovt, @benjick and @maximepvrt. Thank you for your contributions!
1414

15+
- **feat(solidstart)!: Default to `--import` setup and add `autoInjectServerSentry` ([#14862](https://github.com/getsentry/sentry-javascript/pull/14862))**
16+
17+
To enable the SolidStart SDK, wrap your SolidStart Config with `withSentry`. The `sentrySolidStartVite` plugin is now automatically
18+
added by `withSentry` and you can pass the Sentry build-time options like this:
19+
20+
```js
21+
import { defineConfig } from '@solidjs/start/config';
22+
import { withSentry } from '@sentry/solidstart';
23+
24+
export default defineConfig(
25+
withSentry(
26+
{
27+
/* Your SolidStart config options... */
28+
},
29+
{
30+
// Options for setting up source maps
31+
org: process.env.SENTRY_ORG,
32+
project: process.env.SENTRY_PROJECT,
33+
authToken: process.env.SENTRY_AUTH_TOKEN,
34+
},
35+
),
36+
);
37+
```
38+
39+
With the `withSentry` wrapper, the Sentry server config should not be added to the `public` directory anymore.
40+
Add the Sentry server config in `src/instrument.server.ts`. Then, the server config will be placed inside the server build output as `instrument.server.mjs`.
41+
42+
Now, there are two options to set up the SDK:
43+
44+
1. **(recommended)** Provide an `--import` CLI flag to the start command like this (path depends on your server setup):
45+
`node --import ./.output/server/instrument.server.mjs .output/server/index.mjs`
46+
2. Add `autoInjectServerSentry: 'top-level-import'` and the Sentry config will be imported at the top of the server entry (comes with tracing limitations)
47+
```js
48+
withSentry(
49+
{
50+
/* Your SolidStart config options... */
51+
},
52+
{
53+
// Optional: Install Sentry with a top-level import
54+
autoInjectServerSentry: 'top-level-import',
55+
},
56+
);
57+
```
58+
1559
## 8.45.0
1660

1761
- feat(core): Add `handled` option to `captureConsoleIntegration` ([#14664](https://github.com/getsentry/sentry-javascript/pull/14664))
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { sentrySolidStartVite } from '@sentry/solidstart';
1+
import { withSentry } from '@sentry/solidstart';
22
import { defineConfig } from '@solidjs/start/config';
33

4-
export default defineConfig({
5-
ssr: false,
6-
vite: {
7-
plugins: [sentrySolidStartVite()],
8-
},
9-
});
4+
export default defineConfig(
5+
withSentry({
6+
ssr: false,
7+
middleware: './src/middleware.ts',
8+
}),
9+
);

dev-packages/e2e-tests/test-applications/solidstart-spa/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.0.0",
44
"scripts": {
55
"clean": "pnpx rimraf node_modules pnpm-lock.yaml .vinxi .output",
6-
"dev": "NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi dev",
7-
"build": "vinxi build && sh ./post_build.sh",
8-
"preview": "HOST=localhost PORT=3030 NODE_OPTIONS='--import ./src/instrument.server.mjs' vinxi start",
6+
"build": "vinxi build && sh post_build.sh",
7+
"preview": "HOST=localhost PORT=3030 vinxi start",
8+
"start:import": "HOST=localhost PORT=3030 node --import ./.output/server/instrument.server.mjs .output/server/index.mjs",
99
"test:prod": "TEST_ENV=production playwright test",
1010
"test:build": "pnpm install && pnpm build",
1111
"test:assert": "pnpm test:prod"

dev-packages/e2e-tests/test-applications/solidstart-spa/playwright.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
22

33
const config = getPlaywrightConfig({
4-
startCommand: 'pnpm preview',
4+
startCommand: 'pnpm start:import',
55
port: 3030,
66
});
77

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { sentryBeforeResponseMiddleware } from '@sentry/solidstart';
2+
import { createMiddleware } from '@solidjs/start/middleware';
3+
4+
export default createMiddleware({
5+
onBeforeResponse: [sentryBeforeResponseMiddleware()],
6+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
dist
3+
.solid
4+
.output
5+
.vercel
6+
.netlify
7+
.vinxi
8+
9+
# Environment
10+
.env
11+
.env*.local
12+
13+
# dependencies
14+
/node_modules
15+
/.pnp
16+
.pnp.js
17+
18+
# IDEs and editors
19+
/.idea
20+
.project
21+
.classpath
22+
*.launch
23+
.settings/
24+
25+
# Temp
26+
gitignore
27+
28+
# testing
29+
/coverage
30+
31+
# misc
32+
.DS_Store
33+
.env.local
34+
.env.development.local
35+
.env.test.local
36+
.env.production.local
37+
38+
npm-debug.log*
39+
yarn-debug.log*
40+
yarn-error.log*
41+
42+
/test-results/
43+
/playwright-report/
44+
/playwright/.cache/
45+
46+
!*.d.ts
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SolidStart
2+
3+
Everything you need to build a Solid project, powered by [`solid-start`](https://start.solidjs.com);
4+
5+
## Creating a project
6+
7+
```bash
8+
# create a new project in the current directory
9+
npm init solid@latest
10+
11+
# create a new project in my-app
12+
npm init solid@latest my-app
13+
```
14+
15+
## Developing
16+
17+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a
18+
development server:
19+
20+
```bash
21+
npm run dev
22+
23+
# or start the server and open the app in a new browser tab
24+
npm run dev -- --open
25+
```
26+
27+
## Building
28+
29+
Solid apps are built with _presets_, which optimise your project for deployment to different environments.
30+
31+
By default, `npm run build` will generate a Node app that you can run with `npm start`. To use a different preset, add
32+
it to the `devDependencies` in `package.json` and specify in your `app.config.js`.
33+
34+
## Testing
35+
36+
Tests are written with `vitest`, `@solidjs/testing-library` and `@testing-library/jest-dom` to extend expect with some
37+
helpful custom matchers.
38+
39+
To run them, simply start:
40+
41+
```sh
42+
npm test
43+
```
44+
45+
## This project was created with the [Solid CLI](https://solid-cli.netlify.app)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { withSentry } from '@sentry/solidstart';
2+
import { defineConfig } from '@solidjs/start/config';
3+
4+
export default defineConfig(
5+
withSentry(
6+
{},
7+
{
8+
autoInjectServerSentry: 'top-level-import',
9+
},
10+
),
11+
);

0 commit comments

Comments
 (0)