Other log services
Forward editor telemetry to Axiom or Datadog Logs, or validate events without Fetch requests.
@docx-editor.dev/telemetry is available in version 2.29.0 and later.Each recipe replaces only forward in the route from Send to a log service. Keep its other options, such as allowedOrigins and onError.
Forward to Axiom
Axiom reads the time from _time. Create a dataset and an API token with ingest access:
// app/api/telemetry/route.ts
import { telemetryRoute, toLogRecord } from '@docx-editor.dev/telemetry/ingest';
export const POST = telemetryRoute({
forward: (events) =>
fetch(`https://api.axiom.co/v1/datasets/${process.env.AXIOM_DATASET}/ingest`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
},
body: JSON.stringify(
events.map((event) => ({
...toLogRecord(event),
_time: new Date(event.time).toISOString(),
}))
),
}),
});Forward to Datadog Logs
Use the logs intake URL for your Datadog site and an API key:
// app/api/telemetry/route.ts
import { telemetryRoute, toLogRecord } from '@docx-editor.dev/telemetry/ingest';
export const POST = telemetryRoute({
forward: (events) =>
fetch('https://http-intake.logs.datadoghq.com/api/v2/logs', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'DD-API-KEY': String(process.env.DD_API_KEY),
},
body: JSON.stringify(
events.map((event) => ({
...toLogRecord(event),
ddsource: 'docx-editor',
service: 'my-app',
}))
),
}),
});Validate without Fetch
If your framework does not use Fetch Request objects, pass the parsed body to validateTelemetryEvents. It returns the events that pass, or an empty list:
import { toLogRecord, validateTelemetryEvents } from '@docx-editor.dev/telemetry/ingest';
export function recordsFrom(body: unknown) {
return validateTelemetryEvents(body).map(toLogRecord);
}Limits
- Keep provider tokens on the server.
validateTelemetryEventsskips body size, origin, and rate checks. Enforce them yourself.