Configure GDPR-compliant data handling, PII scrubbing, and data
retention policies in Sentry. Use when implementing beforeSend
filters, server-side data scrubbing rules, IP anonymization,
data subject deletion requests, or SOC 2 audit controls.
Trigger with phrases like "sentry pii scrubbing", "sentry gdpr",
"sentry data privacy", "scrub sensitive data sentry",
"sentry data retention", "sentry compliance".
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
sentry-data-handling
description
Configure GDPR-compliant data handling, PII scrubbing, and data
retention policies in Sentry. Use when implementing beforeSend
filters, server-side data scrubbing rules, IP anonymization,
data subject deletion requests, or SOC 2 audit controls.
Trigger with phrases like "sentry pii scrubbing", "sentry gdpr",
"sentry data privacy", "scrub sensitive data sentry",
"sentry data retention", "sentry compliance".
Designed for Claude Code, also compatible with Codex and OpenClaw
Sentry Data Handling
Configure PII scrubbing, GDPR compliance, data retention, and audit controls for Sentry. This skill covers client-side filtering with beforeSend, server-side scrubbing rules, data subject erasure via API, and SOC 2 compliance patterns.
Overview
Sentry captures error context that often contains personally identifiable information (PII) — emails in stack traces, credit card numbers in request bodies, IP addresses in headers. Production deployments must scrub this data at two layers: client-side via beforeSend hooks (before data leaves the application) and server-side via Sentry's built-in Data Scrubber (defense in depth). GDPR requires additional controls: consent-based initialization, data subject deletion endpoints, and a signed Data Processing Agreement. This skill implements all three layers with TypeScript and Python examples, plus verification tests to prove scrubbing works end-to-end.
Prerequisites
Sentry SDK v8 installed and initialized (@sentry/node or sentry-sdk)
Sentry project with Admin or Owner role (required for Security & Privacy settings)
Compliance requirements documented (GDPR, HIPAA, PCI-DSS, or SOC 2)
Auth token with project:write and org:admin scopes for API operations
Step 1 — Client-Side PII Scrubbing with beforeSend
The first defense layer prevents PII from leaving your application. Configure beforeSend, beforeSendTransaction, and beforeBreadcrumb hooks during SDK initialization:
Scrub IP Addresses — enable to remove client IPs from all events
Scrub Credit Cards — detect and remove card number patterns
For advanced regex-based rules, navigate to Project Settings > Security & Privacy > Advanced Data Scrubbing:
# Remove credit card patterns from all string fields
[Remove] [Regex: \d{4}-\d{4}-\d{4}-\d{4}] from [$string]
# Remove email addresses everywhere
[Remove] [Regex: \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b] from [$string]
# Remove SSN patterns
[Remove] [Regex: \b\d{3}-\d{2}-\d{4}\b] from [$string]
# Mask passwords in request bodies
[Mask] [Password] from [extra.request_body]
# Replace credit card data everywhere with placeholder
[Replace] [Credit card] with [REDACTED] from [**]
Data forwarding — if forwarding events to external systems (Splunk, BigQuery), apply the same scrubbing rules at the destination. Configure forwarding in Project Settings > Data Forwarding.
Data retention — configure in Organization Settings > Subscription > Data Retention:
Plan
Default retention
Maximum retention
Developer
30 days
30 days
Team
90 days
90 days
Business
90 days
365 days
Enterprise
90 days
Custom
Step 3 — GDPR Compliance and Data Subject Requests
Right to be Informed — document Sentry usage in your privacy policy. Disclose what data is collected (stack traces, device info, anonymized user IDs) and the legal basis (legitimate interest in application reliability).
Consent-based initialization — for strict GDPR compliance, gate Sentry on user consent:
functioninitSentryWithConsent(hasConsent: boolean): void {
if (!hasConsent) {
// Do not initialize Sentry — no data sentreturn;
}
Sentry.init({
dsn: process.env.SENTRY_DSN,
sendDefaultPii: false,
beforeSend: scrubEvent,
});
}
Right to Erasure (Article 17) — delete user data via the Sentry API:
# Delete all events for a specific issue
curl -X DELETE \
-H "Authorization: Bearer ${SENTRY_AUTH_TOKEN}" \
"https://sentry.io/api/0/projects/${SENTRY_ORG}/${SENTRY_PROJECT}/issues/${ISSUE_ID}/" \
|| { echo"ERROR: Deletion failed — verify auth token has project:admin scope"; exit 1; }
// Programmatic deletion for data subject requestsasyncfunctionhandleDeletionRequest(userId: string): Promise<void> {
const org = process.env.SENTRY_ORG;
const project = process.env.SENTRY_PROJECT;
const token = process.env.SENTRY_AUTH_TOKEN;
// Search for issues containing user dataconst searchRes = awaitfetch(
`https://sentry.io/api/0/projects/${org}/${project}/issues/?query=user.id:${userId}`,
{ headers: { Authorization: `Bearer ${token}` } }
);
if (!searchRes.ok) {
thrownewError(`Search failed: ${searchRes.status}${searchRes.statusText}`);
}
const issues = await searchRes.json();
// Delete each matching issuefor (const issue of issues) {
const deleteRes = awaitfetch(
`https://sentry.io/api/0/projects/${org}/${project}/issues/${issue.id}/`,
{ method: 'DELETE', headers: { Authorization: `Bearer ${token}` } }
);
if (!deleteRes.ok) {
thrownewError(`Deletion failed for issue ${issue.id}: ${deleteRes.status}`);
}
}
console.log(`Deleted ${issues.length} issues for user ${userId}`);
}
Audit log access — Business and Enterprise plans provide audit logs at Organization Settings > Audit Log. Export via API for SOC 2 evidence: