Skip to content

Frontend API

Install the frontend package:

Terminal window
npm install @auditaur/api@0.2.1

Initialize Auditaur once in the Tauri webview:

import { initAuditaur } from '@auditaur/api';
const auditaur = await initAuditaur({
serviceName: 'my-tauri-app',
instrumentConsole: true,
instrumentErrors: true,
instrumentTauriInvoke: true,
propagateTauriInvokeTraceContext: true,
instrumentTauriEvents: true,
captureFullPayloads: false,
onExportError(failure) {
console.warn('Auditaur export failed', failure.error);
},
});
export const invoke = auditaur.invoke;

For existing apps with many direct @tauri-apps/api/core imports, prefer a local wrapper such as src\services\tauri.ts that exports auditaur.invoke. Auditaur does not globally monkey-patch Tauri’s invoke, so direct imports continue to work but are not captured until migrated.

The returned client exposes:

MethodPurpose
invoke(command, args)Wraps Tauri command calls in client spans.
emit(event, payload) / emitTo(target, event, payload)Records event emit spans.
listen(event, handler)Records event receive spans.
createOpenTelemetrySpanExporter()Returns a span exporter that can be attached to an existing OpenTelemetry JS tracer provider.
flush()Writes the current batch immediately.
shutdown()Removes console/error hooks and flushes pending telemetry.

Console and error instrumentation are enabled by default. Full payload capture is disabled by default; payload summaries and recursive key-based redaction help reduce accidental secret capture.

The frontend invoke/event wrappers emit Auditaur’s OTEL-shaped records directly and map them into SQLite spans plus Tauri-specific rows. When instrumentTauriInvoke is enabled, propagateTauriInvokeTraceContext defaults to true and sends W3C traceparent through Tauri invoke request headers plus the reserved auditaurTraceContext invoke argument for compatibility with older instrument_ipc commands. If your app already uses an argument named auditaurTraceContext, Auditaur leaves it untouched and skips propagation for that call; set propagateTauriInvokeTraceContext: false to disable this bridge globally.

For custom invoke wrappers, import AUDITAUR_TRACE_CONTEXT_ARG and createAuditaurTraceContext() to use the same reserved carrier as Auditaur’s built-in wrapper:

import { AUDITAUR_TRACE_CONTEXT_ARG, createAuditaurTraceContext } from '@auditaur/api';
const args = {
id: 'user-1',
[AUDITAUR_TRACE_CONTEXT_ARG]: createAuditaurTraceContext(),
};

onExportError is optional. Failed exports are requeued up to the exporter retention cap; the callback receives the original error plus attempted, queued, retained, and dropped record counts so development UIs or agents can surface collection problems.

To sink spans emitted through an existing OpenTelemetry JS tracer provider, attach the Auditaur exporter as another span processor:

Terminal window
npm install @opentelemetry/api @opentelemetry/sdk-trace-base
import { BasicTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { initAuditaur } from '@auditaur/api';
const auditaur = await initAuditaur({ serviceName: 'my-tauri-app' });
const provider = new BasicTracerProvider({
spanProcessors: [
new SimpleSpanProcessor(auditaur.createOpenTelemetrySpanExporter()),
],
});

If your app already creates a provider, add the span processor to that existing provider configuration instead of installing another global provider. SimpleSpanProcessor is usually enough because Auditaur batches before calling the Tauri plugin. The exporter preserves OpenTelemetry trace/span ids, span kind/status, instrumentation scope, resource attributes, events, and links in the existing SQLite span mapping. Metrics, logs from the OpenTelemetry logs SDK, and automatic instrumentation setup are still planned.