-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(solidstart): Add solidstart sentry vite plugin
- Loading branch information
1 parent
f452423
commit 3627b54
Showing
16 changed files
with
389 additions
and
115 deletions.
There are no files selected for viewing
82 changes: 11 additions & 71 deletions
82
dev-packages/e2e-tests/test-applications/solidstart/src/routes/client-error.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,15 @@ | ||
import * as Sentry from '@sentry/solidstart'; | ||
import type { ParentProps } from 'solid-js'; | ||
import { ErrorBoundary, createSignal, onMount } from 'solid-js'; | ||
|
||
const SentryErrorBoundary = Sentry.withSentryErrorBoundary(ErrorBoundary); | ||
|
||
const [count, setCount] = createSignal(1); | ||
const [caughtError, setCaughtError] = createSignal(false); | ||
|
||
export default function ClientErrorPage() { | ||
return ( | ||
<SampleErrorBoundary> | ||
{caughtError() && ( | ||
<Throw error={`Error ${count()} thrown from Sentry ErrorBoundary in Solid Start E2E test app`} /> | ||
)} | ||
<section class="bg-gray-100 text-gray-700 p-8"> | ||
<div class="flex flex-col items-start space-x-2"> | ||
<button | ||
class="border rounded-lg px-2 mb-2 border-red-500 text-red-500 cursor-pointer" | ||
id="caughtErrorBtn" | ||
onClick={() => setCaughtError(true)} | ||
> | ||
Throw caught error | ||
</button> | ||
</div> | ||
<div class="flex flex-col items-start space-x-2"> | ||
<button | ||
class="border rounded-lg px-2 mb-2 border-red-500 text-red-500 cursor-pointer" | ||
id="errorBtn" | ||
onClick={() => { | ||
throw new Error('Error thrown from Solid Start E2E test app'); | ||
}} | ||
> | ||
Throw uncaught error | ||
</button> | ||
</div> | ||
</section> | ||
</SampleErrorBoundary> | ||
); | ||
} | ||
|
||
function Throw(props: { error: string }) { | ||
onMount(() => { | ||
throw new Error(props.error); | ||
}); | ||
return null; | ||
} | ||
|
||
function SampleErrorBoundary(props: ParentProps) { | ||
return ( | ||
<SentryErrorBoundary | ||
fallback={(error, reset) => ( | ||
<section class="bg-gray-100 text-gray-700 p-8"> | ||
<h1 class="text-2xl font-bold">Error Boundary Fallback</h1> | ||
<div class="flex items-center space-x-2 mb-4"> | ||
<code>{error.message}</code> | ||
</div> | ||
<button | ||
id="errorBoundaryResetBtn" | ||
class="border rounded-lg px-2 border-gray-900" | ||
onClick={() => { | ||
setCount(count() + 1); | ||
setCaughtError(false); | ||
reset(); | ||
}} | ||
> | ||
Reset | ||
</button> | ||
</section> | ||
)} | ||
> | ||
{props.children} | ||
</SentryErrorBoundary> | ||
<div class="flex flex-col items-start space-x-2"> | ||
<button | ||
class="border rounded-lg px-2 mb-2 border-red-500 text-red-500 cursor-pointer" | ||
id="errorBtn" | ||
onClick={() => { | ||
throw new Error('Uncaught error thrown from Solid Start E2E test app'); | ||
}} | ||
> | ||
Throw uncaught error | ||
</button> | ||
</div> | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
dev-packages/e2e-tests/test-applications/solidstart/src/routes/error-boundary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as Sentry from '@sentry/solidstart'; | ||
import type { ParentProps } from 'solid-js'; | ||
import { ErrorBoundary, createSignal, onMount } from 'solid-js'; | ||
|
||
const SentryErrorBoundary = Sentry.withSentryErrorBoundary(ErrorBoundary); | ||
|
||
const [count, setCount] = createSignal(1); | ||
const [caughtError, setCaughtError] = createSignal(false); | ||
|
||
export default function ErrorBoundaryTestPage() { | ||
return ( | ||
<SampleErrorBoundary> | ||
{caughtError() && ( | ||
<Throw error={`Error ${count()} thrown from Sentry ErrorBoundary in Solid Start E2E test app`} /> | ||
)} | ||
<section class="bg-gray-100 text-gray-700 p-8"> | ||
<div class="flex flex-col items-start space-x-2"> | ||
<button | ||
class="border rounded-lg px-2 mb-2 border-red-500 text-red-500 cursor-pointer" | ||
id="caughtErrorBtn" | ||
onClick={() => setCaughtError(true)} | ||
> | ||
Throw caught error | ||
</button> | ||
</div> | ||
</section> | ||
</SampleErrorBoundary> | ||
); | ||
} | ||
|
||
function Throw(props: { error: string }) { | ||
onMount(() => { | ||
throw new Error(props.error); | ||
}); | ||
return null; | ||
} | ||
|
||
function SampleErrorBoundary(props: ParentProps) { | ||
return ( | ||
<SentryErrorBoundary | ||
fallback={(error, reset) => ( | ||
<section class="bg-gray-100 text-gray-700 p-8"> | ||
<h1 class="text-2xl font-bold">Error Boundary Fallback</h1> | ||
<div class="flex items-center space-x-2 mb-4"> | ||
<code>{error.message}</code> | ||
</div> | ||
<button | ||
id="errorBoundaryResetBtn" | ||
class="border rounded-lg px-2 border-gray-900" | ||
onClick={() => { | ||
setCount(count() + 1); | ||
setCaughtError(false); | ||
reset(); | ||
}} | ||
> | ||
Reset | ||
</button> | ||
</section> | ||
)} | ||
> | ||
{props.children} | ||
</SentryErrorBoundary> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './server'; | ||
export * from './vite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './sentrySolidStartVite'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Plugin } from 'vite'; | ||
import { makeSourceMapsVitePlugin } from './sourceMaps'; | ||
import type { SentrySolidStartPluginOptions } from './types'; | ||
|
||
/** | ||
* Various Sentry vite plugins to be used for SolidStart. | ||
*/ | ||
export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions): Plugin[] => { | ||
const sentryPlugins: Plugin[] = []; | ||
|
||
if (process.env.NODE_ENV !== 'development') { | ||
if (options.sourceMapsUploadOptions?.enabled ?? true) { | ||
sentryPlugins.push(...makeSourceMapsVitePlugin(options)); | ||
} | ||
} | ||
|
||
return sentryPlugins; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { sentryVitePlugin } from '@sentry/vite-plugin'; | ||
import type { Plugin } from 'vite'; | ||
import type { SentrySolidStartPluginOptions } from './types'; | ||
|
||
/** | ||
* A Sentry plugin for SolidStart to enable source maps and use | ||
* @sentry/vite-plugin to automatically upload source maps to Sentry. | ||
* @param {SourceMapsOptions} options | ||
*/ | ||
export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { | ||
const { authToken, debug, org, project, sourceMapsUploadOptions } = options; | ||
return [ | ||
{ | ||
name: 'sentry-solidstart-source-maps', | ||
apply: 'build', | ||
enforce: 'post', | ||
config(config) { | ||
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap; | ||
if (debug && sourceMapsPreviouslyNotEnabled) { | ||
// eslint-disable-next-line no-console | ||
console.log('[Sentry SolidStart Plugin] Enabling source map generation'); | ||
if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`[Sentry SolidStart PLugin] We recommend setting the \`sourceMapsUploadOptions.filesToDeleteAfterUpload\` option to clean up source maps after uploading. | ||
[Sentry SolidStart Plugin] Otherwise, source maps might be deployed to production, depending on your configuration`, | ||
); | ||
} | ||
} | ||
return { | ||
...config, | ||
build: { | ||
...config.build, | ||
sourcemap: true, | ||
}, | ||
}; | ||
}, | ||
}, | ||
...sentryVitePlugin({ | ||
org: org ?? process.env.SENTRY_ORG, | ||
project: project ?? process.env.SENTRY_PROJECT, | ||
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, | ||
telemetry: sourceMapsUploadOptions?.telemetry ?? true, | ||
sourcemaps: { | ||
filesToDeleteAfterUpload: sourceMapsUploadOptions?.filesToDeleteAfterUpload ?? undefined, | ||
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps, | ||
}, | ||
_metaOptions: { | ||
telemetry: { | ||
metaFramework: 'solidstart', | ||
}, | ||
}, | ||
debug: debug ?? false, | ||
...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions, | ||
}), | ||
]; | ||
} |
Oops, something went wrong.