Skip to content

Sentry

Sentry

Functions

initSentry

function initSentry()
TypeScript

Use initSentry to enable error tracking and performance monitoring for the skrypt documentation generator.

This is called once at process startup — before any scanning, generation, or CLI commands run — so that crashes and slow operations are captured and reported automatically.

It reads your SENTRY_DSN environment variable (falling back to the project's default DSN) and initializes the Sentry SDK with a 20% performance trace sample rate and the current NODE_ENV as the environment tag. No configuration is required on your end.

Returns: Nothing. Call it at the top of your entry point and move on — Sentry captures unhandled exceptions and slow traces from that point forward.

Heads up:

  • Set NODE_ENV=development locally if you want errors tagged separately from production traffic in the Sentry dashboard.
  • Traces are sampled at 20%, so not every request appears in Sentry's performance view — this is intentional to keep volume low.

Example:

import * as Sentry from '@sentry/node'

// Inline the same initialization logic that initSentry() performs internally
function initSentry() {
  const DSN =
    process.env.SENTRY_DSN ||
    'https://ae4ec6625486c40b92779937c5f6aa64@o4511084239781888.ingest.us.sentry.io/4511084253478912'

  Sentry.init({
    dsn: DSN,
    tracesSampleRate: 0.2,
    environment: process.env.NODE_ENV || 'production',
  })
}

// Call once at process startup, before any other logic runs
initSentry()

// From this point on, unhandled errors and slow operations are tracked
async function runDocGeneration() {
  try {
    // Simulate a documentation generation task
    const span = Sentry.startInactiveSpan({ name: 'generate-docs' })
    console.log('Generating docs...')
    // ... your generation logic here
    span.end()
    console.log('Sentry initialized with environment:', process.env.NODE_ENV || 'production')
    console.log('Traces sample rate: 20%')
  } catch (err) {
    Sentry.captureException(err)
    throw err
  }
}

runDocGeneration()
// => Generating docs...
// => Sentry initialized with environment: production
// => Traces sample rate: 20%
TypeScript
Was this helpful?