HTTP exporter and route reference
Configure HTTP event batches, delivery, filtering, and server validation.
@docx-editor.dev/telemetry is available in version 2.29.0 and later.Use this reference to configure HTTP export and server validation. For the setup steps, see Send to a log service.
httpExporter
httpExporter posts a JSON array of events to your route. While the page is open, it sends a batch when batchSize events are waiting or flushIntervalMs has passed. When you call telemetry.flush() on an open page, it sends everything with fetch. When the page becomes hidden, it sends queued events with navigator.sendBeacon. Delivery can continue while the tab closes.
A closing page has a total delivery budget of about 64 KiB. Delivery is best effort. The exporter drops events beyond that budget and reports them to onError. If you withdraw consent, it discards queued events.
| Option | Default | What it does |
|---|---|---|
url | Required | The route to post to. Use a path on your own origin. |
batchSize | 20 | Events per request, from 1 to 50. Keep it at or below the route's maxEvents, which defaults to 50. The route refuses larger batches. |
flushIntervalMs | 10000 | How long an event waits for its batch to fill. |
headers | None | Extra request headers. With headers, the batches sent while the page closes use fetch with keepalive, because sendBeacon cannot send headers. |
onError | None | Called when a request fails or a closing page drops events. The exporter never throws into your app. |
filter
filter decides which events reach your exporters. Metrics still count every event. Filter by event kind to include summaries of repeated refusals. These summaries carry repeated. isFailure returns false for them.
browserPrivacySignals
browserPrivacySignals returns a consent function. It returns false outside a browser page. To combine it with your consent manager, call both: consent: () => privacy() && consentManager.analytics.
telemetryRoute
telemetryRoute returns a Fetch-style POST handler for Next.js route handlers, Hono, Bun, Deno, and Cloudflare Workers. For each request, it does the following:
- Ignores any method other than
POST. - Refuses an origin outside
allowedOrigins, when you set it. - Reads at most
maxBodyBytes(64 KiB, counted in bytes) and refuses an array longer thanmaxEvents(50). If you raisemaxEvents, the browser'sbatchSizestill stops at 50. - Checks every event with the same closed lists that the browser used. It drops events with unknown kinds or codes, or missing required fields. It removes fields outside their allowed lists.
- Drops the
resourceandattributesthat the browser set, except the keys you list inattributeKeys. Add your fixed fields, such as a service name, on the server instead. - Calls
forwardwith the events that pass.
The handler returns 204 for every request. Use onError to see failures, including a log service that refuses the request. Apply rate limits through your platform; the route does not enforce them.
toLogRecord
toLogRecord(event) adds dt for the timestamp and message for a one-line summary. For example, the summary can be edit.rejected edit.picture-selected. It removes hint and docs, which you can look up from the diagnostic code.