Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions frameworks/react-cra/add-ons/sentry/assets/instrument.server.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import * as Sentry from '@sentry/tanstackstart-react'
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options/#sendDefaultPii
sendDefaultPii: true,
tracesSampleRate: 1.0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 1.0,
})

const sentryDsn = import.meta.env?.VITE_SENTRY_DSN ?? process.env.VITE_SENTRY_DSN

if (!sentryDsn) {
console.warn('VITE_SENTRY_DSN is not defined. Sentry is not running.')
} else {
Sentry.init({
dsn: sentryDsn,
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/tanstackstart-react/configuration/options/#sendDefaultPii
sendDefaultPii: true,
tracesSampleRate: 1.0,
replaysSessionSampleRate: 1.0,
replaysOnErrorSampleRate: 1.0,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ function RouteComponent() {
const [results, setResults] = useState<
Record<string, { type: 'success' | 'error'; spanOp: string }>
>({})
const [sentryConfigured, setSentryConfigured] = useState<boolean | null>(null)

useEffect(() => {
// Check if Sentry DSN environment variable is set
const hasDsn = !!import.meta.env.VITE_SENTRY_DSN
setSentryConfigured(hasDsn)
}, [])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do this directly in the useState initializer:

const [sentryConfigured] = useState(() => {
  // Check if Sentry DSN environment variable is set
  const hasDsn = !!import.meta.env.VITE_SENTRY_DSN
})

also, we’re checking for import.meta.env here, but the server instrumentation file does:

const sentryDsn = import.meta.env?.VITE_SENTRY_DSN ?? process.env.VITE_SENTRY_DSN


// Don't show warning until we've checked on the client
const showWarning = sentryConfigured === false

const handleClientError = async () => {
setIsLoading((prev) => ({ ...prev, clientError: true }))
Expand Down Expand Up @@ -394,8 +404,8 @@ function RouteComponent() {
</div>
</div>
<p className="text-lg text-[#A49FB5] max-w-xl mx-auto leading-relaxed">
Click the buttons below to trigger errors and traces, then view
them in your{' '}
Click the buttons below to trigger errors and traces, then view them
in your{' '}
<a
href="https://sentry.io"
target="_blank"
Expand All @@ -408,6 +418,32 @@ function RouteComponent() {
</p>
</div>

{/* Sentry Not Initialized Warning */}
{showWarning && (
<div className="mb-8 flex items-center gap-3 bg-[#E5A000]/10 border border-[#E5A000]/30 rounded-xl px-6 py-4">
<svg
className="w-6 h-6 text-[#E5A000] flex-shrink-0"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
viewBox="0 0 24 24"
stroke="currentColor"
>
<title>Warning</title>
<path d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
<div>
<p className="text-[#E5A000] font-medium">
Sentry is not initialized
</p>
<p className="text-[#A49FB5] text-sm mt-1">
Set the <code className="bg-[#1C1825] px-1.5 py-0.5 rounded text-[#B3A1FF]">VITE_SENTRY_DSN</code> environment variable to enable error tracking and performance monitoring.
</p>
</div>
</div>
)}

{/* Features Grid */}
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-12">
<FeatureCard
Expand Down Expand Up @@ -463,6 +499,7 @@ function RouteComponent() {
variant="error"
onClick={handleClientError}
loading={isLoading.clientError}
disabled={sentryConfigured === false}
>
Trigger Client Error
</SentryButton>
Expand All @@ -483,6 +520,7 @@ function RouteComponent() {
variant="primary"
onClick={handleClientTrace}
loading={isLoading.clientTrace}
disabled={sentryConfigured === false}
>
Test Client Trace
</SentryButton>
Expand Down Expand Up @@ -513,6 +551,7 @@ function RouteComponent() {
variant="error"
onClick={handleServerError}
loading={isLoading.serverError}
disabled={sentryConfigured === false}
>
Trigger Server Error
</SentryButton>
Expand All @@ -533,6 +572,7 @@ function RouteComponent() {
variant="primary"
onClick={handleServerTrace}
loading={isLoading.serverTrace}
disabled={sentryConfigured === false}
>
Test Server Trace
</SentryButton>
Expand Down
2 changes: 1 addition & 1 deletion frameworks/react-cra/src/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is auto-generated. Do not edit manually.
// Generated from add-ons, examples, hosts, project, and toolchains directories
export const contentChecksum = '91ab333689da4a55dac5572c70c66bf3cf8710caf4fe62ee5fd63d7fa924f8a2'
export const contentChecksum = '88a422e61dd3dfda1f79da5f1c567dbec2b4f7e574bcacda5613409e8403f0e3'
2 changes: 1 addition & 1 deletion frameworks/solid/src/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is auto-generated. Do not edit manually.
// Generated from add-ons, examples, hosts, project, and toolchains directories
export const contentChecksum = '97450d3bd15410ec0fb6553e0b2709464dbef2b643f509e73ff124a3230f44c5'
export const contentChecksum = '3e9cf8aa946ca4d59c413689bf5f02d778bcd23c95bc5e04956f47331261dac8'