From ad66511429e98afcc17a12ab9609aa4fdacac103 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Wed, 1 Jul 2026 22:08:30 -0500 Subject: [PATCH] remove unnecessary sentry logging --- src/app/components/IncomingCallModal.tsx | 24 --------------- src/app/hooks/useCallSignaling.ts | 9 ------ src/app/utils/debugLogger.ts | 16 ++++++---- src/app/utils/sentryScrubbers.test.ts | 37 +++++++++++++++++++++++- src/app/utils/sentryScrubbers.ts | 37 ++++++++++++++++++++++++ src/instrument.ts | 10 ++++--- 6 files changed, 90 insertions(+), 43 deletions(-) diff --git a/src/app/components/IncomingCallModal.tsx b/src/app/components/IncomingCallModal.tsx index 3612ab44d..ecb674cb8 100644 --- a/src/app/components/IncomingCallModal.tsx +++ b/src/app/components/IncomingCallModal.tsx @@ -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, diff --git a/src/app/hooks/useCallSignaling.ts b/src/app/hooks/useCallSignaling.ts index e573749b5..14f38ec6f 100644 --- a/src/app/hooks/useCallSignaling.ts +++ b/src/app/hooks/useCallSignaling.ts @@ -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, diff --git a/src/app/utils/debugLogger.ts b/src/app/utils/debugLogger.ts index 88f787328..6347df784 100644 --- a/src/app/utils/debugLogger.ts +++ b/src/app/utils/debugLogger.ts @@ -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 = {}; - 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).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(), }, }, diff --git a/src/app/utils/sentryScrubbers.test.ts b/src/app/utils/sentryScrubbers.test.ts index 9518705c9..f16884be6 100644 --- a/src/app/utils/sentryScrubbers.test.ts +++ b/src/app/utils/sentryScrubbers.test.ts @@ -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]', + }); + }); +}); diff --git a/src/app/utils/sentryScrubbers.ts b/src/app/utils/sentryScrubbers.ts index 1ace61f44..cc75fe369 100644 --- a/src/app/utils/sentryScrubbers.ts +++ b/src/app/utils/sentryScrubbers.ts @@ -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) + .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. diff --git a/src/instrument.ts b/src/instrument.ts index 4dc0e5f58..02c0a6441 100644 --- a/src/instrument.ts +++ b/src/instrument.ts @@ -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) : undefined; + const scrubbedData = bData + ? (sanitizeSentryPayload(bData) as Record) + : 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