2024-06-03 04:42:54 +00:00
|
|
|
import * as Sentry from "@sentry/node"
|
2025-04-02 01:19:57 +00:00
|
|
|
import { nodeProfilingIntegration } from "@sentry/profiling-node"
|
2025-12-15 16:02:20 +00:00
|
|
|
import { prismaIntegration } from "@sentry/node"
|
|
|
|
|
|
2025-06-05 21:00:31 +00:00
|
|
|
const isProduction = process.env.NODE_ENV === "production"
|
2025-12-15 16:02:20 +00:00
|
|
|
const environment = process.env.AZURE_ENVIRONMENT || process.env.NODE_ENV || "development"
|
2024-06-03 04:42:54 +00:00
|
|
|
|
|
|
|
|
Sentry.init({
|
2025-06-05 21:00:31 +00:00
|
|
|
dsn: isProduction
|
|
|
|
|
? "https://7a83ac92f85c298f31bae97b97cabfe2@o4506833230561280.ingest.sentry.io/4506833372643328"
|
|
|
|
|
: undefined,
|
2025-12-15 16:02:20 +00:00
|
|
|
|
|
|
|
|
environment,
|
|
|
|
|
|
2025-04-02 01:19:57 +00:00
|
|
|
integrations: [
|
|
|
|
|
nodeProfilingIntegration(),
|
2025-12-15 16:02:20 +00:00
|
|
|
prismaIntegration(), // Better database error tracking
|
2025-04-02 01:19:57 +00:00
|
|
|
],
|
2025-12-15 16:02:20 +00:00
|
|
|
|
2025-04-02 01:19:57 +00:00
|
|
|
// Performance Monitoring sampling rate
|
2025-12-15 16:02:20 +00:00
|
|
|
// In production, sample 20% of transactions to reduce noise
|
|
|
|
|
tracesSampleRate: isProduction ? 0.2 : 1.0,
|
2024-06-03 04:42:54 +00:00
|
|
|
|
2025-04-02 01:19:57 +00:00
|
|
|
// Profiling sampling rate
|
2025-12-15 16:02:20 +00:00
|
|
|
// In production, sample 10% of transactions
|
|
|
|
|
profilesSampleRate: isProduction ? 0.1 : 1.0,
|
2025-04-02 01:19:57 +00:00
|
|
|
|
|
|
|
|
// Debug mode for local testing
|
2025-06-05 21:00:31 +00:00
|
|
|
debug: !isProduction,
|
2025-12-15 16:02:20 +00:00
|
|
|
|
|
|
|
|
// Capture more context for errors
|
|
|
|
|
maxBreadcrumbs: 50,
|
|
|
|
|
|
|
|
|
|
// Attach stack traces to messages
|
|
|
|
|
attachStacktrace: true,
|
|
|
|
|
|
|
|
|
|
// Add release information if available
|
|
|
|
|
release: process.env.RELEASE_VERSION || process.env.npm_package_version,
|
|
|
|
|
|
|
|
|
|
// Filter out sensitive data
|
|
|
|
|
beforeSend(event, hint) {
|
|
|
|
|
// Remove sensitive headers
|
|
|
|
|
if (event.request?.headers) {
|
2026-04-13 16:03:05 +00:00
|
|
|
delete event.request.headers.authorization
|
|
|
|
|
delete event.request.headers.cookie
|
2025-12-15 16:02:20 +00:00
|
|
|
delete event.request.headers["x-api-key"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove sensitive environment variables
|
|
|
|
|
if (event.contexts?.runtime?.env) {
|
|
|
|
|
const sensitiveKeys = ["DATABASE_URL", "STRIPE_SECRET", "JWT_SECRET", "GITHUB_PRIVATE_KEY"]
|
|
|
|
|
sensitiveKeys.forEach(key => {
|
|
|
|
|
if (event.contexts?.runtime?.env) {
|
|
|
|
|
delete event.contexts.runtime.env[key]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return event
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Ignore certain errors
|
|
|
|
|
ignoreErrors: [
|
|
|
|
|
// Browser extensions
|
|
|
|
|
"top.GLOBALS",
|
|
|
|
|
// Random plugins/extensions
|
|
|
|
|
"originalCreateNotification",
|
|
|
|
|
"canvas.contentDocument",
|
|
|
|
|
"MyApp_RemoveAllHighlights",
|
|
|
|
|
// Common benign errors
|
|
|
|
|
"Non-Error promise rejection captured",
|
|
|
|
|
"ResizeObserver loop limit exceeded",
|
|
|
|
|
// Network errors that are user-side issues
|
|
|
|
|
"Network request failed",
|
|
|
|
|
"NetworkError",
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
// Add server name for identification
|
|
|
|
|
serverName: process.env.WEBSITE_INSTANCE_ID || process.env.HOSTNAME || "unknown",
|
|
|
|
|
|
|
|
|
|
// Tag with Azure-specific metadata if available
|
|
|
|
|
initialScope: {
|
|
|
|
|
tags: {
|
|
|
|
|
service: "cf-api",
|
|
|
|
|
azure_instance: process.env.WEBSITE_INSTANCE_ID || "unknown",
|
|
|
|
|
azure_site_name: process.env.WEBSITE_SITE_NAME || "unknown",
|
|
|
|
|
node_version: process.version,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-06-03 04:42:54 +00:00
|
|
|
})
|