-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Integrate ErrorBoundary with Analytics Client #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe change adds runtime analytics instrumentation to the ErrorBoundary component. When an error is caught, the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/common/ErrorBoundary.tsx(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/common/ErrorBoundary.tsx (1)
src/lib/analytics-client.ts (1)
recordAnalyticsEvent(17-73)
| recordAnalyticsEvent('error_boundary_catch', { | ||
| message: error.message, | ||
| stack: error.stack, | ||
| componentStack: errorInfo.componentStack, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PII and sensitive data may be logged without sanitization.
Error messages, stack traces, and component stacks can contain personally identifiable information (user input, email addresses, internal file paths, component props with sensitive data). Logging these details to an analytics service without scrubbing or user consent poses compliance risks under GDPR, CCPA, and similar regulations.
Consider sanitizing or redacting sensitive data before sending to analytics, or ensure your analytics pipeline has appropriate safeguards in place.
🤖 Prompt for AI Agents
In src/components/common/ErrorBoundary.tsx around lines 31-35, the code sends
raw error.message, error.stack and errorInfo.componentStack to analytics which
may contain PII; create and call a sanitizeErrorData utility before logging that
redacts emails, IPs, file paths, long strings and component prop values (or
strips component props entirely), truncates and/or hashes identifiers, and
removes or masks any matched sensitive patterns; ensure only allowlisted fields
(error name, truncated message, sanitized stack/componentStack or boolean flags)
are sent and gate logging behind user consent/opt-out where applicable, then
pass the sanitized object to recordAnalyticsEvent.
🛠️ Refactor suggestion | 🟠 Major
Wrap analytics call in try-catch for defensive error handling.
While recordAnalyticsEvent appears to handle errors internally, componentDidCatch is a critical error-handling path and should never throw. Wrap the analytics call in a try-catch block to ensure that any unexpected failure in the analytics layer does not break the error boundary itself.
Apply this diff:
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error('ErrorBoundary caught an error:', error, errorInfo);
- recordAnalyticsEvent('error_boundary_catch', {
- message: error.message,
- stack: error.stack,
- componentStack: errorInfo.componentStack,
- });
+ try {
+ recordAnalyticsEvent('error_boundary_catch', {
+ message: error.message,
+ stack: error.stack,
+ componentStack: errorInfo.componentStack,
+ });
+ } catch (analyticsError) {
+ console.error('Failed to record error boundary analytics:', analyticsError);
+ }
}🤖 Prompt for AI Agents
In src/components/common/ErrorBoundary.tsx around lines 31 to 35, wrap the call
to recordAnalyticsEvent(...) in a try-catch so that any exceptions thrown by the
analytics layer cannot propagate from componentDidCatch; inside the try call
recordAnalyticsEvent with the same payload (message, stack, componentStack) and
in the catch block swallow the error or minimally log it (e.g., console.error)
so the error boundary remains stable.
Overview: This change integrates the
ErrorBoundarycomponent with the analytics client to report caught JavaScript errors, improving error visibility.Changes
recordAnalyticsEventfromsrc/lib/analytics-client.ts.recordAnalyticsEventwithincomponentDidCatchinsrc/components/common/ErrorBoundary.tsx.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.