Send to Sentry

Send editor failures to Sentry and exclude document content from Replay, breadcrumbs, and URLs.

@docx-editor.dev/telemetry is available in version 2.29.0 and later.

Register the Sentry exporter

Pass your app's Sentry module to sentryExporter, then register telemetry.module in the editor:

import * as Sentry from '@sentry/react';
import { createTelemetry } from '@docx-editor.dev/telemetry';
import { sentryExporter } from '@docx-editor.dev/telemetry/sentry';

export const telemetry = createTelemetry({ exporters: [sentryExporter(Sentry)] });

The exporter uses the Sentry module from any Sentry JavaScript SDK. For registration and consent, see Set up an editor.

Protect document content

Block the editor in Replay and drop editor breadcrumbs. Call dropEditorBreadcrumbs first, then apply your own filter to what it keeps:

import * as Sentry from '@sentry/react';
import { dropEditorBreadcrumbs, EDITOR_SELECTORS } from '@docx-editor.dev/telemetry/sentry';

Sentry.init({
  dsn: import.meta.env.VITE_SENTRY_DSN,
  dataCollection: {
    userInfo: false,
    cookies: false,
    httpHeaders: false,
    httpBodies: [],
    urlQueryParams: false,
  },
  integrations: [Sentry.replayIntegration({ block: [...EDITOR_SELECTORS] })],
  beforeBreadcrumb: (crumb, hint) => {
    const kept = dropEditorBreadcrumbs(crumb, hint);
    return kept?.category === 'console' ? null : kept;
  },
  beforeSend: (event) => {
    // Remove identifiers from the URL before the event leaves the browser.
    if (event.request?.url) event.request.url = event.request.url.split('?')[0];
    return event;
  },
});
  • EDITOR_SELECTORS in block replaces the editor with a placeholder in Replay. You do not need mask.
  • dropEditorBreadcrumbs drops editor click and key breadcrumbs. Their alt, title, and aria-label values can hold document content.
  • dataCollection stops user, cookie, header, request body, and query parameter collection. Sentry SDKs before version 11 use sendDefaultPii: false instead.
  • The console filter drops console breadcrumbs, in case your code logs document details.

Choose issue behavior

Failures become grouped issues. Other events become breadcrumbs, which appear beside your errors without using event quota.

EventDefault
document.open rejected because of the app or an unexplained engine errorIssue
document.open rejected for a corrupt or oversized fileBreadcrumb
document.save rejected with save.failedIssue
edit.rejected with edit.internal-invariantIssue
review.skipped with review.revision-unsupported or review.retained-structureWarning issue
font.failed with font.shaper-unavailableIssue
collab.status error that does not recoverIssue
collab.status for an expired token or compacted roomBreadcrumb (the client rejoins)
Everything elseBreadcrumb
Option or helperBehavior
issue: (event) => booleanReplaces the classification. Combine with isSentryIssue(event) to extend the default.
breadcrumbsRecords breadcrumbs for other events. Defaults to true.
FingerprintDiagnostic code, engine reason, and change kind.
TagsFailure detail tags such as docx_editor.cause and docx_editor.change_kind.

Limits

  • The page URL is on every event and on navigation and fetch breadcrumbs. Remove identifiers in beforeSend and beforeBreadcrumb.
  • Removing query strings does not remove identifiers in URL paths or other fields.
  • On a server, request bodies can attach to issues. If an endpoint receives document bytes or agent instructions, remove event.request.data in beforeSend.
  • Uncaught errors carry JavaScript messages and stack traces that the package does not control. Check them for document content.

See also