What Gets Logged
Every audit log entry contains these fields:| Field | Type | Description |
|---|---|---|
id | string | Unique log entry ID |
organizationId | string | Organization where the action occurred |
actorId | string | ID of the user, API key, or system process |
actorType | "user" | "api_key" | "system" | What performed the action |
actorEmail | string | Email of the user (if actorType is user) |
action | string | Action identifier (e.g., organization.updated) |
resourceType | string | Type of resource affected (e.g., organization, member) |
resourceId | string | ID of the affected resource |
oldValues | object | Previous state of changed fields |
newValues | object | New state of changed fields |
ipAddress | string | Client IP address |
userAgent | string | Client user agent string |
metadata | object | Additional context |
createdAt | timestamp | When the action occurred |
Example entry
Creating Audit Log Entries
The audit service provides typed helper methods for different actor types.User actions
API key actions
System actions
Querying Audit Logs
List audit logs with filters, pagination, and date ranges:Available filters
| Parameter | Type | Description |
|---|---|---|
actorId | string | Filter by actor ID |
actorType | string | Filter by actor type (user, api_key, system) |
action | string | Filter by action (e.g., member.added) |
resourceType | string | Filter by resource type (e.g., organization) |
resourceId | string | Filter by specific resource |
startDate | ISO date | Entries after this date |
endDate | ISO date | Entries before this date |
limit | number | Results per page (default: 50) |
offset | number | Pagination offset (default: 0) |
Response format
total field returns the full count of matching entries, so your frontend can calculate page numbers.
Filtering by date range
Log Retention
Audit logs are cleaned up automatically by the background jobs system. Retention periods depend on your plan:| Plan | Retention |
|---|---|
| Free | Not available |
| Pro | 30 days |
| Enterprise | 1 year |
Adjust the
daysToKeep value in apps/api/src/jobs/index.ts to change the retention period.Integration with Other Features
Audit logs are created automatically throughout BunShip. Here are the key integration points:Authentication
Login attempts, password changes, 2FA setup, and session revocations are logged with the user’s
IP address and user agent.
Team Management
Member invitations, role changes, and removals record both the actor and the affected member.
Billing
Subscription changes, checkout completions, and cancellations are logged as system actions
triggered by Stripe webhooks.
API Keys
Key creation and revocation are logged. Requests authenticated with API keys use
actorType: "api_key" for attribution.Adding audit logs to custom routes
When building new features, add audit logging at the service layer:stderr and an InternalError is thrown, which the global error handler catches.
