admin/sentry.server.config.ts
alisaza d3c48a1ed1 fix(ops): enable HTTPS backoffice and Sentry via Finland relay
Ship TLS nginx for backoffice, keep HTTP bootstrap until certs exist, proxy /monitoring to sentry-relay, and tunnel server/edge Sentry through Finland.
2026-09-13 20:38:19 +03:30

40 lines
1.4 KiB
TypeScript

import * as Sentry from '@sentry/nextjs'
import { shouldDropExpectedProductSentryEvent } from './lib/observability/expectedProductError'
const dsn = process.env.SENTRY_DSN?.trim() || process.env.NEXT_PUBLIC_SENTRY_DSN?.trim()
/** Iran runtime cannot reach ingest.de; send via Finland relay. */
function sentryTunnel(): string | undefined {
const fromEnv = process.env.SENTRY_TUNNEL?.trim()
if (fromEnv) return fromEnv
if (process.env.NODE_ENV === 'production') return 'https://sentry-relay.ghabilee.ir/monitoring'
return undefined
}
function tracesSampleRate(): number {
const raw = process.env.SENTRY_TRACES_SAMPLE_RATE ?? '0.1'
const parsed = Number.parseFloat(raw)
return Number.isFinite(parsed) ? parsed : 0.1
}
export function initServerSentry() {
// فقط در production — در local/dev نویز و مصرف سهمیه نمی‌خواهیم
if (process.env.NODE_ENV !== 'production' || !dsn) return
Sentry.init({
dsn,
tunnel: sentryTunnel(),
environment: process.env.SENTRY_ENVIRONMENT?.trim() || process.env.NODE_ENV || 'production',
release: process.env.SENTRY_RELEASE?.trim() || process.env.NEXT_PUBLIC_APP_VERSION || undefined,
tracesSampleRate: tracesSampleRate(),
sendDefaultPii: false,
beforeSend(event, hint) {
if (shouldDropExpectedProductSentryEvent(event, hint.originalException)) return null
return event
},
})
}