---
name: sentry-reliability-patterns
description: '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".'
allowed-tools: Read, Write, Edit, Grep, Bash(node:*), Bash(pip:*), Bash(python*:*)
version: 1.51.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - sentry
  - reliability
  - resilience
  - circuit-breaker
  - offline-queue
  - graceful-degradation
compatibility: Designed for Claude Code
title: sentry-reliability-patterns
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/circuit-breaker-pattern.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/circuit-breaker-pattern.md), [references/dual-write-pattern.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/dual-write-pattern.md), [references/errors.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/errors.md), [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/examples.md), [references/graceful-degradation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/graceful-degradation.md), [references/health-checks.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/health-checks.md), [references/network-failure-handling.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/network-failure-handling.md), [references/timeout-handling.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/timeout-handling.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/sentry-reliability-patterns`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/sentry-reliability-patterns`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/sentry-reliability-patterns --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/sentry-reliability-patterns --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Sentry Reliability Patterns

## Overview

Build Sentry integrations that never take your application down via three pillars: safe initialization with graceful degradation, a circuit breaker that stops hammering Sentry when unreachable, and an offline event queue that buffers errors during outages. Every pattern prioritizes application uptime over telemetry completeness.

## Prerequisites

- `@sentry/node` v8+ (TypeScript) or `sentry-sdk` v2+ (Python)
- A valid Sentry DSN from project settings at `sentry.io`
- A fallback logging destination decided (console, file, or external logger)
- Understanding of your application shutdown lifecycle (signal handlers, container orchestration)

## Instructions

### Step 1 — Safe Initialization with Graceful Degradation

Wrap `Sentry.init()` in try/catch so an invalid DSN, network error, or SDK bug never crashes the app. Track initialization state with a boolean flag. Protect `beforeSend` callbacks with their own error boundary.

Create `lib/sentry-safe.ts` with `initSentrySafe()` and `captureError()`. See [graceful-degradation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/graceful-degradation.md) for full implementation.

Key rules:

- Never let `Sentry.init()` crash the process — wrap in try/catch, set `sentryAvailable = false` on failure
- Verify client creation with `Sentry.getClient()` — invalid DSNs silently produce no client
- Always log errors locally as baseline before attempting Sentry capture
- Wrap user-supplied `beforeSend` hooks in nested try/catch — return raw event on hook failure

### Step 2 — Circuit Breaker for Sentry Outages

When Sentry is unreachable, continued attempts waste resources and add latency. Track consecutive failures and trip open after a threshold. After cooldown, enter half-open state and send a single probe.

Implement `SentryCircuitBreaker` class with closed/open/half-open states. See [circuit-breaker-pattern.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/circuit-breaker-pattern.md) for full implementation. Expose state via [health-checks.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/health-checks.md) endpoint.

Key rules:

- Default: 5 failures to trip open, 60-second cooldown before half-open probe
- In open state, skip Sentry calls entirely and log to fallback
- On half-open success, reset to closed with zero failure count
- Expose `getStatus()` for health check endpoints and monitoring dashboards

### Step 3 — Offline Queue, Custom Transport, and Graceful Shutdown

Buffer events when network is unavailable and replay on reconnect. Use bounded file-based queue to survive restarts. Pair with signal handlers that flush via `Sentry.close()` before process exit.

Implement three modules:

- `lib/sentry-offline-queue.ts` — `enqueueEvent()` and `drainQueue()`. See [network-failure-handling.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/network-failure-handling.md)
- `lib/sentry-transport.ts` — Custom transport with exponential backoff retry. See [timeout-handling.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/timeout-handling.md)
- `lib/sentry-shutdown.ts` — `SIGTERM`/`SIGINT` handlers calling `Sentry.close(2000)`. See [timeout-handling.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/timeout-handling.md)

Key rules:

- Cap offline queue at 1000 events, evict oldest when full
- Drain queue on startup and when connectivity restores
- Call `Sentry.close(timeout)` before `process.exit()` — without it, in-flight events are silently dropped
- For critical errors, use [dual-write-pattern.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/dual-write-pattern.md) to send to multiple destinations via `Promise.allSettled`

## Output

- Safe init wrapper catching SDK failures, starting app in degraded mode
- `captureError()` with automatic fallback to local logging
- Circuit breaker stopping sends after repeated failures, self-healing after cooldown
- Health check endpoint exposing SDK status and circuit breaker state
- File-based offline queue buffering events during outages, draining on reconnect
- Signal handlers flushing in-flight events before process exit
- Custom transport with exponential-backoff retry logic

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| App crashes on `Sentry.init()` | Invalid DSN or SDK bug | Wrap in try/catch via `initSentrySafe()` |
| Events lost on `SIGTERM` | No `Sentry.close()` before exit | Register signal handlers with `Sentry.close(2000)` |
| Sentry outage cascades latency | Every error path hits Sentry HTTP | Circuit breaker trips after 5 failures |
| Events lost during network blip | SDK drops events silently | Retry transport + offline queue |
| Silent event loss | SDK fails without throwing | Health check probes with `captureMessage` + `flush` |
| Queue grows unbounded | Never drained, Sentry permanently down | Cap at 1000 events, drain on startup |
| `beforeSend` crashes pipeline | User hook throws | Nested try/catch, return raw event |

See [errors.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/errors.md) for extended troubleshooting.

## Examples

See [examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/examples.md) for complete TypeScript and Python integration examples including full-stack wiring of all three patterns.

## Resources

- [Sentry JS Configuration](https://docs.sentry.io/platforms/javascript/configuration/) — `beforeSend`, `sampleRate`, init options
- [Custom Transports](https://docs.sentry.io/platforms/javascript/configuration/transports/) — retry and offline transports
- [Shutdown & Draining](https://docs.sentry.io/platforms/javascript/configuration/draining/) — `Sentry.close()` and `Sentry.flush()`
- [Sentry Python SDK](https://docs.sentry.io/platforms/python/) — `sentry_sdk.init()`, `flush()`, scope management
- [Sentry Status Page](https://status.sentry.io/) — monitor platform outages

## Next Steps

- Emit circuit breaker state changes to observability platform (Datadog, Prometheus) for outage alerting
- Set up periodic `drainQueue()` via `setInterval` (Node) or cron (Python) instead of startup-only
- Apply retry transport pattern to Python via `sentry_sdk.init(transport=...)` parameter
- Test failure modes in staging — simulate Sentry failures with `beforeSend` to verify circuit breaker behavior
- Add [dual-write](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/sentry-reliability-patterns/references/dual-write-pattern.md) for P0/fatal errors to secondary destinations (CloudWatch, PagerDuty)
