agentleFS
pabloirracionalpabloirracional/claude-skills/skills/setting-up-error-monitoring/SKILL.md

setting-up-error-monitoring

Skill0 starsChanged 4 months agoMITView on GitHub

Sets up Sentry-style error monitoring with tested scrubbing of sensitive data - including a real scrubbing bug found and fixed during testing, not a theoretical warning. Use whenever the user wants to add error tracking/monitoring to a project, debug why errors aren't showing up in a monitoring tool, or set up alerts for production issues.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add at least one alert (new error type, error rate spike) before calling setup complete - monitoring with no alerting just becomes a …

    line 57

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Setting up error monitoring

Installs and configures error monitoring so production issues surface with useful context - tested against the real @sentry/node SDK, including a real data-leak bug found while testing the scrubbing hook.

Workflow

  1. Detect the platform/framework first - SDK setup differs significantly between a Node backend, a React SPA, and a mobile app.
  2. Separate environments in the SDK config from the start - confirmed below via getOptions().
  3. Source maps for minified code - without uploading source maps, production stack traces are unreadable.
  4. Scrub sensitive data in beforeSend, and verify the scrub actually hits the right path - see the real bug found below. Getting this wrong doesn't throw an error or fail loudly; it just silently ships secrets to your monitoring dashboard.
  5. Always flush() before a process exits - see below, this is a second easy silent-failure mode.

Tested, with a real bug found and fixed

Ran against the actual @sentry/node SDK (not mocked), capturing a real thrown error with request context attached.

Bug found during testing: the first version of the scrubbing hook checked event.request.data for sensitive fields. Testing showed the sensitive data was not scrubbed - password and apiKey came through in plain text:

Captured request data: {"userId":42,"password":"hunter2","apiKey":"sk_live_abc123"}
FAIL - sensitive data leaked into event

Root cause: manually-attached context via Sentry.captureException(err, { contexts: { request: {...} } }) actually lands at event.contexts.request.data - the top-level event.request field is reserved for the SDK's own HTTP framework integrations, not manually-attached context. Checking the wrong path meant the scrub silently did nothing.

Fixed version, checking the correct path:

beforeSend(event) {
  if (event.contexts?.request?.data) {
    for (const field of ['password', 'token', 'apiKey', 'creditCard']) {
      if (event.contexts.request.data[field] !== undefined) {
        event.contexts.request.data[field] = '[Scrubbed]';
      }
    }
  }
  return event;
}

Confirmed after the fix:

Captured request data: {"userId":42,"password":"[Scrubbed]","apiKey":"[Scrubbed]"}
PASS - password and apiKey scrubbed

Practical takeaway for reviewing anyone's beforeSend hook: don't just check that a scrubbing function exists - check that the field path it scrubs actually matches the field path the data was attached at. These two silently drift apart whenever context is attached manually rather than through the SDK's built-in integrations, and there's no error or warning when it happens - the event just ships with the sensitive field intact.

Second finding: events need an explicit flush

The first test run showed 0 events captured immediately after captureException() - not because capture failed, but because Sentry batches and sends asynchronously, and beforeSend only fires when the batch actually flushes. Adding await Sentry.flush(2000) before checking fixed it. This matters most for short-lived processes (serverless functions, CLI scripts, CI jobs) - if the process exits before the SDK's internal flush timer fires, captured errors can be silently dropped with no indication anything went wrong. Always flush explicitly before intentional process exit in these environments.

Notes

  • This was tested with a fake DSN and beforeSend returning null to prevent any real network call - the scrubbing logic and event shape are real SDK behavior; actual delivery to Sentry's servers wasn't (and doesn't need to be) tested here.
  • Add at least one alert (new error type, error rate spike) before calling setup complete - monitoring with no alerting just becomes a dashboard nobody checks.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.