mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-30 13:52:44 -08:00
remove unnecessary sentry logging
This commit is contained in:
1 parent
efeca7ff7a
commit
ad66511429
6 files changed
+90
-43
No files matched your search
@@ -124,14 +124,6 @@ export function IncomingCallInternal({ room, incomingCall, onClose }: IncomingCa
|
||||
notificationType: incomingCall.notificationType,
|
||||
intent: incomingCall.intentRaw,
|
||||
});
|
||||
Sentry.addBreadcrumb({
|
||||
category: 'call.signal',
|
||||
message: 'Incoming call answered',
|
||||
data: {
|
||||
roomId: room.roomId,
|
||||
notificationEventId: incomingCall.notificationEventId,
|
||||
},
|
||||
});
|
||||
Sentry.metrics.count('sable.call.answered', 1, {
|
||||
attributes: {
|
||||
type: incomingCall.notificationType,
|
||||
@@ -156,14 +148,6 @@ export function IncomingCallInternal({ room, incomingCall, onClose }: IncomingCa
|
||||
notificationEventId: incomingCall.notificationEventId,
|
||||
notificationType: incomingCall.notificationType,
|
||||
});
|
||||
Sentry.addBreadcrumb({
|
||||
category: 'call.signal',
|
||||
message: `Incoming call ${action}`,
|
||||
data: {
|
||||
roomId: room.roomId,
|
||||
notificationEventId: incomingCall.notificationEventId,
|
||||
},
|
||||
});
|
||||
Sentry.metrics.count(`sable.call.${action}d`, 1, {
|
||||
attributes: {
|
||||
type: incomingCall.notificationType,
|
||||
@@ -196,14 +180,6 @@ export function IncomingCallInternal({ room, incomingCall, onClose }: IncomingCa
|
||||
notificationEventId: incomingCall.notificationEventId,
|
||||
notificationType: incomingCall.notificationType,
|
||||
});
|
||||
Sentry.addBreadcrumb({
|
||||
category: 'call.signal',
|
||||
message: `Incoming call ${action}`,
|
||||
data: {
|
||||
roomId: room.roomId,
|
||||
notificationEventId: incomingCall.notificationEventId,
|
||||
},
|
||||
});
|
||||
Sentry.metrics.count(`sable.call.${action}d`, 1, {
|
||||
attributes: {
|
||||
type: incomingCall.notificationType,
|
||||
|
||||
@@ -254,15 +254,6 @@ export function useIncomingCallSignaling() {
|
||||
notificationType: nextIncomingCall.notificationType,
|
||||
intent: nextIncomingCall.intentRaw,
|
||||
});
|
||||
Sentry.addBreadcrumb({
|
||||
category: 'call.signal',
|
||||
message: 'Incoming RTC notification',
|
||||
data: {
|
||||
roomId: nextIncomingCall.roomId,
|
||||
notificationType: nextIncomingCall.notificationType,
|
||||
intent: nextIncomingCall.intentRaw,
|
||||
},
|
||||
});
|
||||
Sentry.metrics.count('sable.call.incoming.shown', 1, {
|
||||
attributes: {
|
||||
type: nextIncomingCall.notificationType,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { sanitizeSentryPayload } from './sentryScrubbers';
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
|
||||
@@ -160,13 +161,18 @@ class DebugLoggerService {
|
||||
};
|
||||
const sentryLevel: Sentry.SeverityLevel = sentryLevelMap[entry.level] ?? 'error';
|
||||
|
||||
const sanitizedData = entry.data !== undefined ? sanitizeSentryPayload(entry.data) : undefined;
|
||||
|
||||
// Add breadcrumb for all logs (helps with debugging in Sentry), unless category is disabled
|
||||
if (!this.disabledBreadcrumbCategories.has(entry.category))
|
||||
Sentry.addBreadcrumb({
|
||||
category: `${entry.category}.${entry.namespace}`,
|
||||
message: entry.message,
|
||||
level: sentryLevel,
|
||||
data: entry.data ? { data: entry.data } : undefined,
|
||||
data:
|
||||
sanitizedData !== undefined && sanitizedData !== null
|
||||
? { data: sanitizedData }
|
||||
: undefined,
|
||||
timestamp: entry.timestamp / 1000, // Sentry expects seconds
|
||||
});
|
||||
|
||||
@@ -174,8 +180,8 @@ class DebugLoggerService {
|
||||
const logMsg = `[${entry.category}:${entry.namespace}] ${entry.message}`;
|
||||
// Flatten primitive values from entry.data so they become searchable attributes in Sentry Logs
|
||||
const logDataAttrs: Record<string, string | number | boolean> = {};
|
||||
if (entry.data && typeof entry.data === 'object' && !(entry.data instanceof Error)) {
|
||||
Object.entries(entry.data).forEach(([k, v]) => {
|
||||
if (sanitizedData && typeof sanitizedData === 'object' && !(sanitizedData instanceof Error)) {
|
||||
Object.entries(sanitizedData as Record<string, unknown>).forEach(([k, v]) => {
|
||||
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {
|
||||
logDataAttrs[k] = v;
|
||||
}
|
||||
@@ -226,7 +232,7 @@ class DebugLoggerService {
|
||||
},
|
||||
contexts: {
|
||||
debugLog: {
|
||||
data: entry.data,
|
||||
data: sanitizedData,
|
||||
timestamp: new Date(entry.timestamp).toISOString(),
|
||||
},
|
||||
},
|
||||
@@ -243,7 +249,7 @@ class DebugLoggerService {
|
||||
},
|
||||
contexts: {
|
||||
debugLog: {
|
||||
data: entry.data,
|
||||
data: sanitizedData,
|
||||
timestamp: new Date(entry.timestamp).toISOString(),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { scrubMatrixIds, scrubDataObject, scrubMatrixUrl } from './sentryScrubbers';
|
||||
import {
|
||||
omitSentryIdentifierFields,
|
||||
scrubMatrixIds,
|
||||
scrubDataObject,
|
||||
sanitizeSentryPayload,
|
||||
scrubMatrixUrl,
|
||||
} from './sentryScrubbers';
|
||||
|
||||
// ─── scrubMatrixIds ───────────────────────────────────────────────────────────
|
||||
|
||||
@@ -243,3 +249,32 @@ describe('scrubMatrixUrl – safe inputs', () => {
|
||||
expect(scrubMatrixUrl('')).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('omitSentryIdentifierFields', () => {
|
||||
it('removes identifier keys from call telemetry payloads', () => {
|
||||
expect(
|
||||
omitSentryIdentifierFields({
|
||||
roomId: '!room:example.org',
|
||||
notificationEventId: '$notif',
|
||||
notificationType: 'ring',
|
||||
dm: true,
|
||||
})
|
||||
).toEqual({
|
||||
notificationType: 'ring',
|
||||
dm: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitizeSentryPayload', () => {
|
||||
it('drops identifier keys and redacts remaining Matrix IDs', () => {
|
||||
expect(
|
||||
sanitizeSentryPayload({
|
||||
roomId: '!room:example.org',
|
||||
message: 'from @alice:example.org',
|
||||
})
|
||||
).toEqual({
|
||||
message: 'from @[USER_ID]',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -38,6 +38,43 @@ export function scrubDataObject(data: unknown): unknown {
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Structured fields that should never be sent to Sentry, even redacted. */
|
||||
export const SENTRY_IDENTIFIER_KEYS = new Set([
|
||||
'roomId',
|
||||
'notificationEventId',
|
||||
'refEventId',
|
||||
'senderId',
|
||||
'declineEventId',
|
||||
'eventId',
|
||||
'userId',
|
||||
'targetEventId',
|
||||
'deviceId',
|
||||
'activeNotificationId',
|
||||
'activeRefEventId',
|
||||
'callerId',
|
||||
'recipientId',
|
||||
]);
|
||||
|
||||
/** Drop identifier-bearing keys before values are scrubbed for Sentry export. */
|
||||
export function omitSentryIdentifierFields(data: unknown): unknown {
|
||||
if (Array.isArray(data)) {
|
||||
return data.map(omitSentryIdentifierFields);
|
||||
}
|
||||
if (data !== null && typeof data === 'object') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(data as Record<string, unknown>)
|
||||
.filter(([key]) => !SENTRY_IDENTIFIER_KEYS.has(key))
|
||||
.map(([key, value]) => [key, omitSentryIdentifierFields(value)])
|
||||
);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Full sanitization pass for Sentry breadcrumbs, logs, and contexts. */
|
||||
export function sanitizeSentryPayload(data: unknown): unknown {
|
||||
return scrubDataObject(omitSentryIdentifierFields(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrub Matrix-specific identifiers from URLs that appear in Sentry spans, breadcrumbs,
|
||||
* transaction names, and page URLs. Covers both Matrix API paths and client-side app routes.
|
||||
|
||||
+6
-4
@@ -15,7 +15,7 @@ import {
|
||||
createRoutesFromChildren,
|
||||
matchRoutes,
|
||||
} from 'react-router-dom';
|
||||
import { scrubMatrixIds, scrubDataObject, scrubMatrixUrl } from './app/utils/sentryScrubbers';
|
||||
import { scrubMatrixIds, sanitizeSentryPayload, scrubMatrixUrl } from './app/utils/sentryScrubbers';
|
||||
|
||||
const dsn = import.meta.env.VITE_SENTRY_DSN;
|
||||
const environment = import.meta.env.VITE_SENTRY_ENVIRONMENT || import.meta.env.MODE;
|
||||
@@ -100,7 +100,7 @@ if (dsn && sentryEnabled) {
|
||||
// Redact Matrix IDs from any string-valued log attributes (e.g. roomId, userId)
|
||||
// These are flattened from the structured data object and sent as searchable attributes.
|
||||
if (log.attributes && typeof log.attributes === 'object') {
|
||||
log.attributes = scrubDataObject(log.attributes) as typeof log.attributes;
|
||||
log.attributes = sanitizeSentryPayload(log.attributes) as typeof log.attributes;
|
||||
}
|
||||
return log;
|
||||
},
|
||||
@@ -173,7 +173,9 @@ if (dsn && sentryEnabled) {
|
||||
// Scrub Matrix IDs from all remaining string values in the breadcrumb data object.
|
||||
// debugLog passes structured data (e.g. { roomId, targetEventId }) that would otherwise
|
||||
// bypass the URL-specific scrubbers above.
|
||||
const scrubbedData = bData ? (scrubDataObject(bData) as Record<string, unknown>) : undefined;
|
||||
const scrubbedData = bData
|
||||
? (sanitizeSentryPayload(bData) as Record<string, unknown>)
|
||||
: undefined;
|
||||
|
||||
// Scrub message text — token values and Matrix entity IDs
|
||||
const message = breadcrumb.message ? scrubMatrixIds(breadcrumb.message) : breadcrumb.message;
|
||||
@@ -234,7 +236,7 @@ if (dsn && sentryEnabled) {
|
||||
// Scrub contexts (e.g. debugLog context from captureMessage in debugLogger.ts,
|
||||
// which can carry structured data fields like roomId, targetEventId, etc.)
|
||||
if (event.contexts) {
|
||||
event.contexts = scrubDataObject(event.contexts) as typeof event.contexts;
|
||||
event.contexts = sanitizeSentryPayload(event.contexts) as typeof event.contexts;
|
||||
}
|
||||
|
||||
// Scrub request data
|
||||
|
||||
Reference in new issue
Block a user