This SDK is considered
This package is a wrapper around @sentry/node
for the server and @sentry/solid
for the client side, with added
functionality related to Solid Start.
If the setup through the wizard doesn't work for you, you can also set up the SDK manually.
Install the Sentry Solid Start SDK:
# Using npm
npm install @sentry/solidstart
# Using yarn
yarn add @sentry/solidstart
Initialize the SDK in entry-client.jsx
import * as Sentry from '@sentry/solidstart';
import { solidRouterBrowserTracingIntegration } from '@sentry/solidstart/solidrouter';
import { mount, StartClient } from '@solidjs/start/client';
Sentry.init({
dsn: '__PUBLIC_DSN__',
integrations: [solidRouterBrowserTracingIntegration()],
tracesSampleRate: 1.0, // Capture 100% of the transactions
});
mount(() => <StartClient />, document.getElementById('app'));
Create an instrument file named instrument.server.mjs
and add your initialization code for the server-side SDK.
import * as Sentry from '@sentry/solidstart';
Sentry.init({
dsn: 'https://[email protected]/4507459091824640',
tracesSampleRate: 1.0, // Capture 100% of the transactions
});
Complete the setup by adding the Sentry middlware to your src/middleware.ts
file:
import { sentryBeforeResponseMiddleware } from '@sentry/solidstart/middleware';
import { createMiddleware } from '@solidjs/start/middleware';
export default createMiddleware({
onBeforeResponse: [
sentryBeforeResponseMiddleware(),
// Add your other middleware handlers after `sentryBeforeResponseMiddleware`
],
});
And don't forget to specify ./src/middleware.ts
in your app.config.ts
:
import { defineConfig } from '@solidjs/start/config';
export default defineConfig({
// ...
middleware: './src/middleware.ts',
});
The Sentry middleware enhances the data collected by Sentry on the server side by enabling distributed tracing between the client and server.
Then run your app
NODE_OPTIONS='--import=./instrument.server.mjs' yarn start
# or
NODE_OPTIONS='--require=./instrument.server.js' yarn start
The Solid Router instrumentation uses the Solid Router library to create navigation spans to ensure you collect meaningful performance data about the health of your page loads and associated requests.
Wrap Router
, MemoryRouter
or HashRouter
from @solidjs/router
using withSentryRouterRouting
. This creates a
higher order component, which will enable Sentry to reach your router context.
import { withSentryRouterRouting } from '@sentry/solidstart/solidrouter';
import { Route, Router } from '@solidjs/router';
const SentryRouter = Sentry.withSentryRouterRouting(Router);
render(
() => (
<SentryRouter>
<Route path="/" component={App} />
...
</SentryRouter>
),
document.getElementById('root'),
);
To automatically capture exceptions from inside a component tree and render a fallback component, wrap the native Solid
JS ErrorBoundary
component with Sentry.withSentryErrorBoundary
.
import * as Sentry from '@sentry/solidstart';
import { ErrorBoundary } from 'solid-js';
Sentry.init({
dsn: '__PUBLIC_DSN__',
tracesSampleRate: 1.0, // Capture 100% of the transactions
});
const SentryErrorBoundary = Sentry.withSentryErrorBoundary(ErrorBoundary);
render(
() => (
<SentryErrorBoundary fallback={err => <div>Error: {err.message}</div>}>
<ProblematicComponent />
</SentryErrorBoundary>
),
document.getElementById('root'),
);
To generate and upload source maps of your Solid Start app use our Vite bundler plugin.
- Install the Sentry Vite plugin
# Using npm
npm install @sentry/vite-plugin --save-dev
# Using yarn
yarn add @sentry/vite-plugin --dev
- Configure the vite plugin
To upload source maps you have to configure an auth token. Auth tokens can be passed to the plugin explicitly with the
authToken
option, with a SENTRY_AUTH_TOKEN
environment variable, or with an .env.sentry-build-plugin
file in the
working directory when building your project. We recommend you add the auth token to your CI/CD environment as an
environment variable.
Learn more about configuring the plugin in our Sentry Vite Plugin documentation.
// .env.sentry-build-plugin
SENTRY_AUTH_TOKEN=<your auth token>
SENTRY_ORG=<your org>
SENTRY_PROJECT=<your project name>
- Finally, add the plugin to your
app.config.ts
file.
import { defineConfig } from '@solidjs/start/config';
import { sentryVitePlugin } from '@sentry/vite-plugin';
export default defineConfig({
// rest of your config
// ...
vite: {
build: {
sourcemap: true,
},
plugins: [
sentryVitePlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
}),
],
},
});