Beignet API reference
    Preparing search index...

    Function createAmbientAuditLog

    Ambient audit enrichment for app audit ports.

    • Wrap an audit log port so missing actor, tenant, requestId, and traceId fields are filled from the ambient request context at record time.

      The server keeps the ambient context current for requests (including identity elevated by hooks) and for service contexts created for jobs, listeners, schedules, and tasks. Because enrichment happens when record(...) runs, the wrapper also works for ports rebuilt per transaction inside a unit of work — wrap both the top-level audit port and the per-transaction rebuild.

      Fields provided on the entry always win; only missing fields are filled. When no ambient context is active (for example on runtimes without AsyncLocalStorage propagation), entries pass through unchanged.

      Parameters

      • audit: AuditLogPort

        Underlying audit log port to write enriched entries to.

      Returns AuditLogPort

      An audit log port that fills missing context fields before writing.

      const audit = createAmbientAuditLog(
      createInstrumentedAuditLog({
      audit: createDrizzleSqliteAuditLogPort(db),
      instrumentation: ports,
      }),
      );
      await audit.record({ action: "posts.publish", resource: { type: "post", id } });