Filtering Events
Control which events are sent to Syntropy.
beforeSend Hook
The beforeSend hook is called before each event is sent:
Syntropy.init({
projectId: 'your-project-id',
beforeSend: (event) => {
// Return the event to send it
// Return null to drop it
return event;
},
});
Dropping Events
By Error Message
beforeSend: (event) => {
const message = event.payload.message || '';
// Drop common noise
if (message.includes('ResizeObserver loop')) return null;
if (message.includes('Script error')) return null;
if (message.includes('Network request failed')) return null;
return event;
}
By Error Type
beforeSend: (event) => {
// Only send error events
if (event.type !== 'error') return null;
return event;
}
By URL
beforeSend: (event) => {
const url = event.payload.url || window.location.href;
// Don't track admin pages
if (url.includes('/admin')) return null;
// Don't track development
if (url.includes('localhost')) return null;
return event;
}
Modifying Events
Scrub Sensitive Data
beforeSend: (event) => {
// Scrub passwords
if (event.payload.extra?.password) {
event.payload.extra.password = '[REDACTED]';
}
// Scrub credit cards
if (event.payload.extra?.cardNumber) {
event.payload.extra.cardNumber = '[REDACTED]';
}
// Scrub from breadcrumbs
event.payload.breadcrumbs?.forEach(crumb => {
if (crumb.data?.password) {
crumb.data.password = '[REDACTED]';
}
});
return event;
}
Add Context
beforeSend: (event) => {
// Add custom context
event.payload.extra = {
...event.payload.extra,
appVersion: APP_VERSION,
buildTime: BUILD_TIME,
featureFlags: getFeatureFlags(),
};
return event;
}
Normalize Errors
beforeSend: (event) => {
// Normalize error messages for better grouping
if (event.payload.message) {
// Remove variable parts
event.payload.message = event.payload.message
.replace(/user_\d+/g, 'user_XXX')
.replace(/order_[a-f0-9]+/g, 'order_XXX');
}
return event;
}
Environment-Based Filtering
Development
Syntropy.init({
projectId: 'your-project-id',
enabled: process.env.NODE_ENV === 'production',
});
Specific Environments
beforeSend: (event) => {
// Don't send in staging
if (process.env.NODE_ENV === 'staging') {
return null;
}
return event;
}
Rate Limiting
Use sampleRate to limit events:
Syntropy.init({
projectId: 'your-project-id',
sampleRate: 0.5, // Only send 50% of events
});
For more control:
let errorCount = 0;
const MAX_ERRORS_PER_MINUTE = 10;
setInterval(() => { errorCount = 0; }, 60000);
beforeSend: (event) => {
if (event.type === 'error') {
errorCount++;
if (errorCount > MAX_ERRORS_PER_MINUTE) {
return null; // Drop excess errors
}
}
return event;
}