Add tags to Sentry error reports (#16465)

GitOrigin-RevId: 1d014e8cc9f87d249a285b247c35f12465ecb93a
This commit is contained in:
Alf Eaton 2024-02-01 09:47:14 +00:00 committed by Copybot
parent 614d1d05cc
commit cac1ab1259
3 changed files with 25 additions and 21 deletions

View file

@ -1,15 +0,0 @@
import { Extension } from '@codemirror/state'
import { EditorView } from '@codemirror/view'
import { captureException } from '../../../infrastructure/error-reporter'
/**
* A custom extension which configures the EditorView.exceptionSink facet
* so that exceptions are sent to Sentry with a `cm6-exception` tag.
*/
export const exceptionLogger = (): Extension => {
return EditorView.exceptionSink.of(exception => {
captureException(exception, {
tags: { handler: 'cm6-exception' },
})
})
}

View file

@ -29,7 +29,6 @@ import { filterCharacters } from './filter-characters'
import { keybindings } from './keybindings' import { keybindings } from './keybindings'
import { bracketMatching, bracketSelection } from './bracket-matching' import { bracketMatching, bracketSelection } from './bracket-matching'
import { verticalOverflow } from './vertical-overflow' import { verticalOverflow } from './vertical-overflow'
import { exceptionLogger } from './exception-logger'
import { thirdPartyExtensions } from './third-party-extensions' import { thirdPartyExtensions } from './third-party-extensions'
import { lineNumbers } from './line-numbers' import { lineNumbers } from './line-numbers'
import { highlightActiveLine } from './highlight-active-line' import { highlightActiveLine } from './highlight-active-line'
@ -132,7 +131,8 @@ export const createExtensions = (options: Record<string, any>): Extension[] => [
highlightActiveLineGutter(), highlightActiveLineGutter(),
inlineBackground(options.visual.visual), inlineBackground(options.visual.visual),
codemirrorDevTools(), codemirrorDevTools(),
exceptionLogger(), // Send exceptions to Sentry
EditorView.exceptionSink.of(options.handleException),
// CodeMirror extensions provided by modules // CodeMirror extensions provided by modules
moduleExtensions.map(extension => extension()), moduleExtensions.map(extension => extension()),
thirdPartyExtensions(), thirdPartyExtensions(),

View file

@ -54,6 +54,8 @@ import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-
import { useUserSettingsContext } from '@/shared/context/user-settings-context' import { useUserSettingsContext } from '@/shared/context/user-settings-context'
import { setDocName } from '@/features/source-editor/extensions/doc-name' import { setDocName } from '@/features/source-editor/extensions/doc-name'
import isValidTexFile from '@/main/is-valid-tex-file' import isValidTexFile from '@/main/is-valid-tex-file'
import { captureException } from '@/infrastructure/error-reporter'
import grammarlyExtensionPresent from '@/shared/utils/grammarly'
function useCodeMirrorScope(view: EditorView) { function useCodeMirrorScope(view: EditorView) {
const ide = useIdeContext() const ide = useIdeContext()
@ -241,13 +243,31 @@ function useCodeMirrorScope(view: EditorView) {
const { previewByPath } = useFileTreePathContext() const { previewByPath } = useFileTreePathContext()
const showVisual = visual && isValidTexFile(docName)
const visualRef = useRef({ const visualRef = useRef({
previewByPath, previewByPath,
visual, visual: showVisual,
}) })
const handleError = useErrorHandler() const handleError = useErrorHandler()
const handleException = useCallback((exception: any) => {
captureException(exception, {
tags: {
handler: 'cm6-exception',
// which editor mode is active ('visual' | 'code')
ol_editor_mode: visualRef.current.visual ? 'visual' : 'code',
// which editor keybindings are active ('default' | 'vim' | 'emacs')
ol_editor_keybindings: settingsRef.current.mode,
// whether Writefull is present ('extension' | 'integration')
ol_extensions_writefull: window.writefull?.type,
// whether Grammarly is present
ol_extensions_grammarly: grammarlyExtensionPresent(),
},
})
}, [])
// create a new state when currentDoc changes // create a new state when currentDoc changes
useEffect(() => { useEffect(() => {
@ -268,6 +288,7 @@ function useCodeMirrorScope(view: EditorView) {
visual: visualRef.current, visual: visualRef.current,
changeManager: createChangeManager(view, currentDoc), changeManager: createChangeManager(view, currentDoc),
handleError, handleError,
handleException,
}), }),
}) })
view.setState(state) view.setState(state)
@ -297,7 +318,7 @@ function useCodeMirrorScope(view: EditorView) {
} }
// IMPORTANT: This effect must not depend on anything variable apart from currentDoc, // IMPORTANT: This effect must not depend on anything variable apart from currentDoc,
// as the editor state is recreated when the effect runs. // as the editor state is recreated when the effect runs.
}, [view, currentDoc, handleError]) }, [view, currentDoc, handleError, handleException])
useEffect(() => { useEffect(() => {
if (docName) { if (docName) {
@ -314,8 +335,6 @@ function useCodeMirrorScope(view: EditorView) {
} }
}, [view, docName]) }, [view, docName])
const showVisual = visual && isValidTexFile(docName)
useEffect(() => { useEffect(() => {
visualRef.current.visual = showVisual visualRef.current.visual = showVisual
view.dispatch(setVisual(visualRef.current)) view.dispatch(setVisual(visualRef.current))