Skip to content

Commit bf24740

Browse files
committed
feat(solidstart): Add sentrySolidStart plugin
1 parent 5b9d3bb commit bf24740

File tree

8 files changed

+152
-40
lines changed

8 files changed

+152
-40
lines changed

packages/solidstart/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
files: ['src/vite/**', 'src/server/**'],
1515
rules: {
1616
'@sentry-internal/sdk/no-optional-chaining': 'off',
17+
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
1718
},
1819
},
1920
],

packages/solidstart/README.md

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -157,58 +157,36 @@ render(
157157
);
158158
```
159159

160-
# Sourcemaps and Releases
160+
## Uploading Source Maps
161161

162-
To generate and upload source maps of your Solid Start app use our Vite bundler plugin.
163-
164-
1. Install the Sentry Vite plugin
165-
166-
```bash
167-
# Using npm
168-
npm install @sentry/vite-plugin --save-dev
169-
170-
# Using yarn
171-
yarn add @sentry/vite-plugin --dev
172-
```
173-
174-
2. Configure the vite plugin
175-
176-
To upload source maps you have to configure an auth token. Auth tokens can be passed to the plugin explicitly with the
177-
`authToken` option, with a `SENTRY_AUTH_TOKEN` environment variable, or with an `.env.sentry-build-plugin` file in the
178-
working directory when building your project. We recommend you add the auth token to your CI/CD environment as an
179-
environment variable.
162+
To upload source maps, add the `sentrySolidStart` plugin from `@sentry/solidstart` to your `app.config.ts` and configure
163+
an auth token. Auth tokens can be passed to the plugin explicitly with the `authToken` option, with a
164+
`SENTRY_AUTH_TOKEN` environment variable, or with an `.env.sentry-build-plugin` file in the working directory when
165+
building your project. We recommend you add the auth token to your CI/CD environment as an environment variable.
180166

181167
Learn more about configuring the plugin in our
182168
[Sentry Vite Plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin).
183169

184-
```bash
185-
// .env.sentry-build-plugin
186-
SENTRY_AUTH_TOKEN=<your auth token>
187-
SENTRY_ORG=<your org>
188-
SENTRY_PROJECT=<your project name>
189-
```
190-
191-
3. Finally, add the plugin to your `app.config.ts` file.
192-
193-
```javascript
170+
```typescript
171+
// app.config.ts
194172
import { defineConfig } from '@solidjs/start/config';
195-
import { sentryVitePlugin } from '@sentry/vite-plugin';
173+
import { sentrySolidStart } from '@sentry/solidstart';
196174

197175
export default defineConfig({
198-
// rest of your config
199176
// ...
200177

201178
vite: {
202-
build: {
203-
sourcemap: true,
204-
},
205179
plugins: [
206-
sentryVitePlugin({
207-
org: process.env.SENTRY_ORG,
208-
project: process.env.SENTRY_PROJECT,
209-
authToken: process.env.SENTRY_AUTH_TOKEN,
180+
sentrySolidStart({
181+
sourceMapsUploadOptions: {
182+
org: process.env.SENTRY_ORG,
183+
project: process.env.SENTRY_PROJECT,
184+
authToken: process.env.SENTRY_AUTH_TOKEN,
185+
},
186+
debug: true,
210187
}),
211188
],
212189
},
190+
// ...
213191
});
214192
```

packages/solidstart/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"@sentry/solid": "8.26.0",
8585
"@sentry/types": "8.26.0",
8686
"@sentry/utils": "8.26.0",
87-
"@sentry/vite-plugin": "2.19.0"
87+
"@sentry/vite-plugin": "2.22.2"
8888
},
8989
"devDependencies": {
9090
"@solidjs/router": "^0.13.4",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './server';
2+
export * from './vite';

packages/solidstart/src/index.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// exports in this file - which we do below.
44
export * from './client';
55
export * from './server';
6+
export * from './vite';
67

78
import type { Integration, Options, StackParser } from '@sentry/types';
89

packages/solidstart/src/vite/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { sentryVitePlugin } from '@sentry/vite-plugin';
2+
import type { Plugin } from 'vite';
3+
import type { SentrySolidStartPluginOptions } from './types';
4+
5+
export const sentrySolidStart = (options: SentrySolidStartPluginOptions): Plugin[] => {
6+
const sourceMapsUploadOptions = options.sourceMapsUploadOptions || {};
7+
8+
const sentryPlugins: Plugin[] = [];
9+
10+
if (process.env.NODE_ENV !== 'development') {
11+
sentryPlugins.push(
12+
{
13+
name: 'sentry-solidstart-plugin-config',
14+
config() {
15+
return {
16+
build: {
17+
sourcemap: true,
18+
},
19+
};
20+
},
21+
},
22+
sentryVitePlugin({
23+
org: sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG,
24+
project: sourceMapsUploadOptions.project ?? process.env.SENTRY_PROJECT,
25+
authToken: sourceMapsUploadOptions.authToken ?? process.env.SENTRY_AUTH_TOKEN,
26+
telemetry: sourceMapsUploadOptions.telemetry ?? true,
27+
sourcemaps: {
28+
assets: sourceMapsUploadOptions.sourcemaps?.assets ?? undefined,
29+
ignore: sourceMapsUploadOptions.sourcemaps?.ignore ?? undefined,
30+
filesToDeleteAfterUpload: sourceMapsUploadOptions.sourcemaps?.filesToDeleteAfterUpload ?? undefined,
31+
},
32+
_metaOptions: {
33+
telemetry: {
34+
metaFramework: 'solidstart',
35+
},
36+
},
37+
debug: options.debug ?? false,
38+
}),
39+
);
40+
}
41+
42+
return sentryPlugins;
43+
};

packages/solidstart/src/vite/types.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
type SourceMapsOptions = {
2+
/**
3+
* If this flag is `true`, and an auth token is detected, the Sentry SDK will
4+
* automatically generate and upload source maps to Sentry during a production build.
5+
*
6+
* @default true
7+
*/
8+
enabled?: boolean;
9+
10+
/**
11+
* The auth token to use when uploading source maps to Sentry.
12+
*
13+
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
14+
*
15+
* To create an auth token, follow this guide:
16+
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
17+
*/
18+
authToken?: string;
19+
20+
/**
21+
* The organization slug of your Sentry organization.
22+
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
23+
*/
24+
org?: string;
25+
26+
/**
27+
* The project slug of your Sentry project.
28+
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
29+
*/
30+
project?: string;
31+
32+
/**
33+
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry.
34+
* It will not collect any sensitive or user-specific data.
35+
*
36+
* @default true
37+
*/
38+
telemetry?: boolean;
39+
40+
/**
41+
* Options related to sourcemaps
42+
*/
43+
sourcemaps?: {
44+
/**
45+
* A glob or an array of globs that specify the build artifacts and source maps that will be uploaded to Sentry.
46+
*
47+
* The globbing patterns must follow the implementation of the `glob` package.
48+
* @see https://www.npmjs.com/package/glob#glob-primer
49+
*/
50+
assets?: string | Array<string>;
51+
52+
/**
53+
* A glob or an array of globs that specifies which build artifacts should not be uploaded to Sentry.
54+
*
55+
* @default [] - By default no files are ignored. Thus, all files matching the `assets` glob
56+
* or the default value for `assets` are uploaded.
57+
*
58+
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
59+
*/
60+
ignore?: string | Array<string>;
61+
62+
/**
63+
* A glob or an array of globs that specifies the build artifacts that should be deleted after the artifact
64+
* upload to Sentry has been completed.
65+
*
66+
* @default [] - By default no files are deleted.
67+
*
68+
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
69+
*/
70+
filesToDeleteAfterUpload?: string | Array<string>;
71+
};
72+
};
73+
74+
/**
75+
* Build options for the Sentry module. These options are used during build-time by the Sentry SDK.
76+
*/
77+
export type SentrySolidStartPluginOptions = {
78+
/**
79+
* Options for the Sentry Vite plugin to customize the source maps upload process.
80+
*/
81+
sourceMapsUploadOptions?: SourceMapsOptions;
82+
83+
/**
84+
* Enable debug functionality of the SDK during build-time.
85+
* Enabling this will give you, for example, logs about source maps.
86+
*/
87+
debug?: boolean;
88+
};

packages/solidstart/test/server/withServerActionInstrumentation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
spanToJSON,
1111
} from '@sentry/node';
1212
import { NodeClient } from '@sentry/node';
13-
import { solidRouterBrowserTracingIntegration } from '@sentry/solidstart/solidrouter';
1413
import { redirect } from '@solidjs/router';
1514
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
15+
import { solidRouterBrowserTracingIntegration } from '../../src/client/solidrouter';
1616

1717
const mockCaptureException = vi.spyOn(SentryNode, 'captureException').mockImplementation(() => '');
1818
const mockFlush = vi.spyOn(SentryNode, 'flush').mockImplementation(async () => true);

0 commit comments

Comments
 (0)