Home / Insights / Web and SaaS Development
Web and SaaS Development
Building Audit Logs and Activity History into a SaaS Product
Enterprise buyers now ask about audit logs in the first security review, and support teams need activity history to answer “who changed this?” in minutes. Designing both well from the start is far cheaper than retrofitting them after the first big deal stalls.
TopicsWeb and SaaS DevelopmentArchitecture and Modernization
Key takeaways
- Treat the audit log, the user-facing activity feed and operational application logs as three different products with different audiences, schemas and retention.
- Use one consistent event schema answering who, what, when, where and outcome, with tenant ID on every record; OWASP’s logging guidance is a good template.
- Write audit events in the same transaction as the change, or through a reliable outbox, so the log cannot silently miss actions.
- Make the audit trail append-only and tamper-evident; OWASP recommends integrity controls such as append-only tables for high-value transactions.
- Plan for customer access early: in-app search, CSV export and streaming to the customer’s own storage or SIEM are common enterprise requests.
On this page
- Audit logs, activity history and application logs are different things
- What to record, and what never to record
- Designing the event schema
- Capture and storage architecture: options and trade-offs
- Making the trail trustworthy: integrity, access and retention
- Exposing audit data to customers
- Implementation plan and checklist
- Frequently asked questions
- Sources and methodology
Sooner or later every B2B SaaS product meets the same questions. A customer’s admin wants to know who deleted a project. A security questionnaire asks whether you keep an immutable audit trail of administrative actions. Your own support team needs to see what a user did before reporting a bug. If the product was built without a deliberate audit design, the answers come from scattered application logs, database timestamps and guesswork.
This article is for CTOs, product leads and engineering managers building or scaling a SaaS platform. It explains the difference between audit logs, activity history and operational logs, what to record, how to model and store events, how to make the trail trustworthy, how long to keep it and how to expose it to customers. In PoliteTech’s SaaS product development work we plan roles, tenancy, admin tooling and operations before estimating, and audit logging belongs in that early conversation because it touches every feature that changes data.
Audit logs, activity history and application logs are different things
Teams often try to make one logging system serve every purpose. It rarely works, because the audiences and guarantees differ.
| Aspect | Audit log | Activity history (feed) | Application and operational logs |
|---|---|---|---|
| Primary audience | Customer admins, security and compliance, auditors | End users and collaborators | Your engineers and SRE team |
| Question it answers | Who did what, to which resource, when, from where, and was it allowed? | What happened to this item recently? | Why did the system behave this way? |
| Completeness expectation | Must not miss security-relevant actions | Best effort; can summarise | Sampled or filtered is acceptable |
| Mutability | Append-only, tamper-evident | Can be edited, grouped or hidden | Rotated and discarded |
| Retention | Contractual or regulatory period | Product decision | Short, driven by operations and cost |
| Format | Strict, versioned schema | Human-readable messages | Free text or structured, debug detail |
A sensible architecture generates audit events as the source of truth for security-relevant actions, and derives the user-facing activity feed from them (plus some non-audit events, such as comments). Operational logs stay separate and should never be the place customers look for evidence.
Action for this section
Write one paragraph per log type stating its audience, what it must guarantee and who owns it. That short document prevents months of confusion later.
What to record, and what never to record
The OWASP Logging Cheat Sheet provides a well-tested list of events worth recording. Adapted to a multi-tenant SaaS, the audit log should cover at least:
- Authentication. Sign-in successes and failures, MFA enrolment and changes, SSO configuration changes, password resets.
- Authorisation. Access denials, role and permission changes, invitations, user removal, API key creation and revocation.
- Administrative actions. Tenant settings, billing plan changes, integrations connected or removed, data retention settings.
- Sensitive data access. Exports, bulk downloads, viewing of restricted records, impersonation or “log in as” by your support staff.
- Data lifecycle. Creation, update and deletion of key business objects, especially permanent deletes and restores.
- Consent and legal events. OWASP explicitly lists legal and consent opt-ins as events to log.
Data to keep out of the log
The same cheat sheet is equally clear on exclusions: passwords and authentication secrets, session IDs (hash them if you need correlation), access tokens and encryption keys, connection strings, payment card and bank data, and sensitive personal data such as health or government identifiers should be removed, masked, hashed or encrypted. Pseudonymise personal data where the real identity is not needed. Audit logs are often retained longer than anything else, so a secret that leaks into them stays exposed for years.
Recording changes without copying sensitive values
For updates, store which fields changed and, where safe, old and new values. For sensitive fields, record that the field changed without the values. This gives admins the answer they need (“Jane changed the bank account on this supplier”) without turning the audit log into a second copy of your most sensitive data. Our article on PII redaction, retention and logging decisions covers the same trade-off for AI features.
Designing the event schema
A consistent schema matters more than the storage technology. OWASP’s cheat sheet groups event attributes into when, where, who and what; a SaaS audit event needs those plus tenancy and outcome.
Recommended core fields
| Group | Fields | Notes |
|---|---|---|
| Identity of the event | event_id, schema_version | Unique ID allows deduplication when delivery is at-least-once |
| When | occurred_at, recorded_at | UTC, ISO 8601; keep both to spot delays |
| Tenancy | tenant_id, optional workspace_id | Mandatory on every event; drives isolation and export |
| Who | actor_type (user, API key, system, support staff, AI agent), actor_id, on_behalf_of | Distinguish impersonation and automation from humans |
| Where | ip, user_agent, channel (web, mobile, API), request_id | Request ID links to operational traces |
| What | action (for example project.deleted), target_type, target_id, changes | Use a controlled vocabulary of actions |
| Outcome | result (success, denied, failed), reason | Denied actions are often the most interesting |
Rules that keep the schema healthy
- Maintain a registry of action names, reviewed like an API. Free-text actions make search and export useless.
- Version the schema and never repurpose a field.
- Record automated and AI-driven actions with their own actor type; customers increasingly ask what software did on their behalf.
- Encode values safely: OWASP’s Top 10 notes that log data must be encoded correctly to prevent injection into logging and monitoring systems.
Capture and storage architecture: options and trade-offs
The hardest requirement is completeness: the audit log must not miss an action that happened. That rules out “fire and forget” logging calls that can fail silently.
Capture options
| Approach | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Same-transaction write | Audit row inserted in the same database transaction as the change | Simple, strongly consistent | Couples audit storage to the primary database; grows large |
| Transactional outbox | Event written to an outbox table in the transaction, then published to a queue or stream | Reliable and decoupled; feeds multiple consumers | More moving parts; at-least-once delivery needs deduplication |
| Change data capture | Database change stream converted into events | No application changes; catches everything | Lacks business context (who and why) unless enriched |
| Application log scraping | Audit events parsed from operational logs | Quick to start | Unreliable and incomplete; not suitable for evidence |
For most SaaS products we recommend the transactional outbox: the business change and its audit event commit together, and a separate worker delivers events to the audit store, the activity feed and any customer streams. Event-driven delivery patterns are covered in more depth in our article on event-driven APIs, webhooks and streams.
Storage choices
- Relational table in a separate schema or database. Fine for early-stage products; partition by time and tenant.
- Columnar or search store. Better for fast filtering across millions of events per tenant.
- Object storage archive. Cheap long-term retention in compressed, append-only files, with a short hot window in a queryable store.
A common pattern is hot storage for recent months, searchable in the product, and cold archive for the rest of the retention period, retrievable on request.
Tenant isolation
Every query against audit data must be scoped by tenant ID, enforced in the data access layer rather than left to each endpoint. A leak of one customer’s audit log to another is a serious incident in itself. Include audit endpoints in the tests described in our guide to proving tenant isolation in a multi-tenant SaaS.
Making the trail trustworthy: integrity, access and retention
Append-only and tamper-evident
OWASP’s Top 10 guidance for logging and monitoring failures recommends that high-value transactions have an audit trail with integrity controls to prevent tampering or deletion, such as append-only database tables. Its logging cheat sheet adds tamper detection and moving log data to read-only media as soon as practical. In practice:
- Grant the application a database role that can insert audit rows but not update or delete them.
- Chain records or batches with cryptographic hashes so any modification or gap is detectable.
- Periodically sign and archive batches to write-once storage.
AWS CloudTrail’s log file integrity validation is a useful reference design: it hashes each log file with SHA-256, delivers hourly digest files signed with a private key, and chains each digest to the previous one so that modification or deletion breaks verification. The same idea can be applied to your own audit archive.
Who can read the audit log
- Customer admins see their own tenant’s events, with role-based access.
- Your support staff access audit data through the internal admin console, and that access is itself audited. See our article on the SaaS admin console for the tooling around it.
- OWASP recommends restricting read access, reviewing it periodically and monitoring all access to logs.
Retention
OWASP’s guidance is that logs should not be destroyed before the required retention period and should not be kept beyond it, with legal, regulatory and contractual obligations setting the period. Data protection laws generally require you not to keep personal data longer than necessary, so define retention per event category, document it and make it configurable per plan where customers have different obligations. For deleted users, consider pseudonymising actor details rather than deleting events, after confirming the approach with your legal adviser.
Exposing audit data to customers
Audit logs become a product feature, often on higher-tier plans. Typical expectations, in roughly the order customers ask for them:
- In-app audit log viewer. Filter by user, action, resource and date range, with human-readable descriptions.
- Per-item activity history. A timeline on each record showing who changed what, derived from audit events.
- Export. CSV or JSON download for a date range, itself recorded as an audit event.
- API access. A paginated, filterable audit endpoint for customers’ own tooling.
- Streaming to customer systems. Continuous delivery to the customer’s storage or security tools.
GitHub’s enterprise audit log streaming is a good illustration of what mature buyers expect. It sends audit events as compressed JSON to destinations including Amazon S3, Azure Blob Storage, Azure Event Hubs, Google Cloud Storage, Datadog and Splunk, and states that delivery is at-least-once, so duplicates are possible. Your design should assume the same: stable event IDs, documented schema and idempotent consumers.
Packaging and pricing
Many SaaS companies keep a basic activity history on every plan and reserve long retention, export, API and streaming for business or enterprise tiers. Whatever you choose, keep the underlying capture identical across plans; only access and retention should differ, otherwise upgrades cannot show history.
For example, a 30-person B2B SaaS selling project tools to mid-market firms might start with an in-app viewer and CSV export, then add streaming when its first enterprise customer asks. Because events were captured consistently from day one, that later feature is a delivery pipeline, not a data migration. This example is illustrative.
Implementation plan and checklist
Phased plan
- Define. Agree the three log types, owners, the action vocabulary and retention per category.
- Build the pipeline. Schema, outbox, audit writer with insert-only permissions, tenant-scoped query layer.
- Instrument high-risk actions first. Authentication, permissions, admin settings, exports, deletions and support impersonation.
- Ship the customer viewer. Search, filters, readable descriptions and per-item history.
- Add integrity and archive. Hash chaining, signed batches and cold storage.
- Add export, API and streaming as customer demand appears.
- Test and monitor. Automated tests that each sensitive action emits the right event; alerts when audit delivery lags or fails.
Checklist
- Every audit event carries tenant ID, actor type and ID, action, target, outcome and timestamps.
- Secrets, tokens, card data and sensitive personal data never reach the audit log.
- Audit writes cannot be lost when the business change succeeds.
- The application cannot update or delete audit records.
- Integrity can be verified for any period.
- Support staff access and impersonation are themselves audited.
- Tenant isolation tests cover audit endpoints and exports.
- Retention is documented per category and enforced automatically.
- Customers can search, export and, where needed, stream their events.
- Missing or delayed audit events trigger an alert.
Frequently asked questions
When should a SaaS start building audit logs?
Before the first enterprise sale, ideally from the first version. Retrofitting means reconstructing history that was never captured. A minimal schema and pipeline covering high-risk actions is enough to start; customer-facing features can follow.
Can we use our application logging tool as the audit log?
Not on its own. Application logs are sampled, rotated and edited for engineers’ needs. Audit logs need completeness, a strict schema, tenant isolation and tamper evidence. You can feed both from the same events, but store and govern them separately.
How long should audit logs be kept?
There is no single answer. OWASP’s guidance is to keep logs for the required period and no longer, with legal, regulatory and contractual obligations setting it. Define retention per event category and allow longer periods on plans where customers need them.
Should AI agent actions appear in the audit log?
Yes. Record them with a distinct actor type, the user or policy they acted on behalf of, and the tool or action invoked. Customers increasingly ask what automated systems did in their account.
Does the audit log conflict with the right to erasure?
It can create tension. A common approach is to pseudonymise actor details for deleted users while preserving the event record. Agree the approach with legal counsel, document it and reflect it in your retention policy.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- OWASP Cheat Sheet Series: Logging Cheat Sheet — accessed 9 November 2026. Supports the events to log, when/where/who/what attributes, data exclusions, tamper detection, access control and retention guidance.
- OWASP Top 10:2021 A09 Security Logging and Monitoring Failures — accessed 9 November 2026. Supports append-only audit trails with integrity controls for high-value transactions and encoding log data to prevent injection.
- AWS Documentation: CloudTrail log file integrity validation — accessed 9 November 2026. Supports the SHA-256 hashing, signed hourly digests and chaining design used as a tamper-evidence reference.
- GitHub Docs: Streaming the audit log for your enterprise — accessed 9 November 2026. Supports the example of audit streaming destinations and at-least-once delivery requiring deduplication.
Related reading
Continue your research
Would your SaaS pass an enterprise buyer’s audit log questions today?
We can review your current logging, design an audit event pipeline and build the customer-facing audit features enterprise plans need.
