Identify rooms and users

Add room, user, and tenant identifiers to events while limiting metric series.

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

Add identifiers to telemetry events to find the room or user affected by a problem.

Attach identifiers to an editor

The following example adds page-wide attributes on the client and a room ID per editor. telemetry.moduleFor(attributes) replaces telemetry.module:

import { useMemo } from 'react';
import { DocxEditor } from '@docx-editor.dev/react';
import { createTelemetry } from '@docx-editor.dev/telemetry';
import { otelExporter } from '@docx-editor.dev/telemetry/otel';

const session = { tenantId: 'acme', pseudonymousUserId: 'u-5f2c', tenantTier: 'enterprise' };

export const telemetry = createTelemetry({
  exporters: [otelExporter()],
  attributes: () => ({
    'tenant.id': session.tenantId,
    'user.id': session.pseudonymousUserId,
    'tenant.tier': session.tenantTier,
  }),
  metricLabels: ['tenant.tier'],
});

export function Editor({ bytes, roomId }: { bytes: Uint8Array; roomId: string }) {
  const modules = useMemo(() => [telemetry.moduleFor({ 'room.id': roomId })], [roomId]);
  return <DocxEditor key={roomId} document={bytes} modules={modules} />;
}

Every event then carries tenant.id, user.id, tenant.tier, and room.id in attributes. The engine never adds a value to attributes, and the values go only to your exporters.

Choose attribute scope

WhereScopeReaches
attributes on createTelemetryEvery editor on the page. A function runs for each event.All events.
telemetry.moduleFor(attributes)One editor, such as its room or document.That editor's events.
metricLabelsAttribute keys you select.Metrics, as labels.
DestinationHow attributes appear
SentryIssue tags, searchable by room or user.
OpenTelemetrySpan event attributes under the same keys.
Callbackevent.attributes.
MetricsOnly keys in metricLabels.

Use metric labels with few values, such as tenant tier or region. Keep user, room, and document IDs on events.

Correlate sessions

Every event has a random editorSessionId for its editor instance. The following client tags later Sentry errors and replays with it:

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

export const telemetry = createTelemetry({
  exporters: [
    otelExporter(),
    callbackExporter((event) => {
      Sentry.setTag('docx_editor.editor_session', event.editorSessionId);
    }),
  ],
});

Sentry.setTag sets the tag for the whole page. With two editors on a page, the tag names the editor that sent the last event.

The OpenTelemetry exporter adds events to the active span, so events join your existing traces. Issues from the Sentry exporter already carry the docx_editor.editor_session tag.

Limits

  • After 50 distinct values for a metric label key, metrics record later values as other. Events keep the original values.
  • Avoid labels that differ per browser tab. Each tab's cumulative counters become a separate series; configure delta temporality in the browser SDK instead.
  • Sentry.setTag() applies to the whole page. With two editors, the tag names the editor that sent the last event.
  • editorSessionId identifies an editor instance, not a person or document. Use pseudonymous IDs, never names or email addresses. For more information, see Privacy.

See also