withThemeSentry
Wraps the server's request handler so errors during server rendering are reported to Sentry, tagged with the theme name and the store host.
import { withThemeSentry } from '@salla.sa/twilight-theme-engine/sentry/server';In plain words
Your theme also runs on a server: every page is first built there, before the browser receives it. An error during that step never reaches the browser. withThemeSentry(handler, 'my-theme') wraps the server's request handler so those errors are reported to Sentry, tagged with your theme's name.
Like its browser twin, it sends nothing until a DSN is configured.
Signature
function withThemeSentry<T extends { fetch: (...args: any[]) => any }>(
handler: T,
theme: string
): T
// DSN: env.SENTRY_DSN (server variable) || import.meta.env.VITE_SENTRY_DSN (build time)Example
import handler from '@tanstack/react-start/server-entry';
import { withThemeSentry } from '@salla.sa/twilight-theme-engine/sentry/server';
// TanStack Start's own request handler, wrapped. Same name as initThemeSentry.
export default withThemeSentry(handler, 'my-theme');
How it behaves
app/server.tsis TanStack Start's server entry: when the file exists Start uses it, and its default export must be an object withfetch. Wrap the handler Start exports from@tanstack/react-start/server-entry.It calls
withSentryfrom the server Sentry SDK with the DSN,serverName: 'twilight-theme-<theme>', the tagssource: 'twilight-engine'andtheme, and abeforeSendthat adds astoretag (the host of the failing request's URL).beforeSendnever drops an event.The DSN comes from the server's
SENTRY_DSNvariable, then fromVITE_SENTRY_DSNbaked in at build time. With neither, the handler is still wrapped and Sentry sends nothing.A theme published through Salla runs without server variables, so there only a
VITE_SENTRY_DSNpresent when the theme is built turns reporting on.
Gotchas
Never import
@salla.sa/twilight-theme-engine/sentry/serverfrom code that reaches the browser: it imports the server-only Sentry SDK at the top level. Browser code uses initThemeSentry from/sentry/client.
Related
Starts Sentry error reporting in the shopper's browser, tagged with your theme name; does nothing unless a DSN was set when the theme was built.
twilightMiddlewareThe request middleware every theme lists first in app/start.ts; it opens the private, per-request context the rest of the engine reads.