Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/sentry-reliability-patterns

@0d57af8
Run it yourself

Build reliable Sentry integrations with graceful degradation, circuit breakers, and offline queuing. Use when implementing fault-tolerant error tracking, handling SDK initialization failures, building retry logic for Sentry transports, or ensuring apps survive Sentry outages. Trigger with "sentry reliability", "sentry circuit breaker", "sentry offline queue", "sentry graceful degradation", "sentry failover", or "resilient sentry setup".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestimeout-handling.md

≈926 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Timeout Handling

Custom Transport with Retry Logic

// lib/sentry-transport.ts — resilient transport with exponential backoff
import * as Sentry from '@sentry/node';

export function makeRetryTransport(
  options: Sentry.NodeTransportOptions,
): Sentry.Transport {
  const baseTransport = Sentry.makeNodeTransport(options);

  return {
    send: async (envelope) => {
      const maxRetries = 3;
      let lastError: unknown;

      for (let attempt = 1; attempt <= maxRetries; attempt++) {
        try {
          return await baseTransport.send(envelope);
        } catch (error) {
          lastError = error;
          if (attempt < maxRetries) {
            // Exponential backoff: 1s, 2s, 4s (capped at 5s)
            const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000);
            await new Promise((r) => setTimeout(r, delay));
          }
        }
      }

      // All retries exhausted — queue for offline replay
      console.error('[Sentry Transport] All retries failed:', lastError);
      return { statusCode: 0 };
    },
    flush: (timeout) => baseTransport.flush(timeout),
  };
}

// Usage in init:
// initSentrySafe(dsn, { transport: makeRetryTransport });

Capture with Timeout Wrapper

async function captureWithTimeout(
  error: Error,
  timeoutMs = 5000,
): Promise<string | null> {
  return new Promise((resolve) => {
    const timeout = setTimeout(() => {
      console.warn('[Sentry] Capture timed out');
      resolve(null);
    }, timeoutMs);

    const eventId = Sentry.captureException(error);

    Sentry.flush(timeoutMs - 100).finally(() => {
      clearTimeout(timeout);
      resolve(eventId);
    });
  });
}

Graceful Shutdown with Sentry.close()

// lib/sentry-shutdown.ts
import * as Sentry from '@sentry/node';

const FLUSH_TIMEOUT_MS = 2000; // 2 seconds before giving up on flush

export function registerShutdownHandlers(
  cleanupFn?: () => Promise<void>,
): void {
  const shutdown = async (signal: string) => {
    console.log(`[Shutdown] ${signal} received — flushing Sentry events`);

    // 1. Flush pending Sentry events with timeout
    try {
      const flushed = await Sentry.close(FLUSH_TIMEOUT_MS);
      console.log(`[Shutdown] Sentry flush: ${flushed ? 'complete' : 'timed out'}`);
    } catch (error) {
      console.error('[Shutdown] Sentry flush error:', error);
    }

    // 2. Run application-specific cleanup
    if (cleanupFn) {
      try {
        await cleanupFn();
      } catch (error) {
        console.error('[Shutdown] Cleanup error:', error);
      }
    }

    process.exit(0);
  };

  process.on('SIGTERM', () => shutdown('SIGTERM'));
  process.on('SIGINT', () => shutdown('SIGINT'));

  // Last-resort handler — capture, flush, exit
  process.on('uncaughtException', async (error) => {
    console.error('[Fatal] Uncaught exception:', error);
    Sentry.captureException(error);
    try {
      await Sentry.close(FLUSH_TIMEOUT_MS);
    } catch { /* swallow — process is dying anyway */ }
    process.exit(1);
  });

  process.on('unhandledRejection', (reason) => {
    const error = reason instanceof Error ? reason : new Error(String(reason));
    console.error('[Fatal] Unhandled rejection:', error);
    Sentry.captureException(error);
  });
}

Python Graceful Shutdown

import atexit
import sentry_sdk

def _shutdown_flush():
    """atexit handler — flush pending events before interpreter exits."""
    try:
        sentry_sdk.flush(timeout=2)
    except Exception:
        pass

atexit.register(_shutdown_flush)

Tons of Skills by Intent Solutions

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides production-ready code patterns for building resilient Sentry integrations with features like circuit breakers and offline queuing. No security issues were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 months ago
What it can do
Reads files Edits files Runs commands
version
1.51.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 7 allowed tools
ReadWriteEditGrepBash(node:*)Bash(pip:*)Bash(python*:*)
Other metadata
tags
[
  "saas",
  "sentry",
  "reliability",
  "resilience",
  "circuit-breaker",
  "offline-queue",
  "graceful-degradation"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns