-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathSentrySettings.tsx
More file actions
153 lines (143 loc) · 5.27 KB
/
SentrySettings.tsx
File metadata and controls
153 lines (143 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { useState, useEffect } from 'react';
import { Box, Text, Switch, Button } from 'folds';
import { SequenceCard } from '$components/sequence-card';
import { SettingTile } from '$components/setting-tile';
import { SequenceCardStyle } from '$features/settings/styles.css';
import { getDebugLogger, LogCategory } from '$utils/debugLogger';
const ALL_CATEGORIES: LogCategory[] = [
'sync',
'network',
'notification',
'message',
'call',
'ui',
'timeline',
'error',
'general',
];
export function SentrySettings() {
const [categoryEnabled, setCategoryEnabled] = useState<Record<LogCategory, boolean>>(() => {
const logger = getDebugLogger();
return Object.fromEntries(
ALL_CATEGORIES.map((c) => [c, logger.getBreadcrumbCategoryEnabled(c)])
) as Record<LogCategory, boolean>;
});
const [sentryStats, setSentryStats] = useState(() => getDebugLogger().getSentryStats());
useEffect(() => {
const interval = setInterval(() => {
setSentryStats(getDebugLogger().getSentryStats());
}, 5000);
return () => clearInterval(interval);
}, []);
const handleCategoryToggle = (category: LogCategory, enabled: boolean) => {
getDebugLogger().setBreadcrumbCategoryEnabled(category, enabled);
setCategoryEnabled((prev) => ({ ...prev, [category]: enabled }));
};
const handleExportLogs = () => {
const data = getDebugLogger().exportLogs();
const blob = new Blob([data], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `sable-debug-logs-${Date.now()}.json`;
a.click();
URL.revokeObjectURL(url);
};
const isSentryConfigured = Boolean(import.meta.env.VITE_SENTRY_DSN);
const sentryEnabled = localStorage.getItem('sable_sentry_enabled') === 'true';
const environment = import.meta.env.VITE_SENTRY_ENVIRONMENT || import.meta.env.MODE;
const isProd = environment === 'production';
const traceSampleRate = isProd ? '10%' : '100%';
const replaySampleRate = isProd ? '10%' : '100%';
return (
<Box direction="Column" gap="100">
<Text size="L400">Error Tracking (Sentry)</Text>
<Text size="T200" style={{ opacity: 0.7 }}>
Error reporting toggles are in <strong>Settings → General → Diagnostics & Privacy</strong>.
</Text>
{!isSentryConfigured && (
<Box
style={{
padding: '12px',
backgroundColor: 'rgba(255, 193, 7, 0.1)',
borderRadius: '8px',
}}
>
<Text size="T300" style={{ color: 'orange' }}>
Sentry is not configured. Set VITE_SENTRY_DSN to enable error tracking.
</Text>
</Box>
)}
{isSentryConfigured && sentryEnabled && (
<>
<Text size="L400">Performance Metrics</Text>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="Traces & Profiles"
description={`Current environment: ${environment}. Sample rate: ${traceSampleRate}`}
/>
<SettingTile
title="Session Replay"
description={`Session sample rate: ${replaySampleRate} · On-error rate: 100%`}
/>
<SettingTile
title="Session Error Budget"
description="At most 50 error events are forwarded to Sentry per page load to prevent quota exhaustion."
/>
</SequenceCard>
<Text size="L400">Breadcrumb Categories</Text>
<Text size="T200" style={{ opacity: 0.7 }}>
Control which log categories are included as breadcrumbs in Sentry error reports.
Disabling a category reduces noise without affecting error capture.
</Text>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
{ALL_CATEGORIES.map((cat) => (
<SettingTile
key={cat}
title={cat.charAt(0).toUpperCase() + cat.slice(1)}
after={
<Switch
variant="Primary"
value={categoryEnabled[cat]}
onChange={(v) => handleCategoryToggle(cat, v)}
/>
}
/>
))}
</SequenceCard>
<Text size="L400">Debug Logs</Text>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="Session Activity"
description={`Errors captured: ${sentryStats.errors} · Warnings captured: ${sentryStats.warnings} (updates every 5 s)`}
/>
<SettingTile
title="Export Debug Logs"
description="Download the current in-memory debug log buffer as a JSON file for offline analysis."
after={
<Button variant="Secondary" size="300" onClick={handleExportLogs}>
Export JSON
</Button>
}
/>
</SequenceCard>
</>
)}
</Box>
);
}