Basic information
About sentry-sdk-patterns
Execute best practices for using Sentry SDK in TypeScript and Python. Use when implementing error handling patterns, structuring Sentry code, or optimizing SDK usage. Trigger with phrases like "sentry best practices", "sentry patterns", "sentry sdk usage", "sentry code structure".
sentry-sdk-patterns is an agent skill listed in the AddMCP.net directory, published by jeremylongshore. Runtime: Python. License: MIT. The repository has 2,889 GitHub stars. Source code is hosted on github.com. Related topics: agent-skills, ai, ai-agents, anthropic, automation.
Overview
What is sentry-sdk-patterns?
name: sentry-sdk-patterns description: | Best practices for using Sentry SDK in TypeScript and Python. Use when implementing structured error context with scopes, breadcrumb strategies, beforeSend/beforeBreadcrumb filtering, custom fingerprinting, user context, or performance span creation. Trigger: "sentry best practices", "sentry patterns", "sentry sdk usage", "sentry scope", "sentry breadcrumbs", "sentry beforeSend", "sentry fingerprint". allowed-tools: Read, Write, Edit, Grep version: 1.0.0 license: MIT author: Jeremy Longshore <[email protected]> compatible-with: claude-code, codex, openclaw tags: [saas, sentry, python, typescript, best-practices, error-handling]
Sentry SDK Patterns
Overview
Production patterns for @sentry/node (v8+) and sentry-sdk (Python 2.x+) covering scoped error context, breadcrumb strategies, event filtering with beforeSend, custom fingerprinting for issue grouping, and performance instrumentation with spans. All examples use real Sentry SDK APIs.
Prerequisites
- Sentry SDK v8+ installed (
@sentry/node,@sentry/react, orsentry-sdk) SENTRY_DSNenvironment variable configured- Familiarity with async/await (TypeScript) or context managers (Python)
Instructions
Something went wrong
Try againOutput
After applying these patterns you will have:
- Centralized error handler module with typed severity and scoped context
- Structured breadcrumb helpers for auth, db, and http events
beforeSendfilter that drops noise and scrubs PIIbeforeBreadcrumbcallback that redacts sensitive query parameters- Custom fingerprinting for accurate issue grouping
- Framework error boundaries for Express and React
- Performance spans for tracing critical code paths
Error Handling
| Error | Cause | Solution | |-------|-------|----------| | Scope leaking between requests | Global scope mutations in async handlers | Use withScope() / new_scope() for per-event context | | Duplicate events | Error caught and re-thrown at two layers | Capture at one level only -- middleware or handler, not both | | Missing breadcrumbs | Cleared after max count (default 100) | Set maxBreadcrumbs in Sentry.init() | | beforeSend returns undefined | Missing return statement | Always return event or null explicitly | | Events grouped incorrectly | Default stack-trace fingerprinting | Use scope.setFingerprint() with semantic keys | | Sentry is not defined | SDK not imported | Verify import * as Sentry from '@sentry/node' | | Spans not appearing | Missing tracing config | Set tracesSampleRate in Sentry.init() |
Examples
Centralized error handler: Create lib/error-handler.ts wrapping Sentry.withScope() with typed severity, tags, context, user, and fingerprint support.
Breadcrumb trail for checkout: Add breadcrumb.auth('login'), breadcrumb.db('SELECT', 'orders'), breadcrumb.http('POST', '/api/payments', 201) before critical operations so errors include full context timeline.
Noise filtering: Configure beforeSend to drop ResizeObserver loop and Network request failed, scrub PII from user context and cookies.
Fix issue grouping: Add scope.setFingerprint(['payment-gateway-timeout', gatewayName]) to group all payment timeouts by gateway.
See [examples.md](references/examples.md) for full worked scenarios with Python context managers and async wrappers.
Resources
Next Steps
- sentry-error-capture -- Deep dive on
captureExceptionvscaptureMessagesemantics - sentry-performance-tracing -- Full distributed tracing with
tracesSampleRateand custom instrumentation - sentry-data-handling -- PII scrubbing, data residency, and GDPR-compliant configuration
- sentry-common-errors -- Troubleshooting guide for frequent SDK issues
Comments
No comments yet
Be the first to share feedback about this listing. Sign in to leave a comment.
Sign In