Skip to content

Commit a8c6e32

Browse files
committed
Update sentry files to use environment methods, fix docs
1 parent 26f907e commit a8c6e32

4 files changed

Lines changed: 15 additions & 21 deletions

File tree

‎sentry.server.config.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sentry from "@sentry/astro"
22
import { SENTRY_DSN } from "astro:env/client"
3-
3+
import { isDev, isProd } from '@lib/config'
44
/**
55
* Server-side Sentry initialization
66
*
@@ -11,11 +11,8 @@ import { SENTRY_DSN } from "astro:env/client"
1111
* The server SDK only needs SENTRY_DSN to report errors.
1212
*/
1313

14-
const isProd = import.meta.env.PROD
15-
const isDev = import.meta.env.DEV
16-
1714
// Initialize Sentry in production if DSN is available
18-
if (isProd) {
15+
if (isProd()) {
1916
Sentry.init({
2017
dsn: SENTRY_DSN,
2118

@@ -51,7 +48,7 @@ if (isProd) {
5148
*/
5249
beforeSend(event, _hint) {
5350
// Don't send in development
54-
if (isDev) {
51+
if (isDev()) {
5552
return null
5653
}
5754
return event

‎src/components/scripts/sentry/client.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
linkedErrorsIntegration,
1212
} from '@sentry/browser'
1313
import { SENTRY_DSN } from 'astro:env/client'
14+
import { isDev } from '@components/scripts/utils'
1415
import { $consent } from '@components/scripts/store/consent'
1516

1617
/**
@@ -37,7 +38,6 @@ export class SentryBootstrap {
3738

3839
const client = new BrowserClient({
3940
dsn: SENTRY_DSN,
40-
4141
integrations: [
4242
// Core integrations
4343
breadcrumbsIntegration({
@@ -105,7 +105,7 @@ export class SentryBootstrap {
105105
*/
106106
beforeSend(event, _hint) {
107107
// Don't send errors in development
108-
if (import.meta.env.DEV) {
108+
if (isDev()) {
109109
return null
110110
}
111111

‎src/lib/config/environmentServer.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
/** Cannot use path aliases in this file */
2-
import { BuildError } from '../errors/BuildError'
3-
41
/**
52
* This method is only intended to be called from astro.config.ts
63
*/
74
export const getSentryAuthToken = () => {
8-
if (!process.env['SENTRY_AUTH_TOKEN']) {
9-
throw new BuildError('Running in CI environment, but SENTRY_AUTH_TOKEN is not set.')
10-
}
115
return process.env['SENTRY_AUTH_TOKEN']
126
}
137

‎src/lib/config/environmentalVariableValidation.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import type { AstroUserConfig } from 'astro'
2020
* Secret client variables: not supported because there is no safe way to send this data to the client.
2121
*
2222
* ✅ CORRECT: Public client variables are available from BOTH modules
23-
* import { PUBLIC_SENTRY_DSN } from 'astro:env/client' // Works in client code
24-
* import { PUBLIC_SUPABASE_KEY } from 'astro:env/server' // Works in server code (API routes)
23+
* import { CLIENT_PUBLIC_DSN } from 'astro:env/client' // Works in client code
24+
* import { CLIENT_PUBLIC_KEY } from 'astro:env/server' // Works in server code (API routes)
2525
*
2626
* ❌ WRONG: Server variables are ONLY available from astro:env/server
27-
* import { RESEND_API_KEY } from 'astro:env/client' // TypeScript error!
27+
* import { CLIENT_PUBLIC_KEY } from 'astro:env/client' // TypeScript error!
2828
*/
2929

3030
export const environmentalVariablesConfig: AstroUserConfig['env'] = {
@@ -110,11 +110,14 @@ export const environmentalVariablesConfig: AstroUserConfig['env'] = {
110110
}),
111111
/**
112112
* Site uses Sentry for monitoring site errors and user path tracing
113+
*
114+
* - Only used in code called by astro.config.ts, uses process.env
115+
* - Used to upload source maps during build
113116
*/
114117
SENTRY_AUTH_TOKEN: envField.string({
115-
access: 'public',
118+
access: 'secret',
116119
context: 'server',
117-
optional: false, // Only required for uploading source maps during build
120+
optional: false,
118121
}),
119122
SENTRY_DSN: envField.string({
120123
access: 'public',
@@ -124,12 +127,12 @@ export const environmentalVariablesConfig: AstroUserConfig['env'] = {
124127
/**
125128
* Site uses Suprabase for managing GDPR consent records
126129
*/
127-
PUBLIC_SUPABASE_URL: envField.string({
130+
SUPABASE_URL: envField.string({
128131
access: 'public',
129132
context: 'client',
130133
optional: false,
131134
}),
132-
PUBLIC_SUPABASE_KEY: envField.string({
135+
SUPABASE_KEY: envField.string({
133136
access: 'public',
134137
context: 'server',
135138
optional: false,

0 commit comments

Comments
 (0)